%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/share/hplip/base/pexpect/__pycache__/
Upload File :
Create Path :
Current File : //usr/share/hplip/base/pexpect/__pycache__/__init__.cpython-312.pyc

�

=	fkD����dZ	ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZde_dZdZgd�Zej2dd	k\ZGd
�de�ZGd�d
e�ZGd�de�Z		dd�Z		dd�Z d�Z!Gd�de"�Z#Gd�de#�Z$Gd�de"�Z%Gd�de"�Z&d�Z'd�Z(y#e$r&ej&�dZeee�dz��wxYw)a�Pexpect is a Python module for spawning child applications and controlling
them automatically. Pexpect can be used for automating interactive applications
such as ssh, ftp, passwd, telnet, etc. It can be used to a automate setup
scripts for duplicating software package installations on different servers. It
can be used for automated software testing. Pexpect is in the spirit of Don
Libes' Expect, but Pexpect is pure Python. Other Expect-like modules for Python
require TCL and Expect or require C extensions to be compiled. Pexpect does not
use C, Expect, or TCL extensions. It should work on any platform that supports
the standard Python pty module. The Pexpect interface focuses on ease of use so
that simple tasks are easy.

There are two main interfaces to the Pexpect system; these are the function,
run() and the class, spawn. The spawn class is more powerful. The run()
function is simpler than spawn, and is good for quickly calling program. When
you call the run() function it executes a given program and then returns the
output. This is a handy replacement for os.system().

For example::

    pexpect.run('ls -la')

The spawn class is the more powerful interface to the Pexpect system. You can
use this to spawn a child program then interact with it by sending input and
expecting responses (waiting for patterns in the child's output).

For example::

    child = pexpect.spawn('scp foo user@example.com:.')
    child.expect('Password:')
    child.sendline(mypassword)

This works even for commands that ask for passwords or other input outside of
the normal stdio streams. For example, ssh reads input directly from the TTY
device which bypasses stdin.

Credits: Noah Spurrier, Richard Holden, Marco Molteni, Kimberley Burchett,
Robert Stone, Hartmut Goebel, Chad Schroeder, Erick Tryzelaar, Dave Kirby, Ids
vander Molen, George Todd, Noel Taylor, Nicolas D. Cesar, Alexander Gattin,
Jacques-Etienne Baudoux, Geoffrey Marshall, Francisco Lourenco, Glen Mabey,
Karthik Gurusamy, Fernando Perez, Corey Minyard, Jon Cohen, Guillaume
Chazarain, Andrew Ryan, Nick Craig-Wood, Andrew Stone, Jorgen Grahn, John
Spiegel, Jan Grant, and Shane Kerr. Let me know if I forgot anyone.

Pexpect is free, open source, and all that good stuff.
http://pexpect.sourceforge.net/

PEXPECT LICENSE

    This license is approved by the OSI and FSF as GPL-compatible.
        http://opensource.org/licenses/isc-license.txt

    Copyright (c) 2012, Noah Spurrier <noah@noah.org>
    PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY
    PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE
    COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES.
    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
    WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
    MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
    ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

�NT�z�

A critical module was not found. Probably this operating system does not
support it. Pexpect is intended for UNIX-like operating systems.z3.1�)�ExceptionPexpect�EOF�TIMEOUT�spawn�spawnu�run�runu�which�split_command_line�__version__�__revision__�c�.��eZdZdZ�fd�Zd�Zd�Z�xZS)rz9Base class for all exceptions raised by this module.
    c�:��tt|�|�||_y�N)�superr�__init__�value)�selfr�	__class__s  ��)/usr/share/hplip/base/pexpect/__init__.pyrzExceptionPexpect.__init__gs���
���.�u�5���
�c�,�t|j�Sr)�strr�rs r�__str__zExceptionPexpect.__str__ks���4�:�:��rc���tjtj�d�}|D�cgc]}d|dvs�|��}}tj|�}dj|�Scc}w)z�This returns an abbreviated stack trace with lines that only concern
        the caller. In other words, the stack trace inside the Pexpect module
        is not included. �zpexpect/__init__rr)�	traceback�
extract_tb�sys�exc_info�format_list�join)r�tblist�items   r�	get_tracezExceptionPexpect.get_tracensb��
�%�%�c�l�l�n�Q�&7�8��#)�O�4�-?�t�A�w�-N�$�O��O��&�&�v�.���w�w�v����Ps
�A(�A()�__name__�
__module__�__qualname__�__doc__rrr)�
__classcell__�rs@rrrcs������rrc��eZdZdZy)rzRRaised when EOF is read from a child.
    This usually means the child has exited.N�r*r+r,r-�rrrrys��0rrc��eZdZdZy)rz-Raised when a read time exceeds the timeout. Nr1r2rrrr~s��7rrc�2�t||||||||t��	S)a�
    This function runs the given command; waits for it to finish; then
    returns all output as a string. STDERR is included in output. If the full
    path to the command is not given then the path is searched.

    Note that lines are terminated by CR/LF (\r\n) combination even on
    UNIX-like systems because this is the standard for pseudottys. If you set
    'withexitstatus' to true, then run will return a tuple of (command_output,
    exitstatus). If 'withexitstatus' is false then this returns just
    command_output.

    The run() function can often be used instead of creating a spawn instance.
    For example, the following code uses spawn::

        from pexpect import *
        child = spawn('scp foo user@example.com:.')
        child.expect('(?i)password')
        child.sendline(mypassword)

    The previous code can be replace with the following::

        from pexpect import *
        run('scp foo user@example.com:.', events={'(?i)password': mypassword})

    **Examples**

    Start the apache daemon on the local machine::

        from pexpect import *
        run("/usr/local/apache/bin/apachectl start")

    Check in a file using SVN::

        from pexpect import *
        run("svn ci -m 'automatic commit' my_file.py")

    Run a command and capture exit status::

        from pexpect import *
        (command_output, exitstatus) = run('ls -l /bin', withexitstatus=1)

    The following will run SSH and execute 'ls -l' on the remote machine. The
    password 'secret' will be sent if the '(?i)password' pattern is ever seen::

        run("ssh username@machine.example.com 'ls -l'",
            events={'(?i)password':'secret\n'})

    This will start mencoder to rip a video from DVD. This will also display
    progress ticks every 5 seconds as it runs. For example::

        from pexpect import *
        def print_ticks(d):
            print d['event_count'],
        run("mencoder dvd://1 -o video.avi -oac copy -ovc copy",
            events={TIMEOUT:print_ticks}, timeout=5)

    The 'events' argument should be a dictionary of patterns and responses.
    Whenever one of the patterns is seen in the command out run() will send the
    associated response string. Note that you should put newlines in your
    string if Enter is necessary. The responses may also contain callback
    functions. Any callback is function that takes a dictionary as an argument.
    The dictionary contains all the locals from the run() function, so you can
    access the child spawn object or any other variable defined in run()
    (event_count, child, and extra_args are the most useful). A callback may
    return True to stop the current run process otherwise run() continues until
    the next event. A callback may also return a string which will be sent to
    the child. 'extra_args' is not used by directly run(). It provides a way to
    pass data to a callback function through run() through the locals
    dictionary passed to a callback.
    ��timeout�withexitstatus�events�
extra_args�logfile�cwd�env�_spawn)�_runr)�commandr6r7r8r9r:r;r<s        rr
r
�s&��R�����*�g�3���'�'rc�4�t|f|||||||td�|��S)z�This offers the same interface as :func:`run`, but using unicode.

    Like :class:`spawnu`, you can pass ``encoding`` and ``errors`` parameters,
    which will be used for both input and output.
    r5)r>r	)	r?r6r7r8r9r:r;r<�kwargss	         rrr�s2����2����*�g�3���2�*0�2�2rc		�B�|dk(r||fd|||d�|	��}
