Spade

Mini Shell

Directory:~$ /proc/self/root/usr/lib64/python3.6/__pycache__/
Upload File

[Home] [System Details] [Kill Me]
Current File:~$ //proc/self/root/usr/lib64/python3.6/__pycache__/subprocess.cpython-36.opt-1.pyc

3


 \���@s8dZddlZejdkZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZGdd�de
�ZGdd�de�ZGd	d
�d
e�Zer�ddlZddlZddlZGdd�d�ZnhddlZddlZddlZyddlZWnek
r�ddlZYnXeed
d�Zeed��rejZnejZddddddddddddd
dgZ
e�r�ddlm!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(e
j)ddddd
d!d"d#dg	�Gd$d%�d%e*�Z+gZ,d&d'�Z-d<Z.d=Z/d>Z0d+d,�Z1d-d.�Z2dd/�d0d�Z3d1d�Z4dd/�d2d�Z5Gd3d�de6�Z7ddd4d5�d6d�Z8d7d8�Z9d9d�Z:d:d�Z;e6�Z<Gd;d�de6�Z=dS)?a�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�"/usr/lib64/python3.6/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|jtj|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
eZdZdZdZdZdZdZdS)�STARTUPINFOrN)rrr�dwFlags�	hStdInput�
hStdOutput�	hStdError�wShowWindowrrrrr�s
rZPIPE_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_USESHOWWINDOWr,r-r.r/r0r1r2r3c@s6eZdZdZejfdd�Zdd�Zdd�ZeZ	eZ
dS)	�HandleFcCs|jsd|_||�dS)NT)�closed)r�CloseHandlerrr�Close�szHandle.ClosecCs
|jsd|_t|�Std��dS)NTzalready
closed)r5�intr)rrrr�Detach�sz
Handle.DetachcCsd|jjt|�fS)Nz%s(%d))�	__class__rr8)rrrr�__repr__�szHandle.__repr__N)rrrr5�_winapir6r7r9r;�__del__rrrrrr4�sr4cCsTxNtdd�D]>}|jtjd�}|dk	rytj|�Wqtk
rJYqXqWdS)N)�
_deadstate)�_active�_internal_poll�sys�maxsize�remover)Zinst�resrrr�_cleanup�srE���cCs*g}tjj}|dkr&|jdd|�|S)zgReturn
a list of command-line arguments reproducing the current
    optimization settings in
