AlkantarClanX12

Your IP : 13.59.73.248


Current Path : /opt/alt/python37/lib64/python3.7/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/__pycache__/subprocess.cpython-37.opt-1.pyc

B

� f��@s`dZddlZejdkZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZGdd�de
�ZGdd�de�ZGd	d
�d
e�Zer�ddlZddlZddlZGdd�d�ZnDddlZddlZddlZddlZeed
d�Zeed�r�ejZnejZddddddddddddd
dgZe�r�ddlmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0e�1ddddd d!d"d#dd$d%d&d'd(d)d*d+d,d-g�Gd.d/�d/e2�Z3e�r�dZ4d0d1�Z5ngZ4d2d1�Z5d3Z6d4Z7d5Z8d6d7�Z9d8d9�Z:dd:�d;d�Z;d<d�Z<dd:�d=d�Z=Gd>d�de>�Z?dd?dd?d@�dAd�Z@dBdC�ZAdDd�ZBdEd�ZCGdFd�de>�ZDdS)Ga�Subprocesses with accessible I/O streams

This module allows you to spawn processes, connect to their
input/output/error pipes, and obtain their return codes.

For a complete description of this module see the Python documentation.

Main API
========
run(...): Runs a command, waits for it to complete, then returns a
          CompletedProcess instance.
Popen(...): A class for flexibly executing a command in a new process

Constants
---------
DEVNULL: Special value that indicates that os.devnull should be used
PIPE:    Special value that indicates a pipe should be created
STDOUT:  Special value that indicates that stderr should go to stdout


Older API
=========
call(...): Runs a command, waits for it to complete, then returns
    the return code.
check_call(...): Same as call() but raises CalledProcessError()
    if return code is not 0
check_output(...): Same as check_call() but returns the contents of
    stdout instead of a return code
getoutput(...): Runs a command in the shell, waits for it to complete,
    then returns the output
getstatusoutput(...): Runs a command in the shell, waits for it to complete,
    then returns a (exitcode, output) tuple
�NZwin32)�	monotonicc@seZdZdS)�SubprocessErrorN)�__name__�
__module__�__qualname__�rr�//opt/alt/python37/lib64/python3.7/subprocess.pyr9src@s<eZdZdZd
dd�Zdd�Zedd��Zejd	d��ZdS)�CalledProcessErrorz�Raised when run() is called with check=True and the process
    returns a non-zero exit status.

    Attributes:
      cmd, returncode, stdout, stderr, output
    NcCs||_||_||_||_dS)N)�
returncode�cmd�output�stderr)�selfr
rrr
rrr�__init__CszCalledProcessError.__init__cCsb|jrN|jdkrNyd|jt�|j�fStk
rJd|j|jfSXnd|j|jfSdS)NrzCommand '%s' died with %r.z)Command '%s' died with unknown signal %d.z.Command '%s' returned non-zero exit status %d.)r
r�signalZSignals�
ValueError)rrrr�__str__IszCalledProcessError.__str__cCs|jS)z+Alias for output attribute, to match stderr)r)rrrr�stdoutUszCalledProcessError.stdoutcCs
||_dS)N)r)r�valuerrrrZs)NN)	rrr�__doc__rr�propertyr�setterrrrrr	<s

r	c@s<eZdZdZd
dd�Zdd�Zedd��Zejd	d��ZdS)�TimeoutExpiredz�This exception is raised when the timeout expires while waiting for a
    child process.

    Attributes:
        cmd, output, stdout, stderr, timeout
    NcCs||_||_||_||_dS)N)r�timeoutrr
)rrrrr
rrrrhszTimeoutExpired.__init__cCsd|j|jfS)Nz'Command '%s' timed out after %s seconds)rr)rrrrrnszTimeoutExpired.__str__cCs|jS)N)r)rrrrrrszTimeoutExpired.stdoutcCs
||_dS)N)r)rrrrrrvs)NN)	rrrrrrrrrrrrrras

rc@s,eZdZddddddd�dd�Zdd�ZdS)�STARTUPINFOrN)�dwFlags�	hStdInput�
hStdOutput�	hStdError�wShowWindow�lpAttributeListcCs0||_||_||_||_||_|p(dgi|_dS)N�handle_list)rrrrrr )rrrrrrr rrrr�szSTARTUPINFO.__init__cCs@|j��}d|kr"t|d�|d<t|j|j|j|j|j|d�S)Nr!)rrrrrr )	r �copy�listrrrrrr)rZ	attr_listrrr�_copy�s
zSTARTUPINFO._copy)rrrrr$rrrrr�srZPIPE_BUFi�PollSelector�Popen�PIPE�STDOUT�call�
check_call�getstatusoutput�	getoutput�check_output�run�DEVNULL�CompletedProcess)�CREATE_NEW_CONSOLE�CREATE_NEW_PROCESS_GROUP�STD_INPUT_HANDLE�STD_OUTPUT_HANDLE�STD_ERROR_HANDLE�SW_HIDE�STARTF_USESTDHANDLES�STARTF_USESHOWWINDOW�ABOVE_NORMAL_PRIORITY_CLASS�BELOW_NORMAL_PRIORITY_CLASS�HIGH_PRIORITY_CLASS�IDLE_PRIORITY_CLASS�NORMAL_PRIORITY_CLASS�REALTIME_PRIORITY_CLASS�CREATE_NO_WINDOW�DETACHED_PROCESS�CREATE_DEFAULT_ERROR_MODE�CREATE_BREAKAWAY_FROM_JOBr1r2r3r4r5r6r7r8r9r:r;r<r=r>r?r@rArBc@s6eZdZdZejfdd�Zdd�Zdd�ZeZ	eZ
dS)	�HandleFcCs|jsd|_||�dS)NT)�closed)r�CloseHandlerrr�Close�szHandle.ClosecCs |jsd|_t|�Std��dS)NTzalready closed)rD�intr)rrrr�Detach�sz
Handle.DetachcCsd|jjt|�fS)Nz%s(%d))�	__class__rrG)rrrr�__repr__�szHandle.__repr__N)rrrrD�_winapirErFrHrJ�__del__rrrrrrC�srCcCsdS)Nrrrrr�_cleanup�srMc	Cs`tdkrdSxNtdd�D]>}|jtjd�}|dk	ryt�|�Wqtk
rVYqXqWdS)N)�
_deadstate)�_active�_internal_poll�sys�maxsize�remover)�instZresrrrrM�s���������cCs*g}tjj}|dkr&|�dd|�|S)zgReturn a list of command-line arguments reproducing the current
    optimization settings in sys.flags.r�-�O)rQ�flags�optimize�append)�argsrrrr�"_optim_args_from_interpreter_flagss