n||f|d|||d�|	��}
|�3t|j��}t|j��}nd}d}g}
d}		|
j|�}t	|
j
|
j�r)|
j|
j|
j
z�n|
j|
j�t	|||
j�r|
j||�n�t	||tj�r\||t��}tjj�t	||
j�r|
j|�n|rnt!d��|dz}��/|
j'�j)|
�}|r|
j+�||
j,fS|S#t"$r|
j|
j�Y�gt$$r|
j|
j�Y��wxYw)N�����)�maxreadr:r;r<)r6rEr:r;r<rz*The callback must be a string or function.r)�list�keys�values�expect�
isinstance�after�allowed_string_types�append�before�send�types�FunctionType�localsr#�stdout�flush�	TypeErrorrr�string_typer&�close�
exitstatus)r?r6r7r8r9r:r;r<r=rA�child�patterns�	responses�child_result_list�event_count�index�callback_result�child_results                  rr>r>�s���"�}��w�"��g�3�C�"� �"���w�,���w��S�,�$*�,��
������
�&�������)�	����	����K�
�	��L�L��*�E��%�+�+�u�'A�'A�B�!�(�(�������)C�D�"�(�(����6��)�E�*�E�,F�,F�G��
�
�9�U�+�,��I�e�,�e�.@�.@�A�"2�)�E�"2�6�8�"<���
�
� � �"��o�u�/I�/I�J��J�J��/�$��� L�M�M�%��/�K�)�6�$�$�&�+�+�,=�>�L��
���
��e�.�.�/�/�����	��$�$�U�\�\�2���	��$�$�U�\�\�2��	�s�#DG�?G�$H�8#H�Hc�j�eZdZdZeZer0eefZe	d��Z
ejjd�Ze	d��Zn-efZe	e�Z
ejZej$j&ZdZgdddddddfd	�Ze	d
��Ze	d��Ze	d��Zd
�Zd�Zgfd�Zd�Zd�Zd�Zd<d�Zd�Z d�Z!d=d�Z"d�Z#d�Z$d�Z%d>d�Z&d=d�Z'd=d�Z(d�Z)d=d�Z*d�Zd �Z+d!�Z,d"�Z-d?d#�Z.d$�Z/d%�Z0d&�Z1d'�Z2d@d(�Z3d)�Z4d*�Z5d+�Z6d,�Z7d-�Z8dAd.�Z9dAd/�Z:dAd0�Z;dAd1�Z<d2�Z=d3�Z>ed4�ddfd5�Z?d6�Z@d7�ZA		dBd8�ZBdCd9�ZCd:�ZDd;�ZEy)DrzjThis is the main class interface for Pexpect. Use this class to start
    and control child applications. c��t|g�Sr)�bytes)�cs r�_chrz
spawn._chrs���!��:�r�asciic���	tjjj|�S#t$r2tjj|jdd��cYSwxYw)Nrf�replace)r#rS�buffer�write�AttributeError�decode)�bs r�write_to_stdoutzspawn.write_to_stdout!sT��
F��z�z�(�(�.�.�q�1�1��!�
F��z�z�'�'�����)�(D�E�E�
F�s�(+�8A&�%A&N�rDTc
��tj|_tj|_tj|_tj
|_tj|_tj|_d|_d|_	d|_
d|_d|_d|_
d|_d|_d|_d|_d|_d|_d|_||_t,|_||_d|_d|_||_|j9�|_||_d|_d|_ d|_!d|_"dtG|�zdz|_$d|_%||_&||_'|	|_(tjRjU�jWd	�d
k\|_,tjRjU�jWd�d
k\s0tjRjU�jWd�d
k\rd|_-nd|_-|�d|_.d|_/d
|_$y|ja||�y)a�This is the constructor. The command parameter may be a string that
        includes a command and any arguments to the command. For example::

            child = pexpect.spawn('/usr/bin/ftp')
            child = pexpect.spawn('/usr/bin/ssh user@example.com')
            child = pexpect.spawn('ls -latr /tmp')

        You may also construct it with a list of arguments like so::

            child = pexpect.spawn('/usr/bin/ftp', [])
            child = pexpect.spawn('/usr/bin/ssh', ['user@example.com'])
            child = pexpect.spawn('ls', ['-latr', '/tmp'])

        After this the child application will be created and will be ready to
        talk to. For normal use, see expect() and send() and sendline().

        Remember that Pexpect does NOT interpret shell meta characters such as
        redirect, pipe, or wild cards (``>``, ``|``, or ``*``). This is a
        common mistake.  If you want to run a command and pipe it through
        another command then you must also start a shell. For example::

            child = pexpect.spawn('/bin/bash -c "ls -l | grep LOG > logs.txt"')
            child.expect(pexpect.EOF)

        The second form of spawn (where you pass a list of arguments) is useful
        in situations where you wish to spawn a command and pass it its own
        argument list. This can make syntax more clear. For example, the
        following is equivalent to the previous example::

            shell_cmd = 'ls -l | grep LOG > logs.txt'
            child = pexpect.spawn('/bin/bash', ['-c', shell_cmd])
            child.expect(pexpect.EOF)

        The maxread attribute sets the read buffer size. This is maximum number
        of bytes that Pexpect will try to read from a TTY at one time. Setting
        the maxread size to 1 will turn off buffering. Setting the maxread
        value higher may help performance in cases where large amounts of
        output are read back from the child. This feature is useful in
        conjunction with searchwindowsize.

        The searchwindowsize attribute sets the how far back in the incoming
        seach buffer Pexpect will search for pattern matches. Every time
        Pexpect reads some data from the child it will append the data to the
        incoming buffer. The default is to search from the beginning of the
        incoming buffer each time new data is read from the child. But this is
        very inefficient if you are running a command that generates a large
        amount of data where you want to match. The searchwindowsize does not
        affect the size of the incoming data buffer. You will still have
        access to the full buffer after expect() returns.

        The logfile member turns on or off logging. All input and output will
        be copied to the given file object. Set logfile to None to stop
        logging. This is the default. Set logfile to sys.stdout to echo
        everything to standard output. The logfile is flushed after each write.

        Example log input and output to a file::

            child = pexpect.spawn('some_command')
            fout = file('mylog.txt','w')
            child.logfile = fout

        Example log to stdout::

            child = pexpect.spawn('some_command')
            child.logfile = sys.stdout

        The logfile_read and logfile_send members can be used to separately log
        the input from the child and output sent to the child. Sometimes you
        don't want to see everything you write to the child. You only want to
        log what the child sends back. For example::

            child = pexpect.spawn('some_command')
            child.logfile_read = sys.stdout

        To separately log output sent to the child use logfile_send::

            self.logfile_send = fout

        If ``ignore_sighup`` is True, the child process will ignore SIGHUP
        signals. For now, the default is True, to preserve the behaviour of
        earlier versions of Pexpect, but you should pass this explicitly if you
        want to rely on it.

        The delaybeforesend helps overcome a weird behavior that many users
        were experiencing. The typical problem was that a user would expect() a
        "Password:" prompt and then immediately call sendline() to send the
        password. The user would then see that their password was echoed back
        to them. Passwords don't normally echo. The problem is caused by the
        fact that most applications print out the "Password" prompt and then
        turn off stdin echo, but if you send your password before the
        application turned off echo, then you get your password echoed.
        Normally this wouldn't be a problem when interacting with a human at a
        real keyboard. If you introduce a slight delay just before writing then
        this seems to clear up the problem. This was such a common problem for
        many users that I decided that the default pexpect behavior should be
        to sleep just before writing to the child application. 1/20th of a
        second (50 ms) seems to be enough to clear up the problem. You can set
        delaybeforesend to 0 to return to the old behavior. Most Linux machines
        don't like this to be below 0.03. I don't know why.

        Note that spawn is clever about finding commands on your path.
        It uses the same logic that "which" uses to find executables.

        If you wish to get the exit status of the child you must call the
        close() method. The exit or signal status of the child will be stored
        in self.exitstatus or self.signalstatus. If the child exited normally
        then exitstatus will store the exit return code and signalstatus will
        be None. If the child was terminated abnormally with a signal then
        signalstatus will store the signal value and exitstatus will be None.
        If you need more detail you can also read the self.status member which
        stores the status returned by os.waitpid. You can interpret this using
        os.WIFEXITED/os.WEXITSTATUS or os.WIFSIGNALED/os.TERMSIG. NFTrCg�������?皙�����?�<�>�irixr�solaris�sunos5z<pexpect factory incomplete>)1�pty�STDIN_FILENO�
STDOUT_FILENO�
STDERR_FILENOr#�stdinrS�stderr�searcher�
ignorecaserNrK�match�match_index�
terminatedrX�signalstatus�status�flag_eof�pid�child_fdr6r�	delimiterr:�logfile_read�logfile_sendrErVri�searchwindowsize�delaybeforesend�delayafterclose�delayafterterminate�	softspace�repr�name�closedr;r<�
ignore_sighup�platform�lower�find�_spawn__irix_hack�use_native_pty_forkr?�argsr=)
rr?r�r6rEr�r:r;r<r�s
          rrzspawn.__init__0s���j �,�,��� �.�.��� �.�.����Y�Y��
