%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/pexpect/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/pexpect/__pycache__/spawnbase.cpython-312.pyc

�

��e�T���ddlmZmZddlZddlZddlZddlZddlZddlm	Z	m
Z
mZddlm
Z
mZmZej ddk\ZereneZGd�de�ZGd	�d
e�Zy)�)�StringIO�BytesION�)�ExceptionPexpect�EOF�TIMEOUT)�Expecter�searcher_string�searcher_re�c�4�eZdZdZedd��Zedd��Zy)�
_NullCoderzPass bytes through unchanged.c��|S�N���b�finals  �3/usr/lib/python3/dist-packages/pexpect/spawnbase.py�encodez_NullCoder.encode�����c��|Srrrs  r�decodez_NullCoder.decoderrN)F)�__name__�
__module__�__qualname__�__doc__�staticmethodrrrrrrr
s+��'��������rrc���eZdZdZdZdZdZ		dd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
eee
�Zdd�Zd�Zd
�Zdd�Z		dd�Z		dd�Zdd�Zdd�Zdd�Zd�Zdd�Zd�Zd�Zd�Zd�Zd�Zy) �	SpawnBasez�A base class providing the backwards-compatible spawn API for Pexpect.

    This should not be instantiated directly: use :class:`pexpect.spawn` or
    :class:`pexpect.fdpexpect.fdspawn`.
    NFc��tj|_tj|_tj|_d|_d|_d|_d|_d|_d|_	d|_
d|_d|_d|_
d|_||_t |_||_d|_d|_||_||_d|_d|_d|_d|_d|_dt9|�zdz|_d|_||_||_ |��tC�x|_"|_#tH|_%tL|_'d	|_(tRrAtHtTf|_+tXjZj]d
�|_-d�}||_/�n	t`f|_+tXjZ|_-tjjb|_/n�tejf|�|�|_"tejh|�|�|_#tj|_%tl|_'d|_(tjf|_+tRrtXjZ|_-n$tXjZjod
�|_-tjjb|_/d|_8|jO�|_9|jO�|_:y)
NFT���g�������?g�������?g-C��6?�<�>s
�asciic���	tjjj|�S#t$r2tjj|jdd��cYSwxYw)Nr&�replace)�sys�stdout�buffer�write�AttributeErrorr)rs r�write_to_stdoutz+SpawnBase.__init__.<locals>.write_to_stdout^sT��N�"�z�z�0�0�6�6�q�9�9��)�N�"�z�z�/�/�����)�0L�M�M�N�s�(+�8A&�%A&z
);r)�stdinr*�stderr�searcher�
ignorecase�before�after�match�match_index�
terminated�
exitstatus�signalstatus�status�child_fd�timeoutr�	delimiter�logfile�logfile_read�logfile_send�maxread�searchwindowsize�delaybeforesend�delayafterclose�delayafterterminate�delayafterread�	softspace�repr�name�closed�encoding�codec_errorsr�_encoder�_decoder�bytes�string_typer�buffer_type�crlf�PY3�str�allowed_string_types�os�lineseprr.�
basestringr,�codecs�getincrementalencoder�getincrementaldecoder�	text_typerr�async_pw_transport�_buffer�_before)�selfr<rArBr>rKrLr.s        r�__init__zSpawnBase.__init__!sA���Y�Y��
��j�j����j�j�����
���������
���
���������� ��������
���������� ��� ������ 0��� $��� #���$'�� �%�������$�t�*�$�s�*��	����!��
�(�����,6�L�8�D�M�D�M�$�D��&�D���D�I��-2�C�L��)�!�z�z�0�0��9���N�(7��$�-7�M��)�!�z�z���'*�z�z�'7�'7��$�C�F�8�8��B�<�P�D�M�B�F�8�8��B�<�P�D�M�(�D��'�D���D�I�)2�
�D�%��!�z�z���!�z�z�0�0��9���#&�:�:�#3�#3�D� �"&����'�'�)����'�'�)��rc��|j�5|jj|�|jj�|dk(r|jn|j}|�"|j|�|j�yy)N�send)r>r,�flushr@r?)r`�s�	direction�
second_logs    r�_logzSpawnBase._logsm���<�<�#��L�L���q�!��L�L��� �+4�f�+<�T�&�&�4�CT�CT�
��!����Q������"rc�`�|j�!t|t�s|jd�S|S)Nr&�rK�
isinstancerOr�r`res  r�_coerce_expect_stringzSpawnBase._coerce_expect_string��)���=�=� ��A�u�)=��8�8�G�$�$��rc��|j}|j�4t|t�s$t	j
|j
d��S|j�4t|t�r$t	j
|jd��S|S�Nzutf-8)�patternrKrkrO�re�compilerr)r`�r�ps   r�_coerce_expect_rezSpawnBase._coerce_expect_re�sf��
�I�I���=�=� ��A�u�)=��:�:�a�h�h�w�/�0�0�
�]�]�
&�:�a��+?��:�:�a�h�h�w�/�0�0��rc�`�|j�!t|t�s|jd�S|Srprjrls  r�_coerce_send_stringzSpawnBase._coerce_send_string�rnrc�6�|jj�Sr)r^�getvalue�r`s r�_get_bufferzSpawnBase._get_buffer�s���|�|�$�$�&�&rc�d�|j�|_|jj|�yr)rQr^r,)r`�values  r�_set_bufferzSpawnBase._set_buffer�s$���'�'�)��������5�!rc�\�	tj|j|�}|dk(rd|_td��|jj|d��}|j|d	�|S#t$r8}|jdt
jk(rd|_td���d}~wwxYw)
z�This reads data from the file descriptor.

        This is a simple implementation suitable for a regular file. Subclasses using ptys or pipes should override it.

        The timeout parameter is ignored.
        rTz,End Of File (EOF). Exception style platform.Nrz/End Of File (EOF). Empty string style platform.F)r�read)rVr�r;�OSError�args�errno�EIO�flag_eofrrNrrh)r`�sizer<re�errs     r�read_nonblockingzSpawnBase.read_nonblocking�s���	�����
�
�t�,�A�
��8� �D�M��G�H�H��M�M� � ��%� �0���	�	�!�V������	��x�x��{�e�i�i�'� $��
��H�I�I���	�s� A*�*	B+�33B&�&B+c��tdjt|�|dj|jD�cgc]
}t|���c}�����cc}w)Nz`got {badtype} ({badobj!r}) as pattern, must be one of: {goodtypes}, pexpect.EOF, pexpect.TIMEOUTz, )�badtype�badobj�	goodtypes)�	TypeError�format�type�joinrUrT)r`rq�asts   r�_pattern_type_errzSpawnBase._pattern_type_err�sb���I����W�
�'.�*.�)�)�/3�/H�/H�5J�(+�69��X�5J�+K� �"��	��5Js�Ac	��|�gSt|t�s|g}tj}|jr|tj
z}g}t
|�D]�\}}t||j�r7|j|�}|jtj||���S|tur|jt��q|tur|jt���t|ttjd���r#|j|�}|j|���|j|���|S)a�This compiles a pattern-string or a list of pattern-strings.
        Patterns must be a StringType, EOF, TIMEOUT, SRE_Pattern, or a list of
        those. Patterns may also be None which results in an empty list (you
        might do this if waiting for an EOF or TIMEOUT condition without
        expecting any pattern).

        This is used by expect() when calling expect_list(). Thus expect() is
        nothing more than::

             cpl = self.compile_pattern_list(pl)
             return self.expect_list(cpl, timeout)

        If you are using expect() within a loop it may be more
        efficient to compile the patterns first and then call expect_list().
        This avoid calls in a loop to compile_pattern_list()::

             cpl = self.compile_pattern_list(my_pattern)
             while some_condition:
                ...
                i = self.expect_list(cpl, timeout)
                ...
        �)rk�listrr�DOTALLr2�
IGNORECASE�	enumeraterUrm�appendrsrrr�rvr�)r`�patterns�
compile_flags�compiled_pattern_list�idxrus      r�compile_pattern_listzSpawnBase.compile_pattern_list�s��0���I��(�D�)� �z�H��	�	�
��?�?�)�B�M�M�9�M� "����)�	*�F�C���!�T�6�6�7��.�.�q�1��%�,�,�R�Z�Z��=�-I�J��c��%�,�,�S�1��g��%�,�,�W�5��A�t�B�J�J�r�N�3�4��*�*�1�-��%�,�,�Q�/��&�&�q�)�	*�%�$rc��d|vr|jd�}|rtdj|���|j|�}|j	||||�S)a�This seeks through the stream until a pattern is matched. The
        pattern is overloaded and may take several types. The pattern can be a
        StringType, EOF, a compiled re, or a list of any of those types.
        Strings will be compiled to re types. This returns the index into the
        pattern list. If the pattern was not a list this returns index 0 on a
        successful match. This may raise exceptions for EOF or TIMEOUT. To
        avoid the EOF or TIMEOUT exceptions add EOF or TIMEOUT to the pattern
        list. That will cause expect to match an EOF or TIMEOUT condition
        instead of raising an exception.

        If you pass a list of patterns and more than one matches, the first
        match in the stream is chosen. If more than one pattern matches at that
        point, the leftmost in the pattern list is chosen. For example::

            # the input is 'foobar'
            index = p.expect(['bar', 'foo', 'foobar'])
            # returns 1('foo') even though 'foobar' is a "better" match

        Please note, however, that buffering can affect this behavior, since
        input arrives in unpredictable chunks. For example::

            # the input is 'foobar'
            index = p.expect(['foobar', 'foo'])
            # returns 0('foobar') if all input is available at once,
            # but returns 1('foo') if parts of the final 'bar' arrive late

        When a match is found for the given pattern, the class instance
        attribute *match* becomes an re.MatchObject result.  Should an EOF
        or TIMEOUT pattern match, then the match attribute will be an instance
        of that exception class.  The pairing before and after class
        instance attributes are views of the data preceding and following
        the matching pattern.  On general exception, class attribute
        *before* is all data received up to the exception, while *match* and
        *after* attributes are value None.

        When the keyword argument timeout is -1 (default), then TIMEOUT will
        raise after the default value specified by the class timeout
        attribute. When None, TIMEOUT will not be raised and may block
        indefinitely until match.

        When the keyword argument searchwindowsize is -1 (default), then the
        value specified by the class maxread attribute is used.

        A list entry may be EOF or TIMEOUT instead of a string. This will
        catch these exceptions and return the index of the list entry instead
        of raising the exception. The attribute 'after' will be set to the
        exception type. The attribute 'match' will be None. This allows you to
        write code like this::

                index = p.expect(['good', 'bad', pexpect.EOF, pexpect.TIMEOUT])
                if index == 0:
                    do_something()
                elif index == 1:
                    do_something_else()
                elif index == 2:
                    do_some_other_thing()
                elif index == 3:
                    do_something_completely_different()

        instead of code like this::

                try:
                    index = p.expect(['good', 'bad'])
                    if index == 0:
                        do_something()
                    elif index == 1:
                        do_something_else()
                except EOF:
                    do_some_other_thing()
                except TIMEOUT:
                    do_something_completely_different()

        These two forms are equivalent. It all depends on what you want. You
        can also just expect the EOF if you are waiting for all output of a
        child to finish. For example::

                p = pexpect.spawn('/bin/ls')
                p.expect(pexpect.EOF)
                print p.before

        If you are trying to optimize for speed then see expect_list().

        On Python 3.4, or Python 3.3 with asyncio installed, passing
        ``async_=True``  will make this return an :mod:`asyncio` coroutine,
        which you can yield from to get the same result that this method would
        normally give directly. So, inside a coroutine, you can replace this code::

            index = p.expect(patterns)

        With this non-blocking form::

            index = yield from p.expect(patterns, async_=True)
        �async�Unknown keyword arguments: {})�popr�r�r��expect_list)r`rqr<rB�async_�kwr�s       r�expectzSpawnBase.expect�sb��|�b�=��V�V�G�_�F�
��;�B�B�2�F�G�G� $� 9� 9�'� B����� 5��)�6�3�	3rc��|dk(r|j}d|vr|jd�}|rtdj|���t	|t|�|�}|rddlm}|||�S|j|�S)amThis takes a list of compiled regular expressions and returns the
        index into the pattern_list that matched the child output. The list may
        also contain EOF or TIMEOUT(which are not compiled regular
        expressions). This method is similar to the expect() method except that
        expect_list() does not recompile the pattern list on every call. This
        may help if you are trying to optimize for speed, otherwise just use
        the expect() method.  This is called by expect().


        Like :meth:`expect`, passing ``async_=True`` will make this return an
        asyncio coroutine.
        r#r�r�r��expect_async)	r<r�r�r�r	r�_asyncr��expect_loop)r`�pattern_listr<rBr�r��expr�s        rr�zSpawnBase.expect_listesx���b�=��l�l�G��b�=��V�V�G�_�F�
��;�B�B�2�F�G�G��t�[��6�8H�I���,���W�-�-��?�?�7�+�+rc����|dk(r�j}d|vr|jd�}|rtdj|���t	|�j
�s|ttfvr|g}�fd�}	t|�}|D�cgc]
}||���}}t�t|�|�}|rddlm
}	|	||�S|j|�S#t$r�j|�Y�iwxYwcc}w)a�This is similar to expect(), but uses plain string matching instead
        of compiled regular expressions in 'pattern_list'. The 'pattern_list'
        may be a string; a list or other sequence of strings; or TIMEOUT and
        EOF.

        This call might be faster than expect() for two reasons: string
        searching is faster than RE matching and it is possible to limit the
        search to just the end of the input buffer.

        This method is also useful when you don't want to have to worry about
        escaping regular expression characters that you want to match.

        Like :meth:`expect`, passing ``async_=True`` will make this return an
        asyncio coroutine.
        r#r�r�c���|ttfvr|St|�j�r�j	|�S�j|�yr)rrrkrUrmr�)rqr`s �r�prepare_patternz/SpawnBase.expect_exact.<locals>.prepare_pattern�sC����7�C�.�(����'�4�#<�#<�=��1�1�'�:�:��"�"�7�+rrr�)r<r�r�r�rkrUrr�iterr�r	r