r^cCsbddddddd�}t�}x:|��D].\}}ttj|�}|dkr"|�d	||�q"Wtjjrh|�d
�n$tjjrz|�d�tjjr�|�d�tj	d
d
�}tjj
}ttdi�}d|k}|dkr�|�d�n|r�|�d�|r�|�d�x|D]}|�d|�q�W|�r|�d�xJdD]B}||k�r||}	|	dk�r>|}
nd||	f}
|�d|
f��qW|S)z}Return a list of command-line arguments reproducing the current
    settings in sys.flags, sys.warnoptions and sys._xoptions.�d�B�S�v�b�q)�debug�dont_write_bytecode�no_site�verbose�
bytes_warning�quietrrXz-Iz-Ez-sN�	_xoptions�dev�zerror::BytesWarningzdefault::BytesWarning�defaultz-W)z-Xrl)Zfaulthandler�tracemallocZ
importtimeZshowalloccountZshowrefcount�utf8Tz%s=%sz-X)
r^�items�getattrrQrZr\�isolated�ignore_environment�no_user_site�warnoptionsrirS�extend)Zflag_opt_mapr]�flagZoptrbZwarnoptsriZxoptions�dev_moder�argrrr�_args_from_interpreter_flagssN








r{)rc	Os>t||��*}y|j|d�S|���YnXWdQRXdS)z�Run command with arguments.  Wait for command to complete or
    timeout, then return the returncode attribute.

    The arguments are the same as for the Popen constructor.  Example:

    retcode = call(["ls", "-l"])
    )rN)r&�wait�kill)r�	popenargs�kwargs�prrrr)KscOs6t||�}|r2|�d�}|dkr(|d}t||��dS)aORun command with arguments.  Wait for command to complete.  If
    the exit code was zero then return, otherwise raise
    CalledProcessError.  The CalledProcessError object will have the
    return code in the returncode attribute.

    The arguments are the same as for the call function.  Example:

    check_call(["ls", "-l"])
    r]Nr)r)�getr	)r~r�retcoderrrrr*\s



cOsTd|krtd��d|kr<|ddkr<|�dd�r4dnd|d<t|t|d	d
�|��jS)aRun command with arguments and return its output.

    If the exit code was non-zero it raises a CalledProcessError.  The
    CalledProcessError object will have the return code in the returncode
    attribute and output in the output attribute.

    The arguments are the same as for the Popen constructor.  Example:

    >>> check_output(["ls", "-l", "/dev/null"])
    b'crw-rw-rw- 1 root root 1, 3 Oct 18  2007 /dev/null\n'

    The stdout argument is not allowed as it is used internally.
    To capture standard error in the result, use stderr=STDOUT.

    >>> check_output(["/bin/sh", "-c",
    ...               "ls -l non_existent_file ; exit 0"],
    ...              stderr=STDOUT)
    b'ls: non_existent_file: No such file or directory\n'

    There is an additional optional argument, "input", allowing you to
    pass a string to the subprocess's stdin.  If you use this argument
    you may not also use the Popen constructor's "stdin" argument, as
    it too will be used internally.  Example:

    >>> check_output(["sed", "-e", "s/foo/bar/"],
    ...              input=b"when in the course of fooman events\n")
    b'when in the course of barman events\n'

    By default, all communication is in bytes, and therefore any "input"
    should be bytes, and the return value will be bytes.  If in text mode,
    any "input" should be a string, and the return value will be a string
    decoded according to locale encoding, or by "encoding" if set. Text mode
    is triggered by setting any of text, encoding, errors or universal_newlines.
    rz3stdout argument not allowed, it will be overridden.�inputN�universal_newlinesF��T)rr�check)rr�r.r'r)rr~rrrrr-os#c@s*eZdZdZd	dd�Zdd�Zdd�ZdS)