��j�j����j�j�����
���������
���
���������� ��������
������
���������� ��� �������&�&�(��� 0��� $��� #���$'�� �����$�t�*�$�s�*��	����������*����L�L�.�.�0�5�5�f�=��B���
�\�\�
�
�
!�
&�
&�y�
1�Q�
6����"�"�$�)�)�(�3�q�8�',�D�$�'+�D�$��?��D�L��D�I�6�D�I��K�K���&rc�H�t|t�s|jd�S|S)Nrf�rJrc�encode��ss r�_coerce_expect_stringzspawn._coerce_expect_string�� ���!�U�#��8�8�G�$�$��rc�H�t|t�s|jd�S|S)N�utf-8r�r�s r�_coerce_send_stringzspawn._coerce_send_string�r�rc��|Srr2r�s r�_coerce_read_stringzspawn._coerce_read_string�����rc�N�|js	|j�yy#YyxYw)aLThis makes sure that no system resources are left open. Python only
        garbage collects Python objects. OS file descriptors are not Python
        objects, so they must be handled explicitly. If the child file
        descriptor was opened outside of this class (passed to the constructor)
        then this does not close it. N)r�rWrs r�__del__z
spawn.__del__�s(���{�{�
��
�
����
��s� �$c�|�g}|jt|��|jdtz�|jdt|j�z�|jd|j
���|jd|j���|jd|jddz�|jd|jddz�|jd	|j���|jd
|j���|jdt|j�z�|jdt|j�z�|jd
t|j�z�|jdt|j�z�|jdt|j�z�|jdt|j �z�|jdt|j"�z�|jdt|j$�z�|jdt|j&�z�|jdt|j(�z�|jdt|j*�z�|jdt|j,�z�|jdt|j.�z�|jdt|j0�z�|jdt|j2�z�|jdt|j4�z�|jdt|j6�z�dj9|�S)zVThis returns a human-readable string that represents the state of
        the object. z	version: z	command: zargs: z
searcher: zbuffer (last 100 chars): %ri����Nzbefore (last 100 chars): %rzafter: zmatch: z
match_index: zexitstatus: z
flag_eof: zpid: z
child_fd: zclosed: z	timeout: zdelimiter: z	logfile: zlogfile_read: zlogfile_send: z	maxread: zignorecase: zsearchwindowsize: zdelaybeforesend: zdelayafterclose: zdelayafterterminate: �
)rMr�rrr?r�r}rirNrKrr�rXr�r�r�r�r6r�r:r�r�rEr~r�r�r�r�r&�rr�s  rrz
spawn.__str__	s���
��	����d���	����{�*�+�	����s�4�<�<�0�0�1�	���t�y�y�*�+�	���4�=�=�2�3�	���.�$�+�+�t�u�1E�E�G�	���.�$�+�+�t�u�1E�E�G�	����
�
�,�-�	����
�
�,�-�	����3�t�'7�'7�#8�8�9�	����#�d�o�o�"6�6�7�	�����D�M�M� 2�2�3�	����3�t�x�x�=�(�)�	�����D�M�M� 2�2�3�	����c�$�+�+�.�.�/�	����s�4�<�<�0�0�1�	�����T�^�^�!4�4�5�	����s�4�<�<�0�0�1�	���!�C��(9�(9�$:�:�;�	���!�C��(9�(9�$:�:�;�	����s�4�<�<�0�0�1�	����#�d�o�o�"6�6�7�	���%��D�,A�,A�(B�B�C�	���$�s�4�+?�+?�'@�@�A�	���$�s�4�+?�+?�'@�@�A�	���(�3�t�/G�/G�+H�H�I��y�y��|�rc��t|td��rtd��t|tg��std��|gk(r%t	|�|_|j
d|_n-|dd|_|j
jd|�||_t|j�}|�tdd|jzz��||_|j|j
d<ddj|j
�zd	z|_
|j�Jd
��|j�Jd��|jr#	tj�\|_|_n|j)�\|_|_|jdk(�rX	t"j*j-�|_|j/dd�t1j2t0j4�d}t7d|�D]}	t9j:|��|j<r2t?j>t>j@t>jB�|jD�t9jF|jD�|jH�+t9jJ|j|j
�n5t9jL|j|j
|jH�d|_'d|_(y#t $r/t#j$�d}td
t'|�z��wxYw#Y��qxYw#t $rY��NwxYw)aThis starts the given command in a child process. This does all the
        fork/exec type of stuff for a pty. This is called by __init__. If args
        is empty then command will be parsed (split on spaces) and args will be
        set to parsed arguments. rz�Command is an int type. If this is a file descriptor then maybe you want to use fdpexpect.fdspawn which takes an existing file descriptor instead of a command string.z#The argument, args, must be a list.Nz%The command was not found or was not zexecutable: %s.rr� rszThe pid member must be None.z$The command member must not be None.rzpty.fork() failed: ��PrF))rJ�typerrUr
r�r?�insertrr&r�r�r�rw�forkr��OSErrorr#r$r�_spawn__fork_ptyrS�fileno�
setwinsize�resource�	getrlimit�
RLIMIT_NOFILE�range�osrWr��signal�SIGHUP�SIG_IGNr;�chdirr<�execv�execvper�r�)rr?r��command_with_path�err�max_fd�is       rr=zspawn._spawn*s��� �g�t�A�w�'�"�$C�D�
D�
�$��R��)��A�B�B��2�:�*�7�3�D�I��9�9�Q�<�D�L��Q��D�I��I�I���Q��(�"�D�L�!�$�,�,�/���$�"�#J�%����4�$5�6�
6�(����|�|��	�	�!���#�(�(�4�9�9�-�-��3��	��x�x��?�!?�?���|�|�'�O�)O�O�'��#�#�
I�*-�(�(�*�'���$�-�'+�o�o�&7�#�D�H�d�m��8�8�q�=�

� #�
�
� 1� 1� 3��
�����B�'��'�'��(>�(>�?��B�F��1�f�%�
����H�H�Q�K�
��!�!��
�
�f�m�m�V�^�^�<��x�x�#�������"��x�x��������t�y�y�1��
�
�4�<�<����D�H�H�=� �������Q�
I��l�l�n�Q�'��&�'<�s�3�x�'G�H�H�
I��
�
������s*�!K9�5L4�>L<�98L1�4L9�<	M	�M	c���tj�\}}|dks|dkrtd��tj�}|dkrtd��|dk(r�tj|�|j|�tj|d�tj|d�tj|d�|dkDrtj|�||fStj|�||fS)aThis implements a substitute for the forkpty system call. This
        should be more portable than the pty.fork() function. Specifically,
        this should work on Solaris.

        Modified 10.06.05 by Geoff Marshall: Implemented __fork_pty() method to
        resolve the issue with Python's pty.fork() not supporting Solaris,
        particularly ssh. Based on patch to posixmodule.c authored by Noah
        Spurrier::

            http://mail.python.org/pipermail/python-dev/2003-May/035281.html

        rz!Could not open with os.openpty().zFailed os.fork().rr )r��openptyrr�rW� _spawn__pty_make_controlling_tty�dup2)r�	parent_fdr�r�s    r�
__fork_ptyzspawn.__fork_pty�s���!�j�j�l��	�8��q�=�H�q�L�"�#F�G�G��g�g�i����7�"�#6�7�7�
�A�X��H�H�Y���+�+�H�5��G�G�H�a� ��G�G�H�a� ��G�G�H�a� ��!�|�����"�
�I�~��
�H�H�X���I�~�rc��tj|�}	tjdtjtjz�}|dk\rtj
|�tj�	tjdtjtjz�}|dk\r tj
|�td��	tj|tj�}|dkrtd|z��tj
|�tjdtj�}|dkrtd��tj
|�y#Y��xYw#Y��xYw)z�This makes the pseudo-terminal the controlling tty. This should be
        more portable than the pty.fork() function. Specifically, this should
        work on Solaris. z/dev/ttyrzQFailed to disconnect from controlling tty. It is still possible to open /dev/tty.zCould not open child pty, z(Could not open controlling tty, /dev/ttyN)	r��ttyname�open�O_RDWR�O_NOCTTYrW�setsidr�O_WRONLY)r�tty_fd�
child_name�fds    r�__pty_make_controlling_ttyz spawn.__pty_make_controlling_tty�s��
�Z�Z��'�
�	�����R�Y�Y����%<�=�B��Q�w������	�	�	��		�����R�Y�Y����%<�=�B��Q�w������&�(N�O�O���W�W�Z����
+��
��6�"�#?�*�#L�M�M��H�H�R�L��W�W�Z����
-��
��6�"�#M�N�N��H�H�R�L��?	���	��s�AE,�;AE4�,E1�4E8c��|jS)zCThis returns the file descriptor of the pty for the child.
        )r�rs rr�zspawn.fileno�s���}�}�rc�.�|js�|j�tj|j�tj|j�|j�r|j|�std��d|_d|_yy)a?This closes the connection with the child application. Note that
        calling close() more than once is valid. This emulates standard Python
        behavior with files. Set force to True if you want to make sure that
        the child is terminated (SIGKILL is sent if the child ignores SIGHUP
        and SIGINT). zCould not terminate the child.rCTN)r�rTr�rWr��time�sleepr��isalive�	terminater�r�forces  rrWzspawn.close�sj���{�{��J�J�L��H�H�T�]�]�#��J�J�t�+�+�,��|�|�~��~�~�e�,�*�+K�L�L��D�M��D�K�rc��y)zWThis does nothing. It is here to support the interface for a
        File-like object. Nr2rs rrTzspawn.flush�s��	
rc�@�tj|j�S)zkThis returns True if the file descriptor is open and connected to a
        tty(-like) device, else False. )r��isattyr�rs rr�zspawn.isatty�s���y�y����'�'rc���|dk(r|j}|�tj�|z}	|j�sy|dkr|�y|�tj�z
}tjd��H)aThis waits until the terminal ECHO flag is set False. This returns
        True if the echo mode is off. This returns False if the ECHO flag was
        not set False before the timeout. This can be used to detect when the
        child is waiting for a password. Usually a child application will turn
        off echo mode when it is waiting for the user to enter a password. For
        example, instead of expecting the "password:" prompt you can wait for
        the child to set ECHO off::

            p = pexpect.spawn('ssh user@example.com')
            p.waitnoecho()
            p.sendline(mypassword)

        If timeout==-1 then this method will use the value in self.timeout.
        If timeout==None then this method to block until ECHO flag is False.
        rCTrFrq)r6r��getechor�)rr6�end_times   r�
waitnoechozspawn.waitnoecho�sn��"�b�=��l�l�G����y�y�{�W�,�H���<�<�>����{�w�2���"�"�T�Y�Y�[�0���J�J�s�O�rc�p�tj|j�}|dtjzryy)z�This returns the terminal echo mode. This returns True if echo is
        on or False if echo is off. Child applications that are expecting you
        to enter a password often set ECHO False. See waitnoecho(). rTF)�termios�	tcgetattrr��ECHO)r�attrs  rr�z
spawn.getechos.��
� � ����/����7�W�\�\�!��rc�$�|jtj|j�}|r|dtjz|d<n|dtjz|d<tj|jtj
|�y)aThis sets the terminal echo mode on or off. Note that anything the
        child sent before the echo will be lost, so you should be sure that
        your input buffer is empty before you call setecho(). For example, the
        following will work as expected::

            p = pexpect.spawn('cat') # Echo is on by default.
            p.sendline('1234') # We expect see this twice from the child...
            p.expect(['1234']) # ... once from the tty echo...
            p.expect(['1234']) # ... and again from cat itself.
            p.setecho(False) # Turn off tty echo
            p.sendline('abcd') # We will set this only once (echoed by cat).
            p.sendline('wxyz') # We will set this only once (echoed by cat)
            p.expect(['abcd'])
            p.expect(['wxyz'])

        The following WILL NOT WORK because the lines sent before the setecho
        will be lost::

            p = pexpect.spawn('cat')
            p.sendline('1234')
            p.setecho(False) # Turn off tty echo
            p.sendline('abcd') # We will set this only once (echoed by cat).
            p.sendline('wxyz') # We will set this only once (echoed by cat)
            p.expect(['1234'])
            p.expect(['1234'])
            p.expect(['abcd'])
            p.expect(['wxyz'])
        rN)r�r�r�r��	tcsetattr�TCSANOW)r�stater�s   r�setechoz
spawn.setecho%sl��<	
�
�
�� � ����/����1�g����,�D��G��1�g����
�-�D��G�	���$�-�-����$�?rc��|j�5|jj|�|jj�|dk(r|jn|j}|�"|j|�|j�yy)NrO)r:rjrTr�r�)rr��	direction�
second_logs    r�_logz
spawn._logNsm���<�<�#��L�L���q�!��L�L��� �+4�f�+<�T�&�&�4�CT�CT�
��!����Q������"rc�T�|jrtd��|dk(r|j}|j�s7|j	|j
gggd�\}}}|sed|_td��|jrG|j	|j
gggd�\}}}|s"|j�sd|_td��|j	|j
ggg|�\}}}|s-|j�sd|_td��td	��|j
|vr]	tj|j
|�}|dk(rd|_td��|j|�}|j|d
�|Std��#t$rd|_td
��wxYw)aaThis reads at most size characters from the child application. It
        includes a timeout. If the read does not complete within the timeout
        period then a TIMEOUT exception is raised. If the end of file is read
        then an EOF exception will be raised. If a log file was set using
        setlog() then all data will also be written to the log file.

        If timeout is None then the read may block indefinitely.
        If timeout is -1 then the self.timeout value is used. If timeout is 0
        then the child is polled and if there is no data immediately ready
        then this will raise a TIMEOUT exception.

        The timeout refers only to the amount of time to read at least one
        character. This is not effected by the 'size' parameter, so if you call
        read_nonblocking(size=100, timeout=30) and only one character is
        available right away then one character will be returned immediately.
        It will not wait for 30 seconds for another 99 characters to come in.

        This is a wrapper around os.read(). It uses select.select() to
        implement the timeout. zI/O operation on closed file.rCrTz&End Of File (EOF). Braindead platform.r z!End Of File (EOF). Slow platform.z&End of File (EOF). Very slow platform.zTimeout exceeded.z,End Of File (EOF). Exception style platform.rz/End Of File (EOF). Empty string style platform.�readzReached an unexpected state.)r��
ValueErrorr6r��_spawn__selectr�r�rr�rr�r�r�r�r�r)r�sizer6�r�w�er�s       r�read_nonblockingzspawn.read_nonblockingWs���*�;�;��<�=�=��b�=��l�l�G��|�|�~��m�m�T�]�]�O�R��Q�?�G�A�q�!�� $��
��B�C�C�
�
�
��m�m�T�]�]�O�R��Q�?�G�A�q�!��T�\�\�^� $��
��=�>�>��-�-������R��A���1�a���<�<�>�!%��
��B�C�C��1�2�2��=�=�A��
J��G�G�D�M�M�4�0��
�C�x� $��
��K�L�L��(�(��+�A��I�I�a�� ��H��=�>�>���
J� $��
��H�I�I�
J�s�$ F�F'c�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})	rVrIr�rN�re�compiler��DOTALLrK)rr��crer^s    rr�z
spawn.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|jd|jg�}|dk(r|jdzS|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. rs
)rVrIr�rN)rr�r^s   r�readlinezspawn.readline�sQ���1�9��#�#�%�%����W�d�n�n�5�6���A�:��;�;��(�(��;�;�rc�J�t|j|j��S)z>This is to support iterators over a file-like object.
        )�iterrrVrs r�__iter__zspawn.__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.)rrM)r�sizehint�lines�lines    r�	readlineszspawn.readlines�s5������=�=�?�D�����
�L�L���	rc�&�|j|�y)zHThis is similar to send() except that there is no return value.
        N)rOr�s  rrjzspawn.write�s��	
�	�	�!�rc�4�|D]}|j|��y)z�This calls write() for each element in the sequence. The sequence
        can be any iterable object producing strings, typically a list of
        strings. This does not add line separators. There is no return value.
        N)rj)r�sequencer�s   r�
writelineszspawn.writelines�s���	�A��J�J�q�M�	rc��tj|j�|j|�}|j	|d�|j|�S)z�Sends string ``s`` to the child process, returning the number of
        bytes written. If a logfile is specified, a copy is written to that
        log. rO)r�r�r�r�r��_sendr�s  rrOz
spawn.send�sB��
	
�
�
�4�'�'�(��$�$�Q�'���	�	�!�V���z�z�!�}�rc�B�tj|j|�Sr)r�rjr�r�s  rrzspawn._sends���x�x��
�
�q�)�)rc�d�|j|�}||j|j�z}|S)z�Wraps send(), sending string ``s`` to child process, with os.linesep
        automatically appended. Returns number of bytes written. )rO�linesep)rr��ns   r�sendlinezspawn.sendline	s-��
�I�I�a�L��
��	�	�$�,�,�'�'���rc
��|j�}t|�}|dk\r6|dkr1|td�z
dz}|j|j|��Sddddddddd	d	d
dd�}||vry|j|j||��S)
aHelper method that wraps send() with mnemonic access for sending control
        character to the child (such as Ctrl-C or Ctrl-D).  For example, to send
        Ctrl-G (ASCII 7, bell, '')::

            child.sendcontrol('g')

        See also, sendintr() and sendeof().
        �a�z�arr���ro��)�@�`�[�{�\�|�]�}�^�~�_�?)r��ordrOre)r�charr�ds    r�sendcontrolzspawn.sendcontrols����z�z�|����I����7�q�C�x��C��H��q� �A��9�9�T�Y�Y�q�\�*�*��!��"��2��"��"���

���q�=���y�y����1�T�7�+�,�,rc���ttd�r=ttj|j�dtj
�}nd}|j
|j|��y)a1This sends an EOF to the child. This sends a character which causes
        the pending parent output buffer to be sent to the waiting child
        program without waiting for end-of-line. If it is the first character
        of the line, the read() in the user program returns 0, which signifies
        end-of-file. This means to work as expected a sendeof() has to be
        called at the beginning of a line. This method does not send a newline.
        It is the responsibility of the caller to ensure the eof is sent at the
        beginning of a line. �VEOF��N)�hasattrr�r+r�r�r0rOre�rr,s  r�sendeofz
spawn.sendeof,sP��6�7�F�#��w�(�(����7��:�7�<�<�H�I�D��D��	�	�$�)�)�D�/�"rc���ttd�r=ttj|j�dtj
�}nd}|j
|j|��y)znThis sends a SIGINT to the child. It does not require
        the SIGINT to be the first character on a line. �VINTRr1rN)r3r�r+r�r�r7rOrer4s  r�sendintrzspawn.sendintrNsP��
�7�G�$��w�(�(����7��:�7�=�=�I�J�D��D��	�	�$�)�)�D�/�"rc��|jS)z@This returns True if the EOF exception was ever raised.
        )r�rs r�eofz	spawn.eofZs��
�}�}�rc�&�|j�sy	|jtj�t	j
|j�|j�sy|jtj�t	j
|j�|j�sy|jtj�t	j
|j�|j�sy|rP|jtj�t	j
|j�|j�syyy#t$r4t	j
|j�|j�sYyYywxYw)z�This forces a child process to terminate. It starts nicely with
        SIGHUP and SIGINT. If "force" is True then moves onto SIGKILL. This
        returns True if the child was terminated. This returns False if the
        child could not be terminated. TF)r��killr�r�r�r�r��SIGCONT�SIGINT�SIGKILLr�r�s  rr�zspawn.terminateas���|�|�~��	��I�I�f�m�m�$��J�J�t�/�/�0��<�<�>���I�I�f�n�n�%��J�J�t�/�/�0��<�<�>���I�I�f�m�m�$��J�J�t�/�/�0��<�<�>����	�	�&�.�.�)��
�
�4�3�3�4��|�|�~�� ����		�

�J�J�t�/�/�0��<�<�>���		�s'�AE�"AE�1AE�AE�8F�Fc�L�|j�r$tj|jd�\}}nt	d��tj
|�|_tj|�r;||_tj
|�|_d|_	d|_
|jStj|�r;||_d|_tj|�|_	d|_
|jStj|�rt	d��|jS)amThis waits until the child exits. This is a blocking call. This will
        not read any data from the child, so this will block forever if the
        child has unread output and has terminated. In other words, the child
        may have printed output then called exit(), but, the child is
        technically still alive until its output is read by the parent. rz#Cannot wait for dead child process.NTz�Called wait() on a stopped child process. This is not supported. Is some other process attempting job control with our child pid?)r�r��waitpidr�r�WEXITSTATUSrX�	WIFEXITEDr�r�r��WIFSIGNALED�WTERMSIG�
WIFSTOPPED)rr�r�s   r�waitz
spawn.wait�s����<�<�>��*�*�T�X�X�q�1�K�C��"�#H�I�I��.�.��0���
�<�<��� �D�K� �n�n�V�4�D�O� $�D��"�D�O������^�^�F�
#� �D�K�"�D�O� "���F� 3�D��"�D�O������]�]�6�
"�"�$I�J�
J����rc�r�|jry|jrd}ntj}	tj|j
|�\}}|dk(r*	tj|j
|�\}}|dk(ry|dk(rytj|�r0||_
tj|�|_d|_d|_ytj"|�r0||_
d|_tj$|�|_d|_ytj&|�rtd��y#t$rBtj�d}|jtjk(rtd��|�wxYw#t$r.}|jtjk(rtd���d}~wwxYw)	aZThis tests if the child process is running or not. This is
        non-blocking. If the child was terminated then this will read the
        exitstatus or signalstatus of the child. This returns True if the child
        process appears to be running or False if not. It can take literally
        SECONDS for Solaris to return the right status. Frrz�isalive() encountered condition where "terminated" is 0, but there was no child process. Did someone else call waitpid() on our process?z�isalive() encountered condition that should never happen. There was no child process. Did someone else call waitpid() on our process?NTz�isalive() encountered condition where child process is stopped. This is not supported. Is some other process attempting job control with our child pid?)r�r�r��WNOHANGrAr�r�r#r$�errno�ECHILDrrCr�rBrXr�rDrErF)r�waitpid_optionsr�r�r�r�s      rr�z
spawn.isalive�s����?�?���=�=�
 �O� �j�j�O�	��*�*�T�X�X��?�K�C�� �!�8�
� �j�j����?�C���V� �a�x���!�8��
�<�<��� �D�K� �n�n�V�4�D�O� $�D��"�D�O���^�^�F�
#� �D�K�"�D�O� "���F� 3�D��"�D�O���]�]�6�
"�"�$6�7�
7���o�		��,�,�.��#�C��y�y�E�L�L�(�&�(*�+�+�
�	�		��&�
��7�7�e�l�l�*�*�,.�/�/�
��
�s$�#D1�#E?�1AE<�?	F6�)F1�1F6c�f�|j�r!tj|j|�yy)z�This sends the given signal to the child application. In keeping
        with UNIX tradition it has a misleading name. It does not necessarily
        kill the child unless you send the right signal. N)r�r�r<r�)r�sigs  rr<z
spawn.kill�s$���<�<�>��G�G�D�H�H�c�"�rc��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)rU�formatr�r&rLr)r�pattern�asts   r�_pattern_type_errzspawn._pattern_type_errsb���I����W�
�'.�*.�)�)�/3�/H�/H�5J�(+�69��X�5J�+K� �"��	��5Js�Ac	�d�|�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|���|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(clp, timeout)
                ...
        r)rJrFr�r�r~�
IGNORECASE�	enumeraterLr�rMr�rrr�rV)rrZ�
compile_flags�compiled_pattern_list�idx�ps      r�compile_pattern_listzspawn.compile_pattern_lists���2���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�%�,�,�Q�/��&�&�q�)�	*�%�$rc�J�|j|�}|j|||�S)al
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 returs 1('foo') if parts of the final 'bar' arrive late

        After a match is found the instance attributes 'before', 'after' and
        'match' will be set. You can see all the data read before the match in
        'before'. You can see the data that was matched in 'after'. The
        re.MatchObject used in the re match will be in 'match'. If an error
        occurred then 'before' will be set to all the data read so far and
        'after' and 'match' will be None.

        If timeout is -1 then timeout will be set to the self.timeout value.

        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().
        )r^�expect_list)rrTr6r�r[s     rrIzspawn.expect<s2��Z!%� 9� 9�'� B����� 5��)�+�	+rc�:�|jt|�||�S)a�This 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(). If timeout==-1 then
        the self.timeout value is used. If searchwindowsize==-1 then the
        self.searchwindowsize value is used. )�expect_loop�searcher_re)r�pattern_listr6r�s    rr`zspawn.expect_list�s$������L� 9��)�+�	+rc� ��t|�j�s|ttfvr|g}�fd�}	t	|�}|D�cgc]
}||���}}�jt|�||�S#t
$r�j
|�Y�MwxYwcc}w)aKThis 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.c���|ttfvr|St|�j�r�j	|�S�j|�yr)rrrJrLr�rV)rTrs �r�prepare_patternz+spawn.expect_exact.<locals>.prepare_pattern�sC����7�C�.�(����'�4�#<�#<�=��1�1�'�:�:��"�"�7�+r)	rJrLrrrrUrVrb�searcher_string)rrdr6r�rgr]s`     r�expect_exactzspawn.expect_exact�s����
�|�T�%>�%>�?���#��.�(�>�L�	,�	1���-�L�5A�A�q���*�A��A������ =��)�+�	+���	1��"�"�<�0�	1��As�A+�B�+B�Bc�^�||_|dk(r|j}|�tj�|z}|dk(r|j}	|j}t|�}	|j
|||�}|dk\rj||jd|_|d|j|_	||j|j|_
|j|_||_|jS|�|dkrtd��|j|j|�}t|�}tj d�||z}|�tj�z
}��#t"$r�t%j&�d}	|j)�|_|_	t"|_
|j*}|dk\r t"|_||_|jcYSd|_d|_t#t-|	�dzt-|�z��t$r�t%j&�d}	|_||_	t|_
|j.}|dk\r t|_||_|jcYSd|_d|_tt-|	�dzt-|�z��|_	d|_
d|_d|_�xYw)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. rCNrz!Timeout exceeded in expect_any().g-C��6?rr�)r}r6r�r�ri�len�search�end�startrNrKrr�rr�rEr�rr#r$rV�	eof_indexr�
timeout_index)
rr}r6r�r��incoming�freshlenr^rdr�s
          rrbzspawn.expect_loop�sv��!��
��b�=��l�l�G����y�y�{�W�,�H��r�!�#�4�4��8	��{�{�H��8�}�H�� ����(�<L�M���A�:�"*�8�<�<�=�"9�D�K�"*�+;�X�^�^�"<�D�K�!)�(�.�.�(�,�,�!G�D�J�!)���D�J�',�D�$��+�+�+��'�g��k�!�"E�F�F��)�)�$�,�,��@���q�6���
�
�6�"�#�a�<���&�&�����4�G�'��(�
	7��,�,�.��#�C��*�*�,�D�K�"�D�K��D�J��&�&�E���z� ��
�#(�� ��'�'�'�!��
�#'�� ��#�c�(�T�/�C��I�5�6�6��
	;��,�,�.��#�C�"�D�K�"�D�K� �D�J��*�*�E���z�$��
�#(�� ��'�'�'�!��
�#'�� ��c�#�h��o��D�	�9�:�:�	�"�D�K��D�J��D�J�#�D���s#�BE�A-E�A6J,�BJ,�AJ,c���ttdd�}tjddddd�}t	j
|j||�}tjd|�ddS)zmThis returns the terminal window size of the child tty. The return
        value is a tuple of (rows, cols). �
TIOCGWINSZiht@�HHHHrr )�getattrr��struct�pack�fcntl�ioctlr��unpack)rrtr��xs    r�
getwinsizezspawn.getwinsizesV��
�W�l�J�?�
��K�K���1�a��+���K�K��
�
�z�1�5���}�}�V�Q�'��!�,�,rc��ttdd�}|dk(rd}tjd||dd�}t	j
|j
�||�y)a=This sets the terminal window size of the child tty. This will cause
        a SIGWINCH signal to be sent to the child. This does not change the
        physical window size. It changes the size reported to TTY-aware
        applications like vi or curses -- applications that respond to the
        SIGWINCH signal. �
TIOCSWINSZigt�lgtrurN)rvr�rwrxryrzr�)r�rows�colsrr�s     rr�zspawn.setwinsizesK�� �W�l�K�@�
���#�$�J��K�K���d�A�q�1��
���D�K�K�M�:�q�1rrc�0�|j|j�|jj�|j	�|_tj|j�}tj|j�tr|jd�}	|j|||�tj|jt
j|�y#tj|jt
j|�wxYw)a�This gives control of the child process to the interactive user (the
        human at the keyboard). Keystrokes are sent to the child process, and
        the stdout and stderr output of the child process is printed. This
        simply echos the child stdout and child stderr to the real stdout and
        it echos the real stdin to the child stdin. When the user types the
        escape_character this method will stop. The default for
        escape_character is ^]. This should not be confused with ASCII 27 --
        the ESC character. ASCII 29 was chosen for historical merit because
        this is the character used by 'telnet' as the escape character. The
        escape_character will not be sent to the child process.

        You may pass in optional input and output filter functions. These
        functions should take a string and return a string. The output_filter
        will be passed all the output from the child process. The input_filter
        will be passed all the keyboard input from the user. The input_filter
        is run BEFORE the check for the escape_character.

        Note that if you change the window size of the parent the SIGWINCH
        signal will not be passed through to the child. If you want the child
        window size to change when the parent's window size changes then do
        something like the following example::

            import pexpect, struct, fcntl, termios, signal, sys
            def sigwinch_passthrough (sig, data):
                s = struct.pack("HHHH", 0, 0, 0, 0)
                a = struct.unpack('hhhh', fcntl.ioctl(sys.stdout.fileno(),
                    termios.TIOCGWINSZ , s))
                global p
                p.setwinsize(a[0],a[1])
            # Note this 'p' global and used in sigwinch_passthrough.
            p = pexpect.spawn('/bin/bash')
            signal.signal(signal.SIGWINCH, sigwinch_passthrough)
            p.interact()
        zlatin-1N)rnrirSrTrV�ttyr�rx�setraw�PY3r��_spawn__interact_copyr��	TCSAFLUSH)r�escape_character�input_filter�
output_filter�modes     r�interactzspawn.interact*s���N	
���T�[�[�)��������&�&�(����}�}�T�.�.�/���
�
�4�$�$�%��/�6�6�y�A��	B�� � �!1�<��O��M�M�$�+�+�S�]�]�D�A��C�M�M�$�+�+�S�]�]�D�A�s�!C$�$1Dc��|dk7rD|j�r3tj||�}||d}|dk7r|j�r�1yyyy)�/This is used by the interact() method.
        rN)r�r�rj)rr��datars    r�__interact_writenzspawn.__interact_writen]sE���c�k�d�l�l�n�����T�"�A����8�D��c�k�d�l�l�n�k�n�krc�.�tj|d�S)r�i�)r�r�)rr�s  r�__interact_readzspawn.__interact_reades���w�w�r�4� � rc�H�|j��r\|j|j|jggg�\}}}|j|vr�	|j	|j�}|r|�}|j�5|jj�|jj�tj|j�|j|vry|j	|j�}|r||�}|j|�}|dk7r"|d|}|j|j|�y|j|j|�|j�r��[yy#t
$r)}|jtjk7r�Yd}~��3d}~wwxYw)r�NrC)r�r�r�rx�_spawn__interact_readr�rJ�EIOr:rjrTr�ry�rfind�_spawn__interact_writen)	rr�r�r�r�r�r�r�r�s	         r�__interact_copyzspawn.__interact_copyks\���l�l�n��m�m�T�]�]�D�4E�4E�$F��B�O�G�A�q�!��}�}��!���/�/��
�
�>�D�
!�(��.�D��<�<�+��L�L�&�&�t�,��L�L�&�&�(�����+�+�T�2�� � �A�%��+�+�D�,=�,=�>���'��-�D��J�J�/�0����7����8�D��*�*�4�=�=�$�?���&�&�t�}�}�d�;�1�l�l�n�n��
���w�w�%�)�)�+��,���s�E/�/	F!�8F�F!c�P�|�tj�|z}		tj||||�S#tj$r]tj�d}|j
t
jk(r%|�$tj�z
}|dkrgggfcYS�YnwxYw��)z�This is a wrapper around select.select() that ignores signals. If
        select.select raises a select.error exception and errno is an EINTR
        error then it is ignored. Mainly this is used to ignore sigwinch
        (terminal resize). rr)r��select�errorr#r$rJ�EINTR)r�iwtd�owtd�ewtdr6r�r�s       r�__selectzspawn.__select�s������y�y�{�W�,�H��
��}�}�T�4��w�?�?���<�<�
��l�l�n�Q�'���9�9����+��*�"*�T�Y�Y�[�"8��"�Q�;�#%�r�2�,�.���
��s�4�A*B$� B$�#B$c��td��)zoThis method is no longer supported or allowed. I don't like getters
        and setters without a good reason. zbThis method is no longer supported or allowed. Just assign a value to the maxread member variable.�r)rrEs  r�
setmaxreadzspawn.setmaxread�s��
� +�,�	,rc��td��)z7This method is no longer supported or allowed.
        zbThis method is no longer supported or allowed. Just assign a value to the logfile member variable.r�)r�
fileobjects  r�setlogzspawn.setlog�s��
� #�$�	$r)T)rC)rrC)r)F)rCrC)NNNr)Fr*r+r,r-rcrVr�rrL�staticmethodrer�rr�rn�
basestring�chrr#rSrj�encodingrr�r�r�r�rr=r�r�r�rWrTr�r�r�r�r�r�r�rrr
rrOrrr.r5r8r:r�rGr�r<rVr^rIr`rirbr}r�r�r�r�r�r�r�r�r2rrrrs���(��K�
� %�s�|��	�	�
�	��*�*�#�#�G�,��	�	F�
�	F�!+�}���C� ���*�*���*�*�*�*���H�%'��T��t��4��v'�p����
����
�����"�B$&�Y�v$�L,�\�
�&
�(��<�'@�R�K?�Z�:�*7�
� ��
�*��-�6 #�D
#��'�R�<M�^#��/%�bO+�b
+�+�BI�V-�2�0),�B���T�1B�f�!�04�-1�<�@�>,�$rrc���eZdZdZereZefZee	�Z
ejZn(e
Ze
fZee�Z
ejjd�Zej"j$Z�fd�Zed��Zed��Zd�Zd�Z�xZS)r	a~Works like spawn, but accepts and returns unicode strings.

    Extra parameters:

    :param encoding: The encoding to use for communications (default: 'utf-8')
    :param errors: How to handle encoding/decoding errors; one of 'strict'
                   (the default), 'ignore', or 'replace', as described
                   for :meth:`~bytes.decode` and :meth:`~str.encode`.
    rfc����|jdd�|_|jdd�|_tj|j�|j��|_t
t|�"|i|��y)Nr�r��errors�strict)r�)	�popr�r��codecs�getincrementaldecoder�_decoderrr	r)rr�rArs   �rrzspawnu.__init__�s\����
�
�:�w�7��
��j�j��8�4���C��4�4�T�]�]�C�4�;�;�W��
�
�f�d�$�d�5�f�5rc��|Srr2r�s rr�zspawnu._coerce_expect_string�r�rc��|Srr2r�s rr�zspawnu._coerce_send_string�r�rc�<�|jj|d��S)NF)�final)r�rlr�s  rr�zspawnu._coerce_read_string�s���}�}�#�#�A�U�#�3�3rc��tj|j|j|j|j
��Sr)r�rjr�r�r�r�r�s  rrzspawnu._send�s*���x�x��
�
�q�x�x��
�
�t�{�{�'K�L�Lr)r*r+r,r-r�rrVrLr�r�rer�r�unicode�unichrrlr#rSrjrnrr�r�r�rr.r/s@rr	r	�s�������� #�w���C� ���*�*���� '�{���F�#���*�*�#�#�G�,���j�j�&�&�O�6���������4�Mrr	c�$�eZdZdZd�Zd�Zdd�Zy)rha-This is a plain string search helper for the spawn.expect_any() method.
    This helper class is for speed. For more powerful regex patterns
    see the helper class, searcher_re.

    Attributes:

        eof_index     - index of EOF, or -1
        timeout_index - index of TIMEOUT, or -1

    After a successful match by the search() method the following attributes
    are available:

        start - index into the buffer, first byte of match
        end   - index into the buffer, first byte after match
        match - the matching string itself

    c���d|_d|_g|_t|�D]B\}}|tur||_�|t