r�r�r�)
r`r�r<rBr�r�r�rur�r�s
`         r�expect_exactzSpawnBase.expect_exact�s����$�b�=��l�l�G��b�=��V�V�G�_�F�
��;�B�B�2�F�G�G��|�T�%>�%>�?���#��.�(�>�L�	,�	1���-�L�5A�A�q���*�A��A��t�_�\�:�<L�M���,���W�-�-��?�?�7�+�+���	1��"�"�<�0�	1��As�1C	�C)�	C&�%C&c�>�t|||�}|j|�S)aThis is the common loop used inside expect. The 'searcher' should be
        an instance of searcher_re or searcher_string, which describes how and
        what to search for in the input.

        See expect() for other arguments, return value and exceptions. )r	r�)r`r1r<rBr�s     rr�zSpawnBase.expect_loop�s"���t�X�'7�8�����w�'�'rc�d�|dk(r|j�S|dkr'|j|j�|jSt	j
|j
d|z�tj�}|j||jg�}|dk(r|jS|jS)aDThis reads at most "size" bytes from the file (less if the read hits
        EOF before obtaining size bytes). If the size argument is negative or
        omitted, read all data until EOF is reached. The bytes are returned as
        a string object. An empty string is returned when EOF is encountered
        immediately. rz.{%d})	rPr�r=r3rrrsrmr�r4)r`r��cre�indexs    rr�zSpawnBase.read�s����1�9��#�#�%�%��!�8��K�K����'��;�;���j�j��3�3�G�d�N�C�R�Y�Y�O�����S�$�.�.�1�2���A�:��:�:���{�{�rc���|dk(r|j�S|j|j|jg�}|dk(r|j|jzS|jS)alThis reads and returns one entire line. The newline at the end of
        line is returned as part of the string, unless the file ends without a
        newline. An empty string is returned if EOF is encountered immediately.
        This looks for a newline as a CR/LF pair (\r\n) even on UNIX because
        this is what the pseudotty device returns. So contrary to what you may
        expect you will receive newlines as \r\n.

        If the size argument is 0 then an empty string is returned. In all
        other cases the size argument is ignored, which is not standard
        behavior for a file-like object. r)rPr�rRr=r3)r`r�r�s   r�readlinezSpawnBase.readline�sY���1�9��#�#�%�%����T�Y�Y����7�8���A�:��;�;����*�*��;�;�rc�J�t|j|j��S)z>This is to support iterators over a file-like object.
        )r�r�rPr{s r�__iter__zSpawnBase.__iter__�s���D�M�M�4�#3�#3�#5�6�6rc�V�g}	|j�}|s	|S|j|��')a�This reads until EOF using readline() and returns a list containing
        the lines thus read. The optional 'sizehint' argument is ignored.
        Remember, because this reads until EOF that means the child
        process should have closed its stdout. If you run this method on
        a child that is still running with its stdout open then this
        method will block until it timesout.)r�r�)r`�sizehint�lines�lines    r�	readlineszSpawnBase.readlines�s5������=�=�?�D�����
�L�L���	rc��|jS)z9Expose file descriptor for a file-like interface
        )r;r{s r�filenozSpawnBase.filenos���}�}�rc��y)zWThis does nothing. It is here to support the interface for a
        File-like object. Nrr{s rrdzSpawnBase.flushs��	
rc��y)z Overridden in subclass using ttyFrr{s r�isattyzSpawnBase.isatty
s��rc��|Srrr{s r�	__enter__zSpawnBase.__enter__s���rc�$�|j�yr)�close)r`�etype�evalue�tbs    r�__exit__zSpawnBase.__exit__s
��	
�
�
�r)�i�NNN�strict)rN)r#r#F)r#r#)r#) rrrrrK�pidr�rarhrmrvrxr|r�propertyr+r�r�r�r�r�r�r�r�r�r�r�r�rdr�r�r�rrrr!r!s����
�H�
�C��H�BF�;C�\*�|����
'�"��k�;�
/�F��2�/%�be3�NFH� �,�8GI�!�/,�b(��:�*7�
� �

�
�
�rr!)�iorrrYrVr)rrr��
exceptionsrrrr�r	r
r�version_inforSrT�unicoder\�objectrr!rrr�<module>r�s[�� �
�	�
�	��6�6�:�:�
�����a����C�G�	����A��Ar

Zerion Mini Shell 1.0