r0aEA process that has finished running.

    This is returned by run().

    Attributes:
      args: The list or str args passed to run().
      returncode: The exit code of the process, negative for signals.
      stdout: The standard output (None if not captured).
      stderr: The standard error (None if not captured).
    NcCs||_||_||_||_dS)N)r]r
rr
)rr]r
rr
rrrr�szCompletedProcess.__init__cCshd�|j�d�|j�g}|jdk	r4|�d�|j��|jdk	rP|�d�|j��d�t|�jd�|��S)Nz	args={!r}zreturncode={!r}zstdout={!r}zstderr={!r}z{}({})z, )	�formatr]r
rr\r
�typer�join)rr]rrrrJ�s


zCompletedProcess.__repr__cCs |jrt|j|j|j|j��dS)z6Raise CalledProcessError if the exit code is non-zero.N)r
r	r]rr
)rrrr�check_returncode�sz!CompletedProcess.check_returncode)NN)rrrrrrJr�rrrrr0�s

	F)r��capture_outputrr�cOs |dk	r&|�d�dk	rtd��t|d<|r^|�d�dk	sF|�d�dk	rNtd��t|d<t|d<t||���}y|j||d�\}}Wn^tk
r�}	z,|��tr�|��\|	_|	_	n|�
��Wdd}	~	XYn|���YnX|��}
|�r|
�rt|
|j
||d��WdQRXt|j
|
||�S)	aKRun command with arguments and return a CompletedProcess instance.

    The returned instance will have attributes args, returncode, stdout and
    stderr. By default, stdout and stderr are not captured, and those attributes
    will be None. Pass stdout=PIPE and/or stderr=PIPE in order to capture them.

    If check is True and the exit code was non-zero, it raises a
    CalledProcessError. The CalledProcessError object will have the return code
    in the returncode attribute, and output & stderr attributes if those streams
    were captured.

    If timeout is given, and the process takes too long, a TimeoutExpired
    exception will be raised.

    There is an optional argument "input", allowing you to
    pass bytes or a string to the subprocess's stdin.  If you use this argument
    you may not also use the Popen constructor's "stdin" argument, as
    it will be used internally.

    By default, all communication is in bytes, and therefore any "input" should
    be bytes, and the stdout and stderr will be bytes. If in text mode, any
    "input" should be a string, and stdout and stderr will be strings decoded
    according to locale encoding, or by "encoding" if set. Text mode is
    triggered by setting any of text, encoding, errors or universal_newlines.

    The other arguments are the same as for the Popen constructor.
    N�stdinz/stdin and input arguments may not both be used.rr
z@stdout and stderr arguments may not be used with capture_output.)r)rr
)r�rr'r&�communicaterr}�
_mswindowsrr
r|�pollr	r]r0)r�r�rr�r~rZprocessrr
�excr�rrrr.�s4cCs�g}d}x�|D]�}g}|r$|�d�d|kp8d|kp8|}|rH|�d�xj|D]b}|dkrf|�|�qN|dkr�|�dt|�d�g}|�d�qN|r�|�|�g}|�|�qNW|r�|�|�|r|�|�|�d�qWd�|�S)	a�
    Translate a sequence of arguments into a command line
    string, using the same rules as the MS C runtime:

    1) Arguments are delimited by white space, which is either a
       space or a tab.

    2) A string surrounded by double quotation marks is
       interpreted as a single argument, regardless of white space
       contained within.  A quoted string can be embedded in an
       argument.

    3) A double quotation mark preceded by a backslash is
       interpreted as a literal double quotation mark.

    4) Backslashes are interpreted literally, unless they
       immediately precede a double quotation mark.

    5) If backslashes immediately precede a double quotation mark,
       every pair of backslashes is interpreted as a literal
       backslash.  If the number of backslashes is odd, the last
       backslash escapes the next double quotation mark as
       described in rule 3.
    F� �	�"�\�z\"r�)r\�lenrwr�)�seq�resultZ	needquoterzZbs_buf�crrr�list2cmdlines4