ur||_�&|jj
||f��Dy)z�This creates an instance of searcher_string. This argument 'strings'
        may be a list; a sequence of strings; or the EOF or TIMEOUT types. rCN)rorp�_stringsrYrrrM)r�stringsrr�s    rrzsearcher_string.__init__sk��
��������
��g�&�	)�D�A�q��C�x�!"�����G�|�%&��"���M�M� � �!�Q��(�	)rc��|jD�cgc]}|dd|zf��}}|jd�|jdk\r*|j|jd|jzf�|jdk\r*|j|jd|jzf�|j	�tt
|��d}dj|�Scc}w)�UThis returns a human-readable string that represents the state of
        the object.rz    %d: "%s")rCzsearcher_string:�    %d: EOF�    %d: TIMEOUTrr�)r�rMrorp�sortrF�zipr&)r�ns�sss   rrzsearcher_string.__str__s���
6:�]�]�
C�r�r�!�u�n�r�)�*�
C��
C�
�	�	�*�+��>�>�Q���I�I�t�~�~�}�t�~�~�'E�F�G�����"��I�I�t�)�)�!�D�$6�$6�6�8�
9�
���	�
�#�r�(�^�A�
���y�y��}���Ds�CNc��d}|jD]@\}}|�|t|�z}n|}|j||�}|dk\s�3|�||ks�;|}||}
}	�B|�y
|_||_|jt|j�z|_	S)a�This searches 'buffer' for the first occurence of one of the search
        strings.  'freshlen' must indicate the number of bytes at the end of
        'buffer' which have not been searched before. It helps to avoid
        searching the same, possibly big, buffer over and over again.

        See class spawn for the 'searchwindowsize' argument.

        If there is a match this returns the index of that string, and sets
        'start', 'end' and 'match'. Otherwise, this returns -1. NrrC)r�rkr�rrnrm)rrirrr��first_matchr^r��offsetr�
best_index�
best_matchs           rrlzsearcher_string.search!s������
�
�	2�H�E�1��'�$�c�!�f�,�-��+�*�����A�v�&�A��A�v�;�.�!�k�/���).��J�
�	2������
� ��
��:�:��D�J�J��/����rr�r*r+r,r-rrrlr2rrrhrh�s���$)�"� +rrhc�$�eZdZdZd�Zd�Zdd�Zy)rcaUThis is regular expression string search helper for the
    spawn.expect_any() method. This helper class is for powerful
    pattern matching. For speed, see the helper class, searcher_string.

    Attributes:

        eof_index     - index of EOF, or -1
        timeout_index - index of TIMEOUT, or -1

    After a successful match by the search() method the following attributes
    are available:

        start - index into the buffer, first byte of match
        end   - index into the buffer, first byte after match
        match - the re.match object returned by a succesful re.search

    c	��d|_d|_g|_tt	tt
|���|�D]B\}}|tur||_�|tur||_�&|jj||f��Dy)z�This creates an instance that searches for 'patterns' Where
        'patterns' may be a list or other sequence of compiled regular
        expressions, or the EOF or TIMEOUT types.rCN)
rorp�	_searchesr�rFr�rkrrrM)rrZrr�s    rrzsearcher_re.__init__cs{�������������U�3�x�=�1�2�H�=�	*�D�A�q��C�x�!"�����G�|�%&��"���N�N�!�!�1�a�&�)�	*rc�X�t�}|jD](\}}	|j|d||jfzf��*|jd�|j
dk\r*|j|j
d|j
zf�|jdk\r*|j|jd|jzf�|j�tt|��d}dj|�S#t$r&|j|d||jfzf�Y��wxYw)	r�z    %d: re.compile("%s")z    %d: re.compile(%r))rCzsearcher_re:rr�r�rr�)
rFr�rMrT�UnicodeEncodeErrorrorpr�r�r&)rr�rr�s    rrzsearcher_re.__str__us���V���N�N�	J�D�A�q�
J��	�	�1�8�A�q�y�y�>�I�J�K�	J�	�	�	�&�'��>�>�Q���I�I�t�~�~�}�t�~�~�'E�F�G�����"��I�I�t�)�)�+<��"�"�,#�$�
%�
���	�
�#�r�(�^�A�
���y�y��}���&�
J��	�	�1�6�!�Q�Y�Y��G�H�I�	
J�s�"C:�:+D)�(D)Nc�2�d}|�d}ntdt|�|z
�}|jD]8\}}|j||�}|��|j	�}	|�|	|ks�3|	}|}
|}�:|�y||_
|_|j
j
�|_S)a�This searches 'buffer' for the first occurence of one of the regular
        expressions. 'freshlen' must indicate the number of bytes at the end of
        'buffer' which have not been searched before.

        See class spawn for the 'searchwindowsize' argument.

        If there is a match this returns the index of that string, and sets
        'start', 'end' and 'match'. Otherwise, returns -1.NrrC)�maxrkr�rlrnrrm)rrirrr�r��searchstartr^r�rr�	the_matchr�s            rrlzsearcher_re.search�s������#��K��a��V��/?�!?�@�K����	#�H�E�1��H�H�V�[�1�E��}�����
�A��"�a�+�o���!�	�"�
�	#���� ��
���
��:�:�>�>�#����rrr�r2rrrcrcOs���$*�$�4 rrcc��tjj|�dk7r&tj|tj�r|Sdtj
vstj
ddk(rtj}ntj
d}|jtj�}|D]J}tjj||�}tj|tj�s�H|cSy)z�This takes a given filename; tries to find it in the environment path;
    then checks if it is executable. This returns the full path to the filename
    if found and executable. Otherwise this returns None.r�PATHN)
r��path�dirname�access�X_OK�environ�defpath�split�pathsepr&)�filenamer]�pathlistr��ffs     rrr�s���
�w�w���x� �B�&�
�9�9�X�r�w�w�'��O�
�R�Z�Z��2�:�:�f�#5��#;��J�J���J�J�v����w�w�r�z�z�"�H����
�W�W�\�\�$��
)��
�9�9�R����!��I��rc�r�g}d}d}d}d}d}d}|}|D]�}	||k(s||k(rL|	dk(r|}�|	dk(r|}�|	d	k(r|}�%|	j�r||k(r�;|j|�d}|}�Q||	z}|}�Y||k(r||	z}|}�f||k(r|	dk(r|}�s||	z}�y||k(s�|	d	k(r|}��||	z}��|dk7r|j|�|S)
aThis splits a command line into a list of arguments. It splits arguments
    on spaces, but handles embedded quotes, doublequotes, and escaped
    characters. It's impossible to do this with a regular expression, so I
    wrote a little state machine to parse the command line. rrrr rr2r#�'�")�isspacerM)
�command_line�arg_list�arg�state_basic�	state_esc�state_singlequote�state_doublequote�state_whitespacer�rds
          rr
r
�s���H�
�C��K��I��������E�
�#���K��5�,<�#<��D�y�!���d��)���d��)�������,�,���O�O�C�(��C�,�E��A�g��#��
�i�
���'�C��E�
�'�
'��D�y�#���A�g��
�'�
'��D�y�#���A�g��G#�J�b�y�������Or)rCFNNNNN))r-r�r#r�r�r�rwr�rPrwr�r�ryrJr!r�r��dont_write_bytecode�ImportErrorr$r�rrr�__all__�version_infor��	Exceptionrrrr
rr>�objectrr	rhrcrr
r2rr�<module>r�sJ��?�BE�
����
������������"�C������I�������a����y��,0�
�0�
8��8�;?�59�K'�Z<@�59�	2�1�fd$�F�d$�T-)M�U�)M�X`�f�`�F`�&�`�F�,:��i;�E�
�#�,�,�.��
�C�
�c�#�h�"D�D�E�E�E�s�AC�+C3

Zerion Mini Shell 1.0