sys.flags.r�-�O)rA�flags�optimize�append)�argsrrrr�"_optim_args_from_interpreter_flags�s
rOcCsddddddd�}t�}x:|j�D].\}}ttj|�}|dkr"|jd	||�q"Wtjjrh|jd
�n$tjjrz|jd�tjjr�|jd�xtj	D]}|jd
|�q�Wttdi�}xDdD]<}||kr�||}|dkr�|}nd||f}|j
d|f�q�W|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�quietrrIz-Iz-Ez-sz-W�	_xoptions�faulthandler�tracemalloc�showalloccount�showrefcount�utf8Tz%s=%sz-X)r]r^r_r`ra)rO�items�getattrrArKrM�isolated�ignore_environment�no_user_site�warnoptions�extend)Zflag_opt_maprN�flag�optrSZxoptionsr�argrrr�_args_from_interpreter_flags�s:

rl)rcOsFt||��2}y|j|d�S|j�|j��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$scOs6t||�}|r2|jd�}|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"])
    rNNr)r$�getr	)rorp�retcoderrrrr%(s



cOsTd|krtd��d|kr<|ddkr<|jdd�r4dnd|d<t|t|d	d
�|��jS)a(Run 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'

    If universal_newlines=True is passed, the "input" argument
must be a
    string and the return value will be a string rather than bytes.
    rz3stdout argument not allowed, it will be
overridden.�inputN�universal_newlinesF��T)rr�check)rrrr)r"r)rrorprrrr(;s
c@s*eZdZdZd	dd�Zdd�Zdd�ZdS)
r+aEA 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)rNr
rr
)rrNr
rr
rrrrrszCompletedProcess.__init__cCshdj|j�dj|j�g}|jdk	r4|jdj|j��|jdk	rP|jdj|j��djt|�jdj|��S)Nz	args={!r}zreturncode={!r}zstdout={!r}zstderr={!r}z{}({})z,
)	�formatrNr
rrMr
�typer�join)rrNrrrr;xs


zCompletedProcess.__repr__cCs |jrt|j|j|j|j��dS)z6Raise
CalledProcessError if the exit code is non-zero.N)r
r	rNrr
)rrrr�check_returncode�sz!CompletedProcess.check_returncode)NN)rrrrrr;r|rrrrr+gs

	F)rtrrxc	Os�|dk	r
d|krtd��t|d<t||���}y|j||d�\}}WnVtk
r||j�|j�\}}t|j|||d��Yn|j�|j��YnX|j�}|r�|r�t	||j||d��WdQRXt
|j|||�S)afRun 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 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.

    The other arguments are the same as for the Popen constructor.

    If universal_newlines=True is passed, the "input" argument
must be a
    string and stdout/stderr in the returned object will be strings rather
than
    bytes.
    N�stdinz/stdin and input arguments may not both be
used.)r)rr
)rr"r!�communicaterrnrNrm�pollr	r+)	rtrrxrorpZprocessrr
rsrrrr)�s*
cCs�g}d}x�|D]�}g}|r$|jd�d|kp8d|kp8|}|rH|jd�xj|D]b}|dkrf|j|�qN|dkr�|jdt|�d�g}|jd�qN|r�|j|�g}|j|�qNW|r�|j|�|r|j|�|jd�qWdj|�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�
�	�"�\rGz\"rv)rM�lenrhr{)�seq�resultZ	needquoterkZbs_buf�crrr�list2cmdline�s4






r�cCslyt|ddtd�}d}Wn.tk
rF}z|j}|j}WYdd}~XnX|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)�shellrur
rNrF�
���r�)r(r#r	rr
)r�dataZexitcodeZexrrrr&s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'
    rF)r&)rrrrr'"s
c@s�eZdZdZdZd?dddddeddddddddffddd�dd	�Zd
d�Zdd
�Zdd�Z	e
jej
fdd�Zdd�Zdd�Zd@dd�Zdd�Zdd�Zdd�Ze�rdd�Zd
d!�Zd"d#�Zdejejejfd$d%�ZdAd&d'�Zd(d)�Zd*d+�Z
d,d-�Z!d.d/�Z"e"Z#n�d0d�Zd1d#�Ze$j%e$j&e$j'e$j(e$j)e$j*fd2d3�Z+de$j,e$j-e.j/fd4d%�Zd5d6�Z0dBd7d'�Zd8d+�Z
d9d:�Z1d;d-�Z!d<d/�Z"d=d>�Z#dS)Cr!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.

      universal_newlines: If true, use universal line endings for file
          objects stdin, stdout and stderr.

      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
   
FrFNrT)�encoding�errorscCsrt�tj�|_d|_d|_|dkr(d}t|t�s:td��t	r�|dk	rNt
d��|dk	pd|dk	pd|dk	}|tkr~|rxd}q�d}q�|r�|r�t
d��nF|tkr�d}|r�|r�tj
dt�d}|
dk	r�t
d	��|d
kr�t
d��||_d|_d|_d|_d|_d|_||_||_||_|j|||�\}}}}}}t	�rz|dk�rFtj|j�d
�}|dk�r`tj|j�d
�}|dk�rztj|j�d
�}|�p�|�p�|}d|_y�|dk�r�tj|d|�|_|�r�tj|jd|dk||d
�|_|dk�rtj|d|�|_|�rtj|j||d�|_|dk�r6tj|d|�|_|�r6tj|j||d�|_|j
||||||
||
||	||||||||�W�nxDt!d|j|j|jf�D]*}y|j"�Wnt#k
�r�YnX�q�W|j�sfg}|t$k�r�|j%|�|t$k�r�|j%|�|t$k�r�|j%|�t&|d��r|j%|j'�xP|D]H}y*t	�r<t|t(��r<|j)�n
t*j"|�Wnt#k
�r^YnX�qW�YnXdS)zCreate new Popen instance.NFrFzbufsize
must be an integerz0preexec_fn is not supported on Windows
platformsTzSclose_fds is not supported on Windows platforms if you redirect
stdin/stdout/stderrzpass_fds overriding close_fds.z2startupinfo is only
supported on Windows platformsrz4creationflags is only supported on
Windows
platforms�wb)�
write_through�line_bufferingr�r��rb)r�r��_devnullr�r�r�r�r�r�r�)+rE�	threadingZLock�
_waitpid_lock�_input�_communication_started�
isinstancer8�	TypeError�
_mswindowsr�_PLATFORM_DEFAULT_CLOSE_FDS�warnings�warn�RuntimeWarningrNr}rr
�pidr
rur�r��_get_handles�msvcrtZopen_osfhandler9�_closed_child_pipe_fds�io�open�
TextIOWrapper�_execute_child�filter�close�OSErrorr"rM�hasattrr�r4r7�os)rrN�bufsize�
executabler}rr
�
preexec_fn�	close_fdsr��cwd�envru�startupinfo�
creationflags�restore_signals�start_new_session�pass_fdsr�r�Z
any_stdio_set�p2cread�p2cwrite�c2pread�c2pwrite�errread�errwriteZ	text_mode�fZto_close�fdrrrr`s�

















zPopen.__init__cCs |j||�}|jdd�jdd�S)Nz
r��
)�decode�replace)rr�r�r�rrr�_translate_newlines�szPopen._translate_newlinescCs|S)Nr)rrrr�	__enter__�szPopen.__enter__c
CsD|jr|jj�|jr
|jj�z|jr2|jj�Wd|j�XdS)N)rr�r
r}rm)rrzr�	tracebackrrr�__exit__�s

zPopen.__exit__cCsT|js
dS|jdkr(|d|jt|d�|j|d�|jdkrPtdk	rPtj|�dS)Nzsubprocess
%s is still running)�source)r>)�_child_createdr
r��ResourceWarningr@r?rM)rZ_maxsizeZ_warnrrrr=
s


z
Popen.__del__cCs"t|d�stjtjtj�|_|jS)Nr�)r�r�r��devnull�O_RDWRr�)rrrr�_get_devnulls
zPopen._get_devnullcCs�|rZy|jj|�WnDtk
r(Yn2tk
rX}z|jtjkrFn�WYdd}~XnXy|jj�WnDtk
r|Yn2tk
r�}z|jtjkr�n�WYdd}~XnXdS)N)r}�write�BrokenPipeErrorr��errnoZEINVALr�)rrt�excrrr�_stdin_writes"zPopen._stdin_writecCs�|jr|rtd��|dkr�|jr�|j|j|jgjd�dkr�d}d}|jrV|j|�n6|jrr|jj�}|jj�n|jr�|jj�}|jj�|j	�nJ|dk	r�t
�|}nd}z|j|||�\}}Wdd|_X|j	|j|�d�}||fS)a4Interact
with process: Send data to stdin.  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 (if self.universal_newlines is True, this should
        be a string; if it is False, "input" should be bytes), or
        None, if no data should be sent to the child.

        communicate() returns a tuple (stdout, stderr).  These will be
        bytes or, if self.universal_newlines was True, a string.
        z.Cannot send input after starting
communicationNrGT)r)
r�rr}rr
�countr��readr�rm�_time�_communicate�_remaining_time)rrtrrr
�endtime�stsrrrr~7s.




zPopen.communicatecCs|j�S)zSCheck if child process
has terminated. Set and return returncode
        attribute.)r@)rrrrrhsz
Popen.pollcCs|dkrdS|t�SdS)z5Convenience for _communicate
when computing
timeouts.N)r�)rr�rrrr�nszPopen._remaining_timecCs&|dkrdSt�|kr"t|j|��dS)z2Convenience
for checking if a timeout has
expired.N)r�rrN)rr��orig_timeoutrrr�_check_timeoutvs
zPopen._check_timeoutcCs�|dkr|dkr|dkrd
Sd
\}}d\}}d\}}	|dkrttjtj�}|dkrrtjdd�\}}
t|�}tj|
�nj|tkr�tjdd�\}}t|�t|�}}n>|tkr�tj	|j
��}n&t|t��r�tj	|�}ntj	|j
��}|j|�}|dk�r,tjtj�}|dk�r�tjdd�\}
}t|�}tj|
�nn|tk�rZtjdd�\}}t|�t|�}}n@|tk�rttj	|j
��}n&t|t��r�tj	|�}ntj	|j
��}|j|�}|dk�r�tjtj�}	|	dk�rftjdd�\}
}	t|	�}	tj|
�n~|tk�rtjdd�\}}	t|�t|	�}}	nP|tk�r&|}	n@|tk�r@tj	|j
��}	n&t|t��rXtj	|�}	ntj	|j
��}	|j|	�}	||||||	fS)z|Construct
and return tuple with IO objects:
            p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite
           
NrFrr�r�r�r�r�r�)r�r�r�r�r�r�r�r�)r�r�r�r�)r�r�r�r�)r�r�)r<ZGetStdHandler.Z
CreatePiper4r6r"r*r�Z
get_osfhandler�r�r8�fileno�_make_inheritabler/r0r#)rr}rr
r�r�r�r�r�r��_rrrr��sn











zPopen._get_handlescCs&tjtj�|tj�ddtj�}t|�S)z2Return
a duplicate of handle, which is
inheritablerrF)r<ZDuplicateHandleZGetCurrentProcessZDUPLICATE_SAME_ACCESSr4)rZhandle�hrrrr��s

zPopen._make_inheritablecCs<t|t�st|�}|dkr
t�}d|||fkrP|jtjO_||_||_||_	|
r�|jtj
O_tj|_t
jjdd�}dj||�}z>tj||ddt|�|	||dk	r�t
j|�nd|�	\}}}}Wd|d	kr�|j�|d
kr�|j�|dk�r�|j�t|d��rt
j|j�d|_Xd|_t|�|_||_tj|�dS)z$Execute
program (MS Windows version)NrFZCOMSPECzcmd.exez
{} /c
"{}"r�Tr�r�r�r�)r��strr�rrr<r2rrrr3r1rr��environrrryZ
CreateProcessr8�fspathr7r�r�r�r�r�r4�_handler�r6)rrNr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�Zunused_restore_signalsZunused_start_new_sessionZcomspecZhpZhtr��tidrrrr��sF


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�)rr>Z_WaitForSingleObjectZ_WAIT_OBJECT_0Z_GetExitCodeProcessrrrr@s
zPopen._internal_pollcCs�|dk	r"tjdtdd�|j|�}|dkr2tj}nt|d�}|jdkrztj|j	|�}|tj
krlt|j|��tj
|j	�|_|jS)zOWait for child process to
terminate.  Returns returncode
            attribute.Nz0'endtime' argument is deprecated; use
'timeout'.rG)�
stackleveli�)r�r��DeprecationWarningr�r<ZINFINITEr8r
�WaitForSingleObjectr�ZWAIT_TIMEOUTrrN�GetExitCodeProcess)rrr�Ztimeout_millisr�rrrrm$s



z
Popen.waitcCs|j|j��|j�dS)N)rMr�r�)rZfh�bufferrrr�
_readerthread:szPopen._readerthreadcCs`|jrDt|d�rDg|_tj|j|j|jfd�|_d|j_|jj�|j	r�t|d�r�g|_
tj|j|j	|j
fd�|_d|j_|jj�|jr�|j
|�|jdk	r�|jj|j|��|jj�r�t|j|��|j	dk	r�|jj|j|��|jj�r�t|j|��d}d}|j�r|j}|jj�|j	�r4|j
}|j	j�|dk	�rF|d}|dk	�rX|d}||fS)N�_stdout_buff)�targetrNT�_stderr_buffr)rr�r�r�ZThreadr�Z
stdout_threadZdaemon�startr
r�Z
stderr_threadr}r�r{r�Zis_aliverrNr�)rrtr�r�rr
rrrr�?sF










zPopen._communicatecCsl|jdk	rdS|tjkr"|j�nF|tjkr>tj|jtj�n*|tjkrZtj|jtj�nt	dj
|���dS)zSend a signal to the process.NzUnsupported signal:
{})r
r�SIGTERM�	terminateZCTRL_C_EVENTr�rnr�ZCTRL_BREAK_EVENTrry)r�sigrrr�send_signalss




zPopen.send_signalcCsX|jdk	rdSytj|jd�Wn2tk
rRtj|j�}|tjkrH�||_YnXdS)zTerminates the process.NrF)r
r<ZTerminateProcessr��PermissionErrorr�ZSTILL_ACTIVE)rZrcrrrr��s

zPopen.terminatec
Cs.d\}}d\}}d\}}	|dkr"n@|tkr8tj�\}}n*|tkrJ|j�}nt|t�rZ|}n|j�}|dkrln@|tkr�tj�\}}n*|tkr�|j�}nt|t�r�|}n|j�}|dkr�nh|tkr�tj�\}}	nR|tk�r�|dkr�|}	n
t	j
j�}	n.|tk�r|j�}	nt|t��r|}	n|j�}	||||||	fS)
z|Construct
and return tuple with IO objects:
            p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite
           
rFNr�r�)r�r�r�r�)r�r�r�r�)r�r�r�)r"r��piper*r�r�r8r�r#rA�
__stdout__)
rr}rr
r�r�r�r�r�r�rrrr��sJ






c)"s�t|ttf�r|g}nt|�}|
r:ddg|}�r:�|d<�dkrJ|d��}tj�\}}g}x
|dkr~|j|�tj|�}q`Wx|D]}tj|�q�W�z�z�|dk	r�g}xL|j	�D]:\}}tj
|�}d|kr�td��|j|dtj
|��q�Wnd}tj
���tjj
���r�f}nt�fdd	�tj|�D��}t|�}|j|�tj|||tttt|���|||||
||||||||�|_d
|_Wdtj|�Xt|dd�}|dk�r�|dk�r�||k�r�tj|�|dk�r�|
dk�r�||k�r�tj|�|dk�r|dk�r||k�rtj|�|dk	�r.tj|�d
|_t�}x2tj|d
�}||7}|�sft|�d
k�r<P�q<WWdtj|�X|�r�y6tj|jd�\}
}!| |jk�r�|j|!�nt j!|_"Wnt#k
�r�YnXy|j$dd�\}"}#}$|$j%�}$Wn,tk
�rd}"d}#dj&t|��}$YnXtt'|"j%d�t(�}%t)|%t*��r�|#�r�t|#d�}&|$dk}'|'�rdd}$|}(n|}(|&dk�r�tj+|&�}$|&t,j-k�r�|$dt.|(�7}$|%|&|$|(��|%|$��dS)zExecute
program (POSIX version)z/bin/shz-crNrH�=z!illegal environment
variable
namec3s"|]}tjjtj|���VqdS)N)r��pathr{�fsencode)�.0�dir)r�rr�	<genexpr>sz'Popen._execute_child.<locals>.<genexpr>Tr�rFiP��:rGsSubprocessError�0z#Bad
exception data from child: {!r}�ascii�Znoexecrvz:
r�r�r�r�r�r�)/r�r��bytes�listr�r�rM�dupr�rbr�rr��dirname�tuple�
get_exec_path�set�add�_posixsubprocessZ	fork_exec�sorted�mapr8r�r�rcr��	bytearrayr�r��waitpid�_handle_exitstatusrArBr
�ChildProcessError�splitr�ry�builtinsr�
issubclassr��strerrorr��ENOENT�repr))rrNr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�Zorig_executableZerrpipe_readZ
errpipe_writeZlow_fds_to_closeZlow_fdZenv_list�krSZexecutable_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	_WSTOPSIGrrrrXszPopen._handle_exitstatuscCs�|jdkr�|jjd�sdSz�y8|jdk	r.|jS||j|�\}}||jkrR|j|�WnBtk
r�}z&|dk	rv||_n|j|kr�d|_WYdd}~XnXWd|jj�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�rr�r��release)rr>Z_waitpidZ_WNOHANGZ_ECHILDr�r��errrr@js
	



cCs>ytj|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_wait�s
zPopen._try_waitcCsV|jdk	r|jS|dk	r(tjdtdd�|dk	s8|dk	r^|dkrLt�|}n|dkr^|j|�}|dk	r�d}x�|jjd�r�z6|jdk	r�P|jt	j
�\}}||jkr�|j|�PWd|jj
�X|j|�}|dkr�t|j|��t|d|d�}tj|�qlWnVxT|jdk�rN|j�8|jdk	�rP|jd�\}}||jk�rB|j|�WdQRXq�W|jS)	zOWait
for child process to terminate.  Returns returncode
            attribute.Nz0'endtime' argument is deprecated; use
'timeout'.rG)r�g����Mb@?Frg�������?)r
r�r�r�r�r�r�rrr��WNOHANGr�rrrrN�min�timeZsleep)rrr�Zdelayr�r�Z	remainingrrrrm�sJ





c#Cs|jrZ|jrZy|jj�Wntk
r0YnX|sZy|jj�Wntk
rXYnXd}d}|js�i|_|jr�g|j|j<|jr�g|j|j<|jr�|j|j}|jr�|j|j}|j|�|j	r�t
|j	�}t����}|jr�|r�|j|jt
j�|j�r|j|jt
j�|j�r$|j|jt
j��xJ|j��rp|j|�}|dk	�r\|dk�r\t|j|��|j|�}	|j||�x�|	D]�\}
}|
j|jk�r||j|jt�}y|jtj|
j|�7_Wn,tk
�r�|j|
j�|
jj�Yn*X|jt|j	�k�rf|j|
j�|
jj�nP|
j|j|jfk�rxtj|
jd�}
|
�sT|j|
j�|
jj�|j|
jj|
��qxW�q(WWdQRX|j
|j|�d�|dk	�r�dj!|�}|dk	�r�dj!|�}|j"�s�|j#�s�|j$�r|dk	�r�|j%||jj"|jj#�}|dk	�r|j%||jj"|jj#�}||fS)Nri�)rrw)&r}r��flushr�r�Z_fileobj2outputrr
�_save_inputr��
memoryview�_PopenSelector�register�	selectorsZEVENT_WRITEZ
EVENT_READZget_mapr�rrN�selectr�Zfileobj�
_input_offset�	_PIPE_BUFr�r�r�Z
unregisterr�r�rMrmr{r�r�rur�)rrtr�r�rr
Z
input_viewZselectorrZready�keyZevents�chunkr�rrrr��s�






(







cCsR|jrN|jdkrNd|_||_|dk	rN|js6|js6|jrN|jj|jj|jj�|_dS)Nr)r}r�r#r�r�ru�encode)rrtrrrr/szPopen._save_inputcCs|jdkrtj|j|�dS)zSend
a signal to the process.N)r
r�rnr�)rr�rrrr�<s
cCs|jtj�dS)z/Terminate the process with SIGTERM
            N)r�rr�)rrrrr�BscCs|jtj�dS)z*Kill
the process with SIGKILL
            N)r�r�SIGKILL)rrrrrnGsz
Popen.killr�)NN)NN)NN)2rrrrr�r�rr�r�r�rArBr�r�r=r�r�r~rr�r�r�r�r�r�r<r�Z
WAIT_OBJECT_0r�r@rmr�r�r�r�rnr��WIFSIGNALED�WTERMSIG�	WIFEXITED�WEXITSTATUS�
WIFSTOPPED�WSTOPSIGrr
rr�ZECHILDrrrrrrr!2sd+
1H	@
46
"
4a
r�������)>rrA�platformr�r�r�rrrr�r�rr��	Exceptionrr	rr�r�r<rrr"r!�ImportErrorZdummy_threadingrcr$r�r
rZSelectSelector�__all__r,r-r.r/r0r1r2r3rhr8r4r?rEr"r#r*rOrlr$r%r(�objectr+r)r�r&r'r�r!rrrr�<module>*sr
%

(
.,!2I