%PDF- %PDF-
Mini Shell

Mini Shell

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

�

��e���H�ddlZddlZddlmZmZddlmZ		dd�Z		dd�Zy)�N�)�EOF�TIMEOUT)�spawnc	�V�|dk(rt|fd|||d�|��}	nt|f|d|||d�|��}	t|t�r)|D�
�cgc]\}
}|
��	}}
}|D�
�cgc]\}
}|��	}
}
}nGt|t�r3t|j	��}t|j��}
nd}d}
g}d}		|	j
|�}t|	j|	j�r)|j|	j|	jz�n|j|	j�t|
||	j�r|	j|
|�n�t|
|tj�st|
|tj�r\|
|t��}t j"j%�t||	j�r|	j|�n"|r n&t'dj)||
|����|d	z}��`|	j/�j1|�}|r|	j3�||	j4fS|Scc}}
wcc}}
w#t*$r|j|	j�Y�st,$r|j|	j�Y��wxYw)
aU
    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 either a dictionary or a tuple list that
    contains patterns and responses. Whenever one of the patterns is seen
    in the command output, run() will send the associated response string.
    So, run() in the above example can be also written as::

        run("mencoder dvd://1 -o video.avi -oac copy -ovc copy",
            events=[(TIMEOUT,print_ticks)], timeout=5)

    Use a tuple list for events if the command output requires a delicate
    control over what pattern should be matched, since the tuple list is passed
    to pexpect() as its pattern list, with the order of patterns preserved.

    Note that you should put newlines in your string if Enter is necessary.

    Like the example above, the responses may also contain a callback, either
    a function or method.  It should accept a dictionary value 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.

    Like :class:`spawn`, passing *encoding* will make it work with unicode
    instead of bytes. You can pass *codec_errors* to control how errors in
    encoding and decoding are handled.
    ���i�)�maxread�logfile�cwd�env)�timeoutr	r
rrNrzSparameter `event' at index {index} must be a string, method, or function: {value!r})�index�valuer)r�
isinstance�list�dict�keys�values�expect�after�allowed_string_types�append�before�send�types�FunctionType�
MethodType�locals�sys�stdout�flush�	TypeError�formatrr�string_type�join�close�
exitstatus)�commandr
�withexitstatus�events�
extra_argsr
rr�kwargs�child�x�y�patterns�	responses�child_result_list�event_countr�callback_result�child_results                   �-/usr/lib/python3/dist-packages/pexpect/run.py�runr7s~��p�"�}��g�"�t�W�#�3�"� �"���g�,�w��g��S�,�$*�,���&�$�� &�'���1�1�'��'�"(�)�3�1�Q�Q�)�	�)�	�F�D�	!�����
�&�������)�	����	����K�
�	��L�L��*�E��%�+�+�u�'A�'A�B�!�(�(�������)C�D�"�(�(����6��)�E�*�E�,F�,F�G��
�
�9�U�+�,��Y�u�-�u�/A�/A�B��Y�u�-�u�/?�/?�@�"2�)�E�"2�6�8�"<���
�
� � �"��o�u�/I�/I�J��J�J��/�$���!K�!'��e�9�U�;K��!L�N�N�&��/�K�/�<�$�$�&�+�+�,=�>�L��
���
��e�.�.�/�/����](��)��D�	��$�$�U�\�\�2���	��$�$�U�\�\�2��	�s*�I�I�0D8I�)$I�$J(�#J(�'J(c�N�|jdd�t|f|||||||d�|��S)z0Deprecated: pass encoding to run() instead.
    �encodingzutf-8)r
r)r*r+r
rr)�
setdefaultr7)	r(r
r)r*r+r
rrr,s	         r6�runur;�s@�����j�'�*��w�#����*�g�3��#�!�#�#�)�FNNNNN)	rr�
exceptionsrr�	pty_spawnrr7r;�r<r6�<module>rAs,��
��$��:>�59�M�^<@�59�#r<

Zerion Mini Shell 1.0