r�c
Cslyt|ddtd�}d}Wn.tk
rF}z|j}|j}Wdd}~XYnX|dd�dkrd|dd�}||fS)a�Return (exitcode, output) of executing cmd in a shell.

    Execute the string 'cmd' in a shell with 'check_output' and
    return a 2-tuple (status, output). The locale encoding is used
    to decode the output and process newlines.

    A trailing newline is stripped from the output.
    The exit status for the command can be interpreted
    according to the rules for the function 'wait'. Example:

    >>> import subprocess
    >>> subprocess.getstatusoutput('ls /bin/ls')
    (0, '/bin/ls')
    >>> subprocess.getstatusoutput('cat /bin/junk')
    (1, 'cat: /bin/junk: No such file or directory')
    >>> subprocess.getstatusoutput('/bin/junk')
    (127, 'sh: /bin/junk: not found')
    >>> subprocess.getstatusoutput('/bin/kill $$')
    (-15, '')
    T)�shell�textr
rNrU�
)r-r(r	rr
)r�dataZexitcodeZexrrrr+MscCst|�dS)a%Return output (stdout or stderr) of executing cmd in a shell.

    Like getstatusoutput(), except the exit status is ignored and the return
    value is a string containing the command's output.  Example:

    >>> import subprocess
    >>> subprocess.getoutput('ls /bin/ls')
    '/bin/ls'
    rm)r+)rrrrr,ls
c@s�eZdZdZdZdGdddd�d	d
�Zedd��Zejd
d��Zdd�Z	dd�Z
dd�Zej
ejfdd�Zdd�Zdd�ZdHdd�Zdd�Zdd�ZdId d!�ZdJd"d#�Ze�rd$d%�Zd&d'�Zd(d)�Zd*d+�Zdejejej fd,d-�Z!d.d/�Z"d0d1�Z#d2d3�Z$d4d5�Z%d6d7�Z&e&Z'n�d8d%�Zd9d+�Ze(j)e(j*e(j+e(j,e(j-e(j.fd:d;�Z/de(j0e(j1e2j3fd<d-�Z!d=d>�Z4d?d/�Z"d@d3�Z$dAdB�Z5dCd5�Z%dDd7�Z&dEdF�Z'dS)Kr&a� Execute a child program in a new process.

    For a complete description of the arguments see the Python documentation.

    Arguments:
      args: A string, or a sequence of program arguments.

      bufsize: supplied as the buffering argument to the open() function when
          creating the stdin/stdout/stderr pipe file objects

      executable: A replacement program to execute.

      stdin, stdout and stderr: These specify the executed programs' standard
          input, standard output and standard error file handles, respectively.

      preexec_fn: (POSIX only) An object to be called in the child process
          just before the child is executed.

      close_fds: Controls closing or inheriting of file descriptors.

      shell: If true, the command will be executed through the shell.

      cwd: Sets the current directory before the child is executed.

      env: Defines the environment variables for the new process.

      text: If true, decode stdin, stdout and stderr using the given encoding
          (if set) or the system default otherwise.

      universal_newlines: Alias of text, provided for backwards compatibility.

      startupinfo and creationflags (Windows only)

      restore_signals (POSIX only)

      start_new_session (POSIX only)

      pass_fds (POSIX only)

      encoding and errors: Text mode encoding and error handling to use for
          file objects stdin, stdout and stderr.

    Attributes:
        stdin, stdout, stderr, pid, returncode
    FrUNTrr)�encoding�errorsr�cCsZt�t��|_d|_d|_|dkr(d}t|t�s:td��t	rP|dk	r�t
d��n8|rh|sht�dt
�d}|
dk	rxt
d��|d	kr�t
d
��||_d|_d|_d|_d|_d|_||_||_|dk	r�|dk	r�t|�t|�kr�td��|�|||�\}}}}}}t	�rN|dk�rt�|��d	�}|dk�r4t�|��d	�}|dk�rNt�|��d	�}|�pb|�pb|�pb||_d|_d|_y�|dk�r�t� |d
|�|_|j�r�tj!|jd|dk||d�|_|dk�r�t� |d|�|_|j�r�tj!|j||d�|_|dk�rt� |d|�|_|j�rtj!|j||d�|_|�"||||||
||
||	||||||||�W�nxDt#d|j|j|jf�D]*}y|�$�Wnt%k
�r�YnX�qnW|j�sNg}|t&k�r�|�'|�|t&k�r�|�'|�|t&k�r�|�'|�t(|d��r�|�'|j)�xP|D]H}y*t	�r$t|t*��r$|�+�n
t,�$|�Wnt%k
�rFYnX�qW�YnXdS)zCreate new Popen instance.NFrUzbufsize must be an integerz0preexec_fn is not supported on Windows platformszpass_fds overriding close_fds.Tz2startupinfo is only supported on Windows platformsrz4creationflags is only supported on Windows platformszlCannot disambiguate when both text and universal_newlines are supplied but different. Pass one or the other.g�?�wbrm)�
write_through�line_bufferingr�r��rb)r�r��_devnull)-rM�	threadingZLock�
_waitpid_lock�_input�_communication_started�
isinstancerG�	TypeErrorr�r�warnings�warn�RuntimeWarningr]r�rr
�pidr
r�r��boolr�_get_handles�msvcrtZopen_osfhandlerH�	text_mode�_sigint_wait_secs�_closed_child_pipe_fds�io�open�
TextIOWrapper�_execute_child�filter�close�OSErrorr'r\�hasattrr�rCrF�os)rr]�bufsize�
executabler�rr
�
preexec_fn�	close_fdsr��cwd�envr��startupinfo�
creationflags�restore_signals�start_new_session�pass_fdsr�r�r��p2cread�p2cwrite�c2pread�c2pwrite�errread�errwrite�fZto_close�fdrrrr�s�

















