AlkantarClanX12

Your IP : 3.133.145.17


Current Path : /opt/alt/python310/lib64/python3.10/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/__pycache__/subprocess.cpython-310.pyc

o

6��f�K�@spdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
Z
zddlZWneyEdZYnwgd�ZzddlZddlZdZWneymdZddlZddlZddlZYn0wddlmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)e�*gd��Gd	d
�d
e+�Z,Gdd�de,�Z-Gd
d�de,�Z.er�Gdd�d�Z/Gdd�de0�Z1ne2edd�Z3e4ed�r�ej5Z6nej7Z6er�dZ8dd�Z9ngZ8dd�Z9dZ:dZ;dZ<dd�Z=dd�Z>dd �d!d"�Z?d#d$�Z@dd �d%d&�ZAGd'd(�d(eB�ZCddddd)�d*d+�ZDd,d-�ZEd.d/�ZFd0d1�ZGd2d3�ZHeH�ZIdZJGd4d5�d5�ZKdS)6a�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
�N)�	monotonic)�Popen�PIPE�STDOUT�call�
check_call�getstatusoutput�	getoutput�check_output�run�CalledProcessError�DEVNULL�SubprocessError�TimeoutExpired�CompletedProcessTF)�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_JOB)rrrrrrrr�STARTUPINFOrrrrrrrr r!r"c@seZdZdS)rN)�__name__�
__module__�__qualname__�r'r'�1/opt/alt/python310/lib64/python3.10/subprocess.pyresrc@�<eZdZdZd
dd�Zdd�Zedd��Zejd	d��ZdS)rz�Raised when run() is called with check=True and the process
    returns a non-zero exit status.

    Attributes:
      cmd, returncode, stdout, stderr, output
    NcC�||_||_||_||_dS�N)�
returncode�cmd�output�stderr)�selfr,r-r.r/r'r'r(�__init__o�
zCalledProcessError.__init__cCs`|jr(|jdkr(z
d|jt�|j�fWSty'd|j|jfYSwd|j|jfS)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�r0r'r'r(�__str__us�

���zCalledProcessError.__str__cC�|jS)z+Alias for output attribute, to match stderr�r.r5r'r'r(�stdout�szCalledProcessError.stdoutcC�
||_dSr+r8�r0�valuer'r'r(r9��
�NN�	r$r%r&�__doc__r1r6�propertyr9�setterr'r'r'r(rhs

rc@r))rz�This exception is raised when the timeout expires while waiting for a
    child process.

    Attributes:
        cmd, output, stdout, stderr, timeout
    NcCr*r+)r-�timeoutr.r/)r0r-rCr.r/r'r'r(r1�r2zTimeoutExpired.__init__cCsd|j|jfS)Nz'Command '%s' timed out after %s seconds)r-rCr5r'r'r(r6�s
�zTimeoutExpired.__str__cCr7r+r8r5r'r'r(r9�szTimeoutExpired.stdoutcCr:r+r8r;r'r'r(r9�r=r>r?r'r'r'r(r�s

rc@s,eZdZddddddd�dd�Zdd�ZdS)r#rN��dwFlags�	hStdInput�
hStdOutput�	hStdError�wShowWindow�lpAttributeListcCs0||_||_||_||_||_|pdgi|_dS)N�handle_listrD)r0rErFrGrHrIrJr'r'r(r1�szSTARTUPINFO.__init__cCs@|j��}d|vrt|d�|d<t|j|j|j|j|j|d�S)NrKrD)	rJ�copy�listr#rErFrGrHrI)r0Z	attr_listr'r'r(rL�s
�zSTARTUPINFO.copy)r$r%r&r1rLr'r'r'r(r#�s
�	r#c@s2eZdZdZejfdd�Zdd�Zdd�ZeZ	dS)	�HandleFcCs|jsd|_||�dSdS)NT)�closed)r0�CloseHandler'r'r(�Close�s�zHandle.ClosecCs|js
d|_t|�Std��)NTzalready closed)rO�intr4r5r'r'r(�Detach�sz
Handle.DetachcCsd|jjt|�fS)Nz%s(%d))�	__class__r$rRr5r'r'r(�__repr__�szHandle.__repr__N)
r$r%r&rO�_winapirPrQrSrU�__del__r'r'r'r(rN�srNZPIPE_BUFi�PollSelectorcCsdSr+r'r'r'r'r(�_cleanup��rYc	CsZtdurdStdd�D]}|jtjd�}|dur*zt�|�Wqty)YqwqdS)N��
_deadstate)�_active�_internal_poll�sys�maxsize�remover4)�inst�resr'r'r(rY�s������������cCs*g}tjj}|dkr|�dd|�|S)zgReturn a list of command-line arguments reproducing the current
    optimization settings in sys.flags.r�-�O)r_�flags�optimize�append)�argsr<r'r'r(�"_optim_args_from_interpreter_flagss
rmcCsNddddddd�}t�}|��D]\}}ttj|�}|dkr'|�d	||�qtjjr2|�d
�ntjjr;|�d�tjjrD|�d�tj	d
d
�}tjj
}ttdi�}d|v}|dkrc|�d�n|rj|�d�|rq|�d�|D]	}|�d|�qs|r�|�d�dD]}||vr�||}	|	dur�|}
nd||	f}
|�d|
f�q�|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�quietrrgz-Iz-Ez-sN�	_xoptions�dev�zerror::BytesWarningzdefault::BytesWarning�defaultz-W)�-Xr{)Zfaulthandler�tracemallocZ
importtimeZshowrefcount�utf8Tz%s=%sr~)
rm�items�getattrr_rirk�isolated�ignore_environment�no_user_site�warnoptionsrxra�extend)Zflag_opt_maprl�flag�optrqZwarnoptsrxZxoptions�dev_moder<�argr'r'r(�_args_from_interpreter_flagssT��




�r��rCcOsRt|i|���}z|j|d�WWd�S|���1s"wYdS)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"])
    r�N)r�wait�kill)rC�	popenargs�kwargs�pr'r'r(rQs��rcOs:t|i|��}|r|�d�}|dur|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"])
    rlNr)r�getr)r�r��retcoder-r'r'r(rbs


rcOsvd|vrtd��d|vr/|ddur/|�d�s&|�d�s&|�d�s&|�d�r)d	}nd
}||d<t|t|dd�|��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.
    r9z3stdout argument not allowed, it will be overridden.�inputN�universal_newlines�text�encoding�errors��T)r9rC�check)r4r�rrr9)rCr�r��emptyr'r'r(r
us#���r
c@s4eZdZdZd	dd�Zdd�Zeej�Z	dd�Z
dS)
raEA 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).
    NcCr*r+)rlr,r9r/)r0rlr,r9r/r'r'r(r1�r2zCompletedProcess.__init__cCshd�|j�d�|j�g}|jdur|�d�|j��|jdur(|�d�|j��d�t|�jd�|��S)Nz	args={!r}zreturncode={!r}zstdout={!r}zstderr={!r}z{}({})z, )	�formatrlr,r9rkr/�typer$�join)r0rlr'r'r(rU�s

�

zCompletedProcess.__repr__cCs |jrt|j|j|j|j��dS)z6Raise CalledProcessError if the exit code is non-zero.N)r,rrlr9r/r5r'r'r(�check_returncode�s
��z!CompletedProcess.check_returncoder>)r$r%r&r@r1rU�classmethod�types�GenericAlias�__class_getitem__r�r'r'r'r(r�s


	r)r��capture_outputrCr�cOs$|dur|�d�durtd��t|d<|r/|�d�dus#|�d�dur'td��t|d<t|d<t|i|���L}z|j||d�\}}Wn'tyb}	z|��trY|��\|	_|	_	�|�
��d}	~	w|���|��}
|r{|
r{t|
|j
||d��Wd�n1s�wYt|j
|
||�S)	a|Run 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,
    or pass capture_output=True to capture both.

    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.r9r/z@stdout and stderr arguments may not be used with capture_output.r��r.r/)r�r4rr�communicaterr��
_mswindowsr9r/r��pollrrlr)r�r�rCr�r�r�Zprocessr9r/�excr�r'r'r(r�s>�����rcCs�g}d}ttj|�D]d}g}|r|�d�d|vpd|vp|}|r'|�d�|D]1}|dkr5|�|�q)|dkrL|�dt|�d�g}|�d�q)|rU|�|�g}|�|�q)|rb|�|�|rn|�|�|�d�q
d�|�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�)�map�os�fsdecoderk�lenr�r�)�seq�resultZ	needquoter�Zbs_buf�cr'r'r(�list2cmdlines6





�
r�c
Csnzt|ddtd�}d}Wnty$}z|j}|j}WYd}~nd}~ww|dd�dkr3|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)�shellr�r/rNrd�
)r
rrr.r,)r-�dataZexitcodeZexr'r'r(r\s��rcCs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'
    r|)r)r-r'r'r(r	{s
r	c
Cs�tsttd�s	dStjdvrdSz<t�d�}|jdd�}t|�dkr$t�|d	}t	t
t|d�d
���}tjdkrD|dkrG|d
krJWdSWdSWdSWdSttt
fyYYdSw)a�Check if posix_spawn() can be used for subprocess.

    subprocess requires a posix_spawn() implementation that properly reports
    errors to the parent process, & sets errno on the following failures:

    * Process attribute actions failed.
    * File actions failed.
    * exec() failed.

    Prefer an implementation which can use vfork() in some cases for best
    performance.
    �posix_spawnF)�darwinZsunos5T�CS_GNU_LIBC_VERSIONr|)�maxsplitr�r�.ZlinuxZglibc)r��)r��hasattrr�r_�platform�confstr�splitr�r4�tupler�rR�AttributeError�OSError)Zver�partsZlibc�versionr'r'r(�_use_posix_spawn�s.


�����r�c
@s�eZdZdZdZ							dMddddddddd�d	d
�Zdd�Zeej	�Z
ed
d��Zej
dd��Zdd�Zdd�Zdd�Zejejfdd�Zdd�Zdd�ZdNdd�Zdd�Zd d!�Z	dOd"d#�ZdPd$d%�Zd&d'�Zer�d(d)�Zd*d+�Z d,d-�Z!d.d/�Z"de#j$e#j%e#j&fd0d1�Z'd2d3�Z(d4d5�Z)d6d7�Z*d8d9�Z+d:d;�Z,e,Z-dSd<d)�Zd=d>�Z.d?d/�Z"e/j0e/j1e/j2fd@dA�Z3de/j4e/j5e6j7fdBd1�Z'dCdD�Z8dEd3�Z(dFd7�Z*dGdH�Z9dId9�Z+dJd;�Z,dKdL�Z-dS)QraP 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)

      group (POSIX only)

      extra_groups (POSIX only)

      user (POSIX only)

      umask (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
    FrdNTrr')�user�group�extra_groupsr�r�r��umask�pipesizec+Cs�t�t��|_d|_d|_|durd}t|t�std��|dur#d}t|t�s,td��t	r7|dur6t
d��n|rC|sCt�dt
�d}|
durKt
d	��|d
krSt
d��||_d|_d|_d|_d|_d|_||_||_||_|dur�|dur�t|�t|�kr�td��|�|||�\}}}}}}t	r�|dkr�t�|��d
�}|dkr�t�|��d
�}|dkr�t�|��d
�}|p�|p�|p�||_|jr�|dur�d
|_}d|_d|_|jr�|dkr�d} d}nd} d}!|du�r,t t!d�s�t
d��t|t"��rzd
dl#}"Wnt$�yt
d��w|"�%|�j&}!nt|t��r|}!n	td�'t(|����|!d
k�r,t
d|!����d}#|du�r�t t!d��s=t
d��t|t"��rGt
d��g}#|D];}$t|$t"��rqzd
dl#}"Wnt$�yet
d��w|#�)|"�%|$�j&��qKt|$t��r~|#�)|$��qKtd�'t(|$����|#D]}%|%d
k�r�t
d|%�����q�d}&|du�r�t t!d��s�t
d��t|t"��r�zd
dl*}'Wnt$�y�t
d��w|'�+|�j,}&n
t|t��r�|}&ntd��|&d
k�r�t
d|&����zp|dk�rt-�.|d|�|_|j�rt-j/|jd| ||d �|_|dk�rt-�.|d!|�|_|j�rt-j/|j||d"�|_|dk�r7t-�.|d!|�|_|j�r7t-j/|j||d"�|_|�0||||||
||
||	||||||||!|#|&||�WdSt1d|j|j|jf�D]}(z|(�2�W�qbt3�yvY�qbw|j�s�g})|t4k�r�|)�)|�|t4k�r�|)�)|�|t4k�r�|)�)|�t |d#��r�|)�)|j5�|)D]#}*zt	�r�t|*t6��r�|*�7�nt!�2|*�W�q�t3�y�Y�q�w�)$zCreate new Popen instance.NFrdzbufsize must be an integerzpipesize 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.�localeg�?r|�setregidz>The 'group' parameter is not supported on the current platformzHThe group parameter cannot be a string on systems without the grp modulez,Group must be a string or an integer, not {}z!Group ID cannot be negative, got �	setgroupszEThe 'extra_groups' parameter is not supported on the current platformz#Groups must be a list, not a stringzIItems in extra_groups cannot be strings on systems without the grp modulez9Items in extra_groups must be a string or integer, not {}�setreuidz=The 'user' parameter is not supported on the current platformzGThe user parameter cannot be a string on systems without the pwd modulez#User must be a string or an integerz User ID cannot be negative, got �wb)�
write_through�line_bufferingr�r��rb)r�r��_devnull)8rY�	threadingZLock�
_waitpid_lock�_input�_communication_started�
isinstancerR�	TypeErrorr�r4�warnings�warn�RuntimeWarningrlr�r9r/�pidr,r�r�r��boolr�_get_handles�msvcrtZopen_osfhandlerS�	text_mode�_sigint_wait_secs�_closed_child_pipe_fdsr�r��str�grp�ImportErrorZgetgrnamZgr_gidr�r�rk�pwd�getpwnamZpw_uid�io�open�
TextIOWrapper�_execute_child�filter�closer�rr�rNrQ)+r0rl�bufsize�
executabler�r9r/�
preexec_fn�	close_fdsr��cwd�envr��startupinfo�
creationflags�restore_signals�start_new_session�pass_fdsr�r�r�r�r�r�r�r��p2cread�p2cwrite�c2pread�c2pwrite�errread�errwriter��gidr��gidsZextra_groupZ	gid_check�uidr��fZto_close�fdr'r'r(r1�sV	


��


�
�

�
�
�
�


�
�
�
�	�







��zPopen.__init__cCs@d|jj�d|j�d|j�d�}t|�dkr|dd�d}|S)N�<z: returncode: z args: �>�P�Lz...>)rTr$r,rlr�)r0Zobj_reprr'r'r(rU�s���zPopen.__repr__cCr7r+)r�r5r'r'r(r��szPopen.universal_newlinescCst|�|_dSr+)r�r�)r0r�r'r'r(r�scCs |�||�}|�dd��dd�S)Nz
r��
)�decode�replace)r0r�r�r�r'r'r(�_translate_newlinesszPopen._translate_newlinescCs|Sr+r'r5r'r'r(�	__enter__
rZzPopen.__enter__cCs�|jr|j��|jr|j��z0|jr|j��W|tkr;|jdkr6z	|j|jd�Wn	ty5Ynwd|_dS|��dS|tkrf|jdkr]z	|j|jd�Wn	ty\Ynwd|_YdS|��w)Nrr�)	r9r�r/r��KeyboardInterruptr��_waitrr�)r0�exc_typer<�	tracebackr'r'r(�__exit__
s8


�
��
�
zPopen.__exit__cCs\|jsdS|jdur|d|jt|d�|j|d�|jdur*tdur,t�|�dSdSdS)Nzsubprocess %s is still running)�sourcer[)�_child_createdr,r��ResourceWarningr^r]rk)r0Z_maxsizeZ_warnr'r'r(rW)s

��z
Popen.__del__cCs"t|d�st�tjtj�|_|jS)Nr�)r�r�r��devnull�O_RDWRr�r5r'r'r(�_get_devnull8s
zPopen._get_devnullc
Cs�|r-z|j�|�Wn"tyYnty,}z|jtjkr!n�WYd}~nd}~wwz|j��WdSty?YdStyY}z|jtjkrMn�WYd}~dSd}~wwr+)r��write�BrokenPipeErrorr��errnoZEINVALr�)r0r�r�r'r'r(�_stdin_write=s.���	���zPopen._stdin_writecCsR|jr	|r	td��|durM|jsM|j|j|jg�d�dkrMd}d}|jr*|�|�n|jr8|j��}|j��n
|jrE|j��}|j��|�	�||fS|durWt
�|}nd}z>z|�|||�\}}Wn-ty�|durzt
|j|�|��}n|j}d|_z|j|d�W�ty�Y�wwWd|_nd|_w|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�rr�T)r�r4r�r9r/�countr#�readr�r��_time�_communicater�minr��_remaining_timerr)r0r�rCr9r/�endtime�sigint_timeout�stsr'r'r(r�VsP



������zPopen.communicatecCs|��S)zSCheck if child process has terminated. Set and return returncode
        attribute.)r^r5r'r'r(r��sz
Popen.pollcCs|durdS|t�S)z5Convenience for _communicate when computing timeouts.N)r&)r0r*r'r'r(r)�s
zPopen._remaining_timecCsP|durdS|s
t�|kr&t|j||rd�|�nd|r"d�|�d��dd��dS)z2Convenience for checking if a timeout has expired.Nr�r�)r&rrlr�)r0r*�orig_timeoutZ
stdout_seqZ
stderr_seq�skip_check_and_raiser'r'r(�_check_timeout�s���zPopen._check_timeoutcCs||dur	t�|}z|j|d�WSty=|dur%t|j|�|��}n|j}d|_z|j|d�W�ty<Y�ww)z=Wait for child process to terminate; returns self.returncode.Nr�r)r&rrr(r�r)r)r0rCr*r+r'r'r(r��s&
����z
Popen.waitc	Cst|dd�}t���m}tr,|dkr|�|j�|dkr!|�|j�|dkr+|�|j�n9|dkr?|dkr?||kr?|�tj|�|dkrR|dkrR||krR|�tj|�|dkre|dkre||kre|�tj|�|durp|�tj|�Wd�n1szwYd|_dS)Nr�rdT)	r��
contextlib�	ExitStackr��callbackrQr�r�r�)	r0rrrrrrZ
devnull_fd�stackr'r'r(�_close_pipe_fds�s*
���
zPopen._close_pipe_fdscCsp|dur|dur|durdSd\}}d\}}d\}}	|dur:t�tj�}|dur9t�dd�\}}
t|�}t�|
�n4|tkrPt�dd�\}}t|�t|�}}n|tkr\t�	|�
��}nt|t�rgt�	|�}nt�	|�
��}|�|�}|dur�t�tj�}|dur�t�dd�\}
}t|�}t�|
�n4|tkr�t�dd�\}}t|�t|�}}n|tkr�t�	|�
��}nt|t�r�t�	|�}nt�	|�
��}|�|�}|dur�t�tj�}	|	dur�t�dd�\}
}	t|	�}	t�|
�n?|tk�rt�dd�\}}	t|�t|	�}}	n(|tk�r|}	n |tk�rt�	|�
��}	nt|t��r$t�	|�}	nt�	|�
��}	|�|	�}	||||||	fS)�|Construct and return tuple with IO objects:
            p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite
            N)rdrdrdrdrdrd�rdrdr)rVZGetStdHandlerZ
CreatePiperNrPrr
r�Z
get_osfhandlerr�rR�fileno�_make_inheritablerrr)r0r�r9r/rrrrrr�_r'r'r(r��sv
�


�


�



�zPopen._get_handlescCs&t�t��|t��ddtj�}t|�S)z2Return a duplicate of handle, which is inheritablerr|)rVZDuplicateHandleZGetCurrentProcessZDUPLICATE_SAME_ACCESSrN)r0�handle�hr'r'r(r84s
�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@dkst�|�tjkr|�qS)�)rVZGetFileTypeZFILE_TYPE_CHAR)�.0r:r'r'r(�	<setcomp>Ds��z,Popen._filter_handle_list.<locals>.<setcomp>)rM)r0rKr'r'r(�_filter_handle_list=szPopen._filter_handle_listc!Cs�|rJd��t|t�rn't|t�r|
rtd��t|g�}nt|tj�r/|
r)td��t|g�}nt|�}|dur<t�|�}|durDt�}n|�	�}d|||fv}|rb|j
tjO_
||_
||_||_|j}t|ood|voo|d�}|sw|r�|r�|dur�i}|_t|�dg��}|d<|r�|t|�t|�t|�g7}|�|�|dd�<|r�|s�t�dt�d}|
r�|j
tjO_
tj|_|s�tj�d	�}|s�tj�d
d�}tj�|dd
�}tj�|�s�t d��tj�|�r�|}n|}d�!||�}|dur�t�|�}t"�#d||||�z t�$||ddt|�|	|||�	\}}}} W|�%|||
|||�n|�%|||
|||�wd|_&t'|�|_(||_)t�*|�dS)z$Execute program (MS Windows version)z"pass_fds not supported on Windows.z$bytes args is not allowed on Windows�0path-like args is not allowed when shell is trueNrdrKz?startupinfo.lpAttributeList['handle_list'] overriding close_fdsFZComSpecZ
SystemRootr�ZSystem32zcmd.exez:shell not found: neither %ComSpec% nor %SystemRoot% is setz
{} /c "{}"�subprocess.PopenT)+r�r��bytesr�r�r��PathLiker�r#rLrErVrrFrGrHrJr�rMr�rRr?r�r�r�rrrI�environ�pathr��isabs�FileNotFoundErrorr�r_�auditZ
CreateProcessr4rrN�_handler�rP)!r0rlr�r�r�rr�r�r�r�r�rrrrrrZunused_restore_signalsZ
unused_gidZunused_gidsZ
unused_uidZunused_umaskZunused_start_new_sessionZuse_std_handlesZattribute_listZhave_handle_listrKZcomspecZsystem_rootZhpZhtr��tidr'r'r(r�Js�


��

���
���
zPopen._execute_childcCs,|jdur||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,rI)r0r\Z_WaitForSingleObjectZ_WAIT_OBJECT_0Z_GetExitCodeProcessr'r'r(r^�s
zPopen._internal_pollcCs^|durtj}nt|d�}|jdur,t�|j|�}|tjkr%t|j|��t�	|j�|_|jS)z-Internal implementation of wait() on Windows.Ni�)
rVZINFINITErRr,�WaitForSingleObjectrIZWAIT_TIMEOUTrrl�GetExitCodeProcess)r0rCZtimeout_millisr�r'r'r(r�s
�
zPopen._waitcCs|�|���|��dSr+)rkr%r�)r0Zfh�bufferr'r'r(�
_readerthread�szPopen._readerthreadcCsT|jr!t|d�s!g|_tj|j|j|jfd�|_d|j_|j��|j	rBt|d�sBg|_
tj|j|j	|j
fd�|_d|j_|j��|jrJ|�
|�|jdurc|j�|�|��|j��rct|j|��|j	dur||j�|�|��|j��r|t|j|��d}d}|jr�|j}|j��|j	r�|j
}|j	��|r�|dnd}|r�|dnd}||fS)N�_stdout_buff)�targetrlT�_stderr_buffr)r9r�rOr�ZThreadrNZ
stdout_threadZdaemon�startr/rQZ
stderr_threadr�r#r�r)Zis_aliverrlr�)r0r�r*r-r9r/r'r'r(r'�sJ
��

��







zPopen._communicatecCsn|jdurdS|tjkr|��dS|tjkr!t�|jtj�dS|tjkr0t�|jtj�dSt	d�
|���)�Send a signal to the process.NzUnsupported signal: {})r,r3�SIGTERM�	terminateZCTRL_C_EVENTr�r�r�ZCTRL_BREAK_EVENTr4r��r0Zsigr'r'r(�send_signal!s



zPopen.send_signalcCsV|jdurdSz
t�|jd�WdSty*t�|j�}|tjkr$�||_YdSw)zTerminates the process.Nr|)r,rVZTerminateProcessrI�PermissionErrorrLZSTILL_ACTIVE)r0Zrcr'r'r(rU/s

�zPopen.terminatec
Cs�d\}}d\}}d\}}	|durn3|tkr/t��\}}|jdkr.ttd�r.t�|tj|j�n|tkr8|��}nt	|t
�r@|}n|��}|durIn3|tkrgt��\}}|jdkrfttd�rft�|tj|j�n|tkrp|��}nt	|t
�rx|}n|��}|dur�nD|tkr�t��\}}	|jdkr�ttd�r�t�|	tj|j�n&|tkr�|dkr�|}	nt
j��}	n|tkr�|��}	nt	|t
�r�|}	n|��}	||||||	fS)r5r6Nr�F_SETPIPE_SZrd)rr��piper�r��fcntlrYr
rr�rRr7rr_�
__stdout__)
r0r�r9r/rrrrrrr'r'r(r�Ds^�

�

�

�cCs�|durtj}i}|r%g}dD]}
tt|
d�}|dur |�|�q||d<g}|||	fD]}|dkr:|�tj|f�q,|df|df|
dffD]\}}|dkrW|�tj||f�qF|r^||d<tj|||fi|��|_d	|_	|�
|||||	|
�dS)
z'Execute program using os.posix_spawn().N)�SIGPIPEZSIGXFZ�SIGXFSZZ	setsigdefrdrr|r��file_actionsT)r�rDr�r3rk�POSIX_SPAWN_CLOSE�POSIX_SPAWN_DUP2r�r�rr4)r0rlr�r�r�rrrrrrr�ZsigsetZsignameZsignumr_rZfd2r'r'r(�_posix_spawn�s>
�����zPopen._posix_spawnc-s�t|ttf�r|g}nt|tj�r|
rtd��|g}nt|�}|
r6ttd�r(dnd}|dg|}�r6�|d<�dur>|d�t�	d�|||�t
r�tj���r�|dur�|s�|s�|dur�|d	ksc|d
kr�|d	ksk|d
kr�|d	kss|d
kr�|s�|dur�|dur�|dur�|dkr�|�
|�|||||
|||�
dS�}t��\}}g}|dkr�|�|�t�|�}|dks�|D]}t�|�q�z�z||dur�g}|��D]\}}t�|�}d|vr�td
��|�|dt�|��q�nd}t����tj���r��f} nt�fdd�t�|�D��} t|�}!|!�|�t�|| |tttt|!���|||||
||||||||||||�|_d|_Wt�|�nt�|�w|� |||
|||�t!�}"	t�"|d�}#|"|#7}"|#�rat#|"�dk�rbn�qMWt�|�nt�|�w|"�r�zt�$|jd�\}$}%|$|jk�r�|�%|%�ntj&|_'Wn
t(�y�Ynwz|"�)dd
�\}&}'}(|(�*�}(Wnt�y�d}&d}'d�+t|"��}(Ynwt,t-|&�*d�t.�})t/|)t0��r�|'�r�t|'d�}*|(dk}+|+�r�d}(|},n|},|*dk�r�t�1|*�}(|)|*|(|,��|)|(��dS)zExecute program (POSIX version)r@Zgetandroidapilevelz/system/bin/shz/bin/shz-crNrArdr�r<�=z!illegal environment variable namec3s$�|]
}tj�t�|���VqdSr+)r�rEr��fsencode)r=�dir�r�r'r(�	<genexpr>�s
��
�z'Popen._execute_child.<locals>.<genexpr>TiP��:sSubprocessError�0z#Bad exception data from child: {!r}�ascii�Znoexecr�)2r�r�rBr�rCr�rMr�r_rH�_USE_POSIX_SPAWNrE�dirnamerbrZrk�dupr�r�rdr4r��
get_exec_path�set�add�_posixsubprocessZ	fork_exec�sortedr�rRr�rr4�	bytearrayr%r��waitpid�_handle_exitstatusr`r,�ChildProcessErrorr�rr�r��builtinsr�
issubclassr��strerror)-r0rlr�r�r�rr�r�r�r�r�rrrrrrr�rrr	r�r�Z
unix_shellZorig_executableZerrpipe_readZ
errpipe_writeZlow_fds_to_closeZlow_fdZenv_list�krqZexecutable_listZfds_to_keepZerrpipe_data�partr�r,Zexception_nameZ	hex_errno�err_msgZchild_exception_typeZ	errno_numZchild_exec_never_calledZerr_filenamer'rfr(r��s
��
�����

�
�
�
�
����
���
�


�cCs&||�r||�|_dS||�|_dS)�:All callers to this function MUST hold self._waitpid_lock.N)r,)r0r,�waitstatus_to_exitcodeZ_WIFSTOPPEDZ	_WSTOPSIGr'r'r(rvKszPopen._handle_exitstatusc
Cs�|jdurl|j�d�s
dSzXz#|jdur|jWW|j��S||j|�\}}||jkr0|�|�Wn"tyS}z|durA||_n|j|krId|_WYd}~nd}~wwW|j��|jSW|j��|jS|j��w|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��acquire�releaser�rvr�r")r0r\Z_waitpidZ_WNOHANGZ_ECHILDr�r,�er'r'r(r^Ws4
	
�

�
���
�
��cCs@zt�|j|�\}}W||fSty|j}d}Y||fSw)r~r)r�rur�rw)r0Z
wait_flagsr�r,r'r'r(�	_try_waitzs��zPopen._try_waitcCsr|jdur|jS|duryt�|}d}	|j�d�r\z;|jdur)W|j��|jS|�tj�\}}||jks<|dks<J�||jkrO|�	|�W|j��|jSW|j��n|j��w|�
|�}|dkrkt|j|��t
|d|d�}t�|�q|jdur�|j�(|jdur�	Wd�|jS|�d�\}}||jkr�|�	|�Wd�n1s�wY|jdus~|jS)z+Internal implementation of wait() on POSIX.Ng����Mb@?TFrr�g�������?)r,r&r�r�r�r�r��WNOHANGr�rvr)rrlr(�time�sleep)r0rCr*Zdelayr�r,Z	remainingr'r'r(r�sP



�


�

�

�	�

��
�
c
Cs$|jr*|js*z|j��Wn	tyYnw|s*z|j��Wn	ty)Ynwd}d}|jsFi|_|jr=g|j|j<|jrFg|j|j<|jrO|j|j}|jrX|j|j}|�|�|j	ret
|j	�}t���}|jrv|rv|�|jt
j�|jr�|jjs�|�|jt
j�|jr�|jjs�|�|jt
j�|���r=|�|�}|dur�|dkr�|j||||dd�td��|�|�}	|�||||�|	D]u\}
}|
j|ju�r||j|jt�}z|jt�|
j|�7_Wnty�|�|
j�|
j��Yq�w|jt|j	�k�r|�|
j�|
j��q�|
j|j|jfv�r8t�|
jd�}
|
�s/|�|
j�|
j��|j|
j�|
�q�|��s�Wd�n	1�sHwY|j |�|�d�|du�r`d�!|�}|du�rjd�!|�}|j"�r�|du�r~|�#||jj$|jj%�}|du�r�|�#||jj$|jj%�}||fS)NrT)r.zN_check_timeout(..., skip_check_and_raise=True) failed to raise TimeoutExpired.i�r�r�)&r�r��flushr!r�Z_fileobj2outputr9r/�_save_inputr��
memoryview�_PopenSelector�register�	selectorsZEVENT_WRITErOZ
EVENT_READZget_mapr)r/�RuntimeError�selectZfileobj�
_input_offset�	_PIPE_BUFr�r r�
unregisterr�r%rkr�r�r�rr�r�)r0r�r*r-r9r/Z
input_viewZselectorrCZready�keyZevents�chunkr�r'r'r(r'�s���




��
��
�
����,




�
�cCsV|jr#|jdur%d|_||_|dur'|jr)|j�|jj|jj�|_dSdSdSdSdS)Nr)r�r�r�r��encoder�r�)r0r�r'r'r(r�s
��zPopen._save_inputcCs@|��|jdurdSz
t�|j|�WdStyYdSw)rSN)r�r,r�r�r��ProcessLookupErrorrVr'r'r(rW"s
�cC�|�tj�dS)z/Terminate the process with SIGTERM
            N)rWr3rTr5r'r'r(rUB�cCr�)z*Kill the process with SIGKILL
            N)rWr3�SIGKILLr5r'r'r(r�Gr�z
Popen.kill)rdNNNNNTFNNNNrTFr'r>)Fr+):r$r%r&r@rr1rUr�r�r�r�rAr�rBrrrr_r`r�r�rWrr#r�r�r)r/r�r4r�r�r8r?r�rVrKZ
WAIT_OBJECT_0rLr^rrNr'rWrUr�rbr�r�
WIFSTOPPED�WSTOPSIGrvrur�r"ZECHILDr�r�r'r'r'r(r�s�5�
�|
	


D	
�
H	

�2<'&
�
�#
)f r)Lr@rxr"r�r�r�r3r_r�r�r0rr&r�r[r��__all__r�rVr��ModuleNotFoundErrorrrr�r�rrrrrrrrrrrrrrrr r!r"r��	Exceptionrrrr#rRrNr�r�r�rXr�ZSelectSelectorr]rYrrr
rmr�rrr
�objectrrr�rr	r�rlZ
_USE_VFORKrr'r'r'r(�<module>s�"��P

%
	


;4%�FI
2