zPopen.__init__cCs|jS)N)r�)rrrrr�>szPopen.universal_newlinescCst|�|_dS)N)r�r�)rr�rrrr�DscCs |�||�}|�dd��dd�S)Nz
r��
)�decode�replace)rr�r�r�rrr�_translate_newlinesHszPopen._translate_newlinescCs|S)Nr)rrrr�	__enter__LszPopen.__enter__cCs�|jr|j��|jr |j��z|jr2|j��Wd|tkrz|jdkrpy|j|jd�Wntk
rnYnXd|_dS|��XdS)Nr)r)	rr�r
r��KeyboardInterruptr��_waitrr|)r�exc_typer�	tracebackrrr�__exit__Os 


zPopen.__exit__cCsT|js
dS|jdkr(|d|jt|d�|j|d�|jdkrPtdk	rPt�|�dS)Nzsubprocess %s is still running)�source)rN)�_child_createdr
r��ResourceWarningrPrOr\)rZ_maxsizeZ_warnrrrrLks


z
Popen.__del__cCs"t|d�st�tjtj�|_|jS)Nr�)r�r�r��devnull�O_RDWRr�)rrrr�_get_devnullzs
zPopen._get_devnullc
Cs�|rZy|j�|�WnDtk
r(Yn2tk
rX}z|jtjkrFn�Wdd}~XYnXy|j��WnDtk
r|Yn2tk
r�}z|jtjkr�n�Wdd}~XYnXdS)N)r��write�BrokenPipeErrorr��errnoZEINVALr�)rr�r�rrr�_stdin_writes"zPopen._stdin_writecCsT|jr|rtd��|dkr�|js�|j|j|jg�d�dkr�d}d}|jrT|�|�n6|jrp|j��}|j��n|jr�|j��}|j��|�	�n�|dk	r�t
�|}nd}z�y|�|||�\}}Wnhtk
�r,|dk	r�t
|j|�|��}n|j}d|_y|j|d�Wntk
�r$YnX�YnXWdd|_X|j	|�|�d�}||fS)a9Interact with process: Send data to stdin and close it.
        Read data from stdout and stderr, until end-of-file is
        reached.  Wait for process to terminate.

        The optional "input" argument should be data to be sent to the
        child process, or None, if no data should be sent to the child.
        communicate() returns a tuple (stdout, stderr).

        By default, all communication is in bytes, and therefore any
        "input" should be bytes, and the (stdout, stderr) will be bytes.
        If in text mode (indicated by self.text_mode), any "input" should
        be a string, and (stdout, stderr) will be strings decoded
        according to locale encoding, or by "encoding" if set. Text mode
        is triggered by setting any of text, encoding, errors or
        universal_newlines.
        z.Cannot send input after starting communicationNr�r)rT)r�rr�rr
�countr��readr�r|�_time�_communicater��minr��_remaining_timer�r)rr�rrr
�endtime�sigint_timeout�stsrrrr��sD




zPopen.communicatecCs|��S)zSCheck if child process has terminated. Set and return returncode
        attribute.)rP)rrrrr��sz
Popen.pollcCs|dkrdS|t�SdS)z5Convenience for _communicate when computing timeouts.N)r�)rr�rrrr��szPopen._remaining_timecCsL|dkrdS|st�|krHt|j||r0d�|�nd|r@d�|�ndd��dS)z2Convenience for checking if a timeout has expired.Nr�)rr
)r�rr]r�)rr��orig_timeoutZ
stdout_seqZ
stderr_seq�skip_check_and_raiserrr�_check_timeout�szPopen._check_timeoutcCs�|dk	rt�|}y|j|d�Stk
r�|dk	rJt|j|�|��}n|j}d|_y|j|d�Wntk
rzYnX�YnXdS)z=Wait for child process to terminate; returns self.returncode.N)rr)r�r�r�r�r�r�r)rrr�r�rrrr|�s
z
Popen.waitcCs~|dkr|dkr|dkrdSd\}}d\}}d\}}	|dkrtt�tj�}|dkr�t�dd�\}}
t|�}t�|
�nh|tkr�t�dd�\}}t|�t|�}}n<|tkr�t�	|�
��}n$t|t�r�t�	|�}nt�	|�
��}|�|�}|dk�r*t�tj�}|dk�r�t�dd�\}
}t|�}t�|
�nn|tk�rXt�dd�\}}t|�t|�}}n@|tk�rrt�	|�
��}n&t|t��r�t�	|�}nt�	|�
��}|�|�}|dk�r�t�tj�}	|	dk�rdt�dd�\}
}	t|	�}	t�|
�n~|tk�rt�dd�\}}	t|�t|	�}}	nP|tk�r$|}	n@|tk�r>t�	|�
��}	n&t|t��rVt�	|�}	nt�	|�
��}	|�|	�}	||||||	fS)z|Construct and return tuple with IO objects:
            p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite
            N)rUrUrUrUrUrU)rUrUr)rKZGetStdHandler3Z
CreatePiperCrEr'r/r�Z
get_osfhandler�r�rG�fileno�_make_inheritabler4r5r()rr�rr
r�r�r�r�r�r��_rrrr�sn












zPopen._get_handlescCs&t�t��|t��ddtj�}t|�S)z2Return a duplicate of handle, which is inheritablerrm)rKZDuplicateHandleZGetCurrentProcessZDUPLICATE_SAME_ACCESSrC)r�handle�hrrrr�Zs

zPopen._make_inheritablecCstdd�|D��S)z�Filter out console handles that can't be used
            in lpAttributeList["handle_list"] and make sure the list
            isn't empty. This also removes duplicate handles.cSs,h|]$}|d@dks$t�|�tjkr|�qS)�)rKZGetFileTypeZFILE_TYPE_CHAR)�.0r�rrr�	<setcomp>jsz,Popen._filter_handle_list.<locals>.<setcomp>)r#)rr!rrr�_filter_handle_listcszPopen._filter_handle_listcCsDt|t�st|�}|dkr"t�}n|��}d|||fk}|r^|jtjO_||_||_	||_
|j}t|oxd|kox|d�}|s�|r�|r�|dkr�i}|_t
|�dg��}|d<|r�|t|�t|�t|�g7}|�|�|dd�<|r�|s�t�dt�d}|
�r�|jtjO_tj|_|�sxtj�d�}|�sdtj�dd�}tj�|d	d
�}tj�|��sdtd��tj�|��r||}n|}d�||�}z@t�||ddt|�|	||dk	�r�t�|�nd|�	\}}}}Wd|dk�r�|� �|dk�r�|� �|dk�r|� �t!|d
��rt�"|j#�d|_$Xd|_%t&|�|_'||_(t�)|�dS)z$Execute program (MS Windows version)NrUr!z?startupinfo.lpAttributeList['handle_list'] overriding close_fdsFZComSpecZ
SystemRootr�ZSystem32zcmd.exez:shell not found: neither %ComSpec% nor %SystemRoot% is setz
{} /c "{}"r�T)*r��strr�rr$rrKr7rrrr r�r#r�rGr�r�r�r�r8r6rr��environ�pathr��isabs�FileNotFoundErrorr�Z
CreateProcess�fspathrFr�r�r�r�r�rC�_handler�rE)rr]r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�Zunused_restore_signalsZunused_start_new_sessionZuse_std_handlesZattribute_listZhave_handle_listr!ZcomspecZsystem_rootZhpZhtr��tidrrrr�ps|






zPopen._execute_childcCs,|jdkr&||jd�|kr&||j�|_|jS)z�Check if child process has terminated.  Returns returncode
            attribute.

            This method is called by __del__, so it can only refer to objects
            in its local scope.

            Nr)r
r)rrNZ_WaitForSingleObjectZ_WAIT_OBJECT_0Z_GetExitCodeProcessrrrrP�s
zPopen._internal_pollcCs^|dkrtj}nt|d�}|jdkrXt�|j|�}|tjkrJt|j|��t�	|j�|_|jS)z-Internal implementation of wait() on Windows.Ni�)
rKZINFINITErGr
�WaitForSingleObjectrZWAIT_TIMEOUTrr]�GetExitCodeProcess)rrZtimeout_millisr�rrrr��s

zPopen._waitcCs|�|���|��dS)N)r\r�r�)rZfh�bufferrrr�
_readerthreadszPopen._readerthreadcCs\|jrBt|d�sBg|_tj|j|j|jfd�|_d|j_|j��|j	r�t|d�s�g|_
tj|j|j	|j
fd�|_d|j_|j��|jr�|�
|�|jdk	r�|j�|�|��|j��r�t|j|��|j	dk	r�|j�|�|��|j��r�t|j|��d}d}|j�r|j}|j��|j	�r0|j
}|j	��|dk	�rB|d}|dk	�rT|d}||fS)N�_stdout_buff)�targetr]T�_stderr_buffr)rr�rr�ZThreadrZ
stdout_threadZdaemon�startr
r
Z
stderr_threadr�r�r�r�Zis_aliverr]r�)rr�r�r�rr
rrrr�sF










zPopen._communicatecCsl|jdk	rdS|tjkr"|��nF|tjkr>t�|jtj�n*|tjkrZt�|jtj�nt	d�
|���dS)zSend a signal to the process.NzUnsupported signal: {})r
r�SIGTERM�	terminateZCTRL_C_EVENTr�r}r�ZCTRL_BREAK_EVENTrr�)r�sigrrr�send_signal;s




zPopen.send_signalcCsX|jdk	rdSyt�|jd�Wn2tk
rRt�|j�}|tjkrH�||_YnXdS)zTerminates the process.Nrm)r
rKZTerminateProcessr�PermissionErrorrZSTILL_ACTIVE)rZrcrrrr
Is

zPopen.terminatec
Cs,d\}}d\}}d\}}	|dkr"n@|tkr8t��\}}n*|tkrJ|��}nt|t�rZ|}n|��}|dkrln@|tkr�t��\}}n*|tkr�|��}nt|t�r�|}n|��}|dkr�nf|tkr�t��\}}	nP|tkr�|dkr�|}	n
t	j
��}	n.|tk�r|��}	nt|t��r|}	n|��}	||||||	fS)z|Construct and return tuple with IO objects:
            p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite
            )rUrUNrU)r'r��piper/r�r�rGr�r(rQ�
__stdout__)
rr�rr
r�r�r�r�r�r�rrrr�^sJ





c*s�t|ttf�r|g}nt|�}|
rLttd�r0dnd}|dg|}�rL�|d<�dkr\|d��}t��\}}g}x |dkr�|�|�t�	|�}qrWx|D]}t�
|�q�W�z�z�|dk	�rg}xL|��D]:\}}t�|�}d|kr�t
d	��|�|dt�|��q�Wnd}t����tj����r,�f}nt�fd
d�t�|�D��}t|�}|�|�t�|||tttt|���|||||
||||||||�|_d|_Wdt�
|�Xt|d
d�}|dk�r�|dk�r�||k�r�t�
|�|dk�r|
dk�r||k�rt�
|�|dk�r.|dk�r.||k�r.t�
|�|dk	�rBt�
|�d|_t�}x0t�|d�} || 7}| �rxt|�dk�rPP�qPWWdt�
|�X|�r�y6t� |jd�\}!}"|!|jk�r�|�!|"�ntj"|_#Wnt$k
�r�YnXy|�%dd�\}#}$}%|%�&�}%Wn,t
k
�r.d}#d}$d�'t|��}%YnXtt(|#�&d�t)�}&t*|&t+��r�|$�r�t|$d�}'|%dk}(|(�rvd}%|})n|})|'dk�r�t�,|'�}%|'t-j.k�r�|%dt/|)�7}%|&|'|%|)��|&|%��dS)zExecute program (POSIX version)Zgetandroidapilevelz/system/bin/shz/bin/shz-crNr��=z!illegal environment variable namec3s"|]}tj�t�|���VqdS)N)r�r�r��fsencode)r��dir)r�rr�	<genexpr>�sz'Popen._execute_child.<locals>.<genexpr>Tr�rUiP��:r�sSubprocessError�0z#Bad exception data from child: {!r}�ascii�Znoexecr�z: )0r�r��bytesr#r�rQr�rr\�dupr�rqrrr��dirname�tuple�
get_exec_path�set�add�_posixsubprocessZ	fork_exec�sorted�maprGr�r�rrr��	bytearrayr�r��waitpid�_handle_exitstatusrRr
�ChildProcessError�splitr�r��builtinsr�
issubclassr��strerrorr�ZENOENT�repr)*rr]r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�Z
unix_shellZorig_executableZerrpipe_readZ
errpipe_writeZlow_fds_to_closeZlow_fdZenv_list�krbZexecutable_listZfds_to_keepZ
devnull_fdZerrpipe_data�partr�r�Zexception_nameZ	hex_errnoZerr_msgZchild_exception_typeZ	errno_numZchild_exec_never_calledZerr_filenamer)r�rr��s�	

















cCsL||�r||�|_n2||�r*||�|_n||�r@||�|_ntd��dS)z:All callers to this function MUST hold self._waitpid_lock.zUnknown child exit status!N)r
r)rr�Z_WIFSIGNALEDZ	_WTERMSIGZ
_WIFEXITEDZ_WEXITSTATUSZ_WIFSTOPPEDZ	_WSTOPSIGrrrr'#szPopen._handle_exitstatusc
Cs�|jdkr�|j�d�sdSz�y8|jdk	r.|jS||j|�\}}||jkrR|�|�WnBtk
r�}z$|dk	rv||_n|j|kr�d|_Wdd}~XYnXWd|j��X|jS)z�Check if child process has terminated.  Returns returncode
            attribute.

            This method is called by __del__, so it cannot reference anything
            outside of the local scope (nor can any methods it calls).

            NFr)r
r��acquirer�r'r�r��release)rrNZ_waitpidZ_WNOHANGZ_ECHILDr�r��errrrP5s 	



cCs>yt�|j|�\}}Wntk
r4|j}d}YnX||fS)z:All callers to this function MUST hold self._waitpid_lock.r)r�r&r�r()rZ
wait_flagsr�r�rrr�	_try_waitXs
zPopen._try_waitc	Cs|jdk	r|jS|dk	r�t�|}d}x�|j�d�rxz6|jdk	rBP|�tj�\}}||jkrh|�|�PWd|j�	�X|�
|�}|dkr�t|j|��t
|d|d�}t�|�q(WnRxP|jdk�r|j�4|jdk	r�P|�d�\}}||jkr�|�|�WdQRXq�W|jS)z+Internal implementation of wait() on POSIX.Ng����Mb@?Frr�g�������?)r
r�r�r0r3r��WNOHANGr�r'r1r�rr]r��timeZsleep)rrr�Zdelayr�r�Z	remainingrrrr�es8







c
Cs,|jrX|jsXy|j��Wntk
r.YnX|sXy|j��Wntk
rVYnXd}d}|js�i|_|jr~g|j|j<|jr�g|j|j<|jr�|j|j}|jr�|j|j}|�|�|j	r�t
|j	�}t����}|jr�|r�|�|jt
j�|j�r|jj�s|�|jt
j�|j�r6|jj�s6|�|jt
j��x^|���r�|�|�}|dk	�r~|dk�r~|j||||dd�td��|�|�}	|�||||�x�|	D]�\}
}|
j|jk�r<||j|jt�}y|jt�|
j|�7_Wn,tk
�r|�|
j�|
j��Yn*X|jt|j	�k�r�|�|
j�|
j��nP|
j|j|jfk�r�t�|
jd�}
|
�sz|�|
j�|
j��|j|
j�|
��q�W�q:WWdQRX|j |�|�d�|dk	�r�d�!|�}|dk	�r�d�!|�}|j"�r$|dk	�r|�#||jj$|jj%�}|dk	�r$|�#||jj$|jj%�}||fS)NrT)r�zN_check_timeout(..., skip_check_and_raise=True) failed to raise TimeoutExpired.i�)rr�)&r�r��flushr�r�Z_fileobj2outputrr
�_save_inputr��
memoryview�_PopenSelector�register�	selectorsZEVENT_WRITErDZ
EVENT_READZget_mapr�r��RuntimeError�selectZfileobj�
_input_offset�	_PIPE_BUFr�r�r�Z
unregisterr�r�r\r|r�r�r�r�r�)rr�r�r�rr
Z
input_viewZselectorrZready�keyZevents�chunkr�rrrr��s�






(







cCsF|jrB|jdkrBd|_||_|dk	rB|jrB|j�|jj|jj�|_dS)Nr)r�r�r>r��encoder�r�)rr�rrrr7�szPopen._save_inputcCs|jdkrt�|j|�dS)zSend a signal to the process.N)r
r�r}r�)rrrrrrs
cCs|�tj�dS)z/Terminate the process with SIGTERM
            N)rrr)rrrrr
scCs|�tj�dS)z*Kill the process with SIGKILL
            N)rr�SIGKILL)rrrrr}sz
Popen.kill)rUNNNNNTFNNNNrTFr)NN)F)N)6rrrrr�rrr�rr�r�r�rQrRr�r�rLr�r�r�r�r�r�r|r�r�r�r�r�rKrZ
WAIT_OBJECT_0rrPr�rr�rr
r}r��WIFSIGNALED�WTERMSIG�	WIFEXITED�WEXITSTATUS�
WIFSTOPPED�WSTOPSIGr'r&r4r�ZECHILDr3r7rrrrr&ysl-
D	

H	
q46"
)f)ErrQ�platformr�r�r�r5rr*r�r�rr��	Exceptionrr	rr�r�rKrr"r=r;rrr?r�r%r9ZSelectSelector�__all__r1r2r3r4r5r6r7r8r9r:r;r<r=r>r?r@rArBrwrGrCrOrMr'r(r/r^r{r)r*r-�objectr0r.r�r+r,r&rrrr�<module>*sz
%


P

	


;/"DI