OwlCyberSecurity - MANAGER
Edit File: subprocess.cpython-37.pyc
B ����� f������������������@���s`��d�Z�ddlZejdkZddlZddlZddlZddlZddlZddl Z ddl Z ddlmZ�G�dd��de �ZG�dd��de�ZG�d d ��d e�Zer�ddlZddlZddlZG�dd��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/m0Z0�e�1ddddd d!d"d#dd$d%d&d'd(d)d*d+d,d-g��G�d.d/��d/e2�Z3e�r�dZ4d0d1��Z5ng�Z4d2d1��Z5d3Z6d4Z7d5Z8d6d7��Z9d8d9��Z:dd:�d;d�Z;d<d��Z<dd:�d=d�Z=G�d>d��de>�Z?dd?dd?d@�dAd�Z@dBdC��ZAdDd��ZBdEd��ZCG�dFd��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���e�Zd�ZdS�)�SubprocessErrorN)�__name__� __module__�__qualname__��r���r����//opt/alt/python37/lib64/python3.7/subprocess.pyr���9���s����r���c���������������@���s<���e�Zd�ZdZd 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 Nc�������������C���s���||�_�||�_||�_||�_d�S�)N)� returncode�cmd�output�stderr)�selfr ���r���r���r ���r���r���r����__init__C���s����zCalledProcessError.__init__c�������������C���sb���|�j�rN|�j�dk�rNyd|�jt�|�j���f�S��tk rJ���d|�j|�j��f�S�X�nd|�j|�j�f�S�d�S�)Nr���zCommand '%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)r���r���r���r����__str__I���s����zCalledProcessError.__str__c�������������C���s���|�j�S�)z+Alias for output attribute, to match stderr)r���)r���r���r���r����stdoutU���s����zCalledProcessError.stdoutc�������������C���s ���||�_�d�S�)N)r���)r����valuer���r���r���r���Z���s����)NN) r���r���r����__doc__r���r����propertyr����setterr���r���r���r���r ���<���s ��� r ���c���������������@���s<���e�Zd�ZdZd 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 Nc�������������C���s���||�_�||�_||�_||�_d�S�)N)r����timeoutr���r ���)r���r���r���r���r ���r���r���r���r���h���s����zTimeoutExpired.__init__c�������������C���s���d|�j�|�jf�S�)Nz'Command '%s' timed out after %s seconds)r���r���)r���r���r���r���r���n���s����zTimeoutExpired.__str__c�������������C���s���|�j�S�)N)r���)r���r���r���r���r���r���s����zTimeoutExpired.stdoutc�������������C���s ���||�_�d�S�)N)r���)r���r���r���r���r���r���v���s����)NN) r���r���r���r���r���r���r���r���r���r���r���r���r���r���a���s ��� r���c���������������@���s,���e�Zd�Zddddddd�dd�Zdd��ZdS�)�STARTUPINFOr���N)�dwFlags� hStdInput� hStdOutput� hStdError�wShowWindow�lpAttributeListc������������C���s0���||�_�||�_||�_||�_||�_|p(dg�i|�_d�S�)N�handle_list)r���r���r���r���r���r ���)r���r���r���r���r���r���r ���r���r���r���r�������s����zSTARTUPINFO.__init__c�������������C���s@���|�j����}d|kr"t|d��|d<�t|�j|�j|�j|�j|�j|d�S�)Nr!���)r���r���r���r���r���r ���) r ����copy�listr���r���r���r���r���r���)r���Z attr_listr���r���r����_copy����s���� zSTARTUPINFO._copy)r���r���r���r���r$���r���r���r���r���r�������s���r���ZPIPE_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_JOBr1���r2���r3���r4���r5���r6���r7���r8���r9���r:���r;���r<���r=���r>���r?���r@���rA���rB���c���������������@���s6���e�Zd�ZdZejfdd�Zdd��Zdd��ZeZ eZ dS�) �HandleFc�������������C���s���|�j�sd|�_�||���d�S�)NT)�closed)r����CloseHandler���r���r����Close����s����zHandle.Closec�������������C���s ���|�j�sd|�_�t|��S�td��d�S�)NTzalready closed)rD����intr���)r���r���r���r����Detach����s����z Handle.Detachc�������������C���s���d|�j�jt|��f�S�)Nz%s(%d))� __class__r���rG���)r���r���r���r����__repr__����s����zHandle.__repr__N)r���r���r���rD����_winapirE���rF���rH���rJ����__del__r���r���r���r���r���rC�������s���rC���c���������������C���s���d�S�)Nr���r���r���r���r����_cleanup����s����rM���c����������� ���C���s`���t�d�krd�S�xNt�d�d���D�]>}�|�jtjd�}|d�k ryt��|���W�q�tk rV���Y�qX�qW�d�S�)N)� _deadstate)�_active�_internal_poll�sys�maxsize�remover���)�instZresr���r���r���rM�������s�������������c��������������C���s*���g�}�t�jj}|dkr&|��dd|����|�S�)zgReturn a list of command-line arguments reproducing the current optimization settings in sys.flags.r����-�O)rQ����flags�optimize�append)�argsr���r���r���r����"_optim_args_from_interpreter_flags��s ����r^���c��������������C���sb��ddddddd�}�t���}x:|����D�].\}}ttj|�}|dkr"|�d ||����q"W�tjjrh|�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>|} nd|| 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�quietr���rX���z-Iz-Ez-sN� _xoptions�dev����zerror::BytesWarningzdefault::BytesWarning�defaultz-W)z-Xrl���)Zfaulthandler�tracemallocZ importtimeZshowalloccountZshowrefcount�utf8Tz%s=%sz-X) r^����items�getattrrQ���rZ���r\����isolated�ignore_environment�no_user_site�warnoptionsri���rS����extend)Zflag_opt_mapr]����flagZoptrb���Zwarnoptsri���Zxoptions�dev_moder����argr���r���r����_args_from_interpreter_flags��sN���� r{���)r���c���������� ���O���s>���t�||��*}y|j|�d�S����|������Y�nX�W�dQ�R�X�dS�)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)r���� popenargs�kwargs�pr���r���r���r)���K��s����c��������������O���s6���t�|�|�}|r2|�d�}|dkr(|�d�}t||��dS�)aO��Run 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����retcoder���r���r���r���r*���\��s���� c�������������O���sT���d|krt�d��d|kr<|d�dkr<|�dd�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' 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. r���z3stdout argument not allowed, it will be overridden.�inputN�universal_newlinesF�������T)r���r����check)r���r����r.���r'���r���)r���r~���r���r���r���r���r-���o��s����#c���������������@���s*���e�Zd�ZdZd dd�Zdd��Zdd��ZdS�) r0���aE��A 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). Nc�������������C���s���||�_�||�_||�_||�_d�S�)N)r]���r ���r���r ���)r���r]���r ���r���r ���r���r���r���r������s����zCompletedProcess.__init__c�������������C���sh���d��|�j�d��|�j�g}|�jd�k r4|�d��|�j���|�jd�k rP|�d��|�j���d��t|��jd�|��S�)Nz args={!r}zreturncode={!r}zstdout={!r}zstderr={!r}z{}({})z, ) �formatr]���r ���r���r\���r ����typer����join)r���r]���r���r���r���rJ������s���� zCompletedProcess.__repr__c�������������C���s ���|�j�rt|�j�|�j|�j|�j��dS�)z6Raise CalledProcessError if the exit code is non-zero.N)r ���r ���r]���r���r ���)r���r���r���r����check_returncode���s����z!CompletedProcess.check_returncode)NN)r���r���r���r���r���rJ���r����r���r���r���r���r0������s��� F)r�����capture_outputr���r����c�������������O���s ��|�dk r&|��d�dk rtd��t|d<�|r^|��d�dk sF|��d�dk rNtd��t|d<�t|d<�t||���}y|j|�|d�\}}W�n^�tk r��} �z,|����tr�|���\| _| _ n|� �����W�dd} ~ X�Y�n���|������Y�nX�|���} |�r| �rt| |j ||d��W�dQ�R�X�t|j | ||�S�) aK��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. 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.r���r ���z@stdout and stderr arguments may not be used with capture_output.)r���)r���r ���)r����r���r'���r&����communicater���r}���� _mswindowsr���r ���r|����pollr ���r]���r0���)r����r����r���r����r~���r���Zprocessr���r ����excr����r���r���r���r.������s4����c�������������C���s����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��qW�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����)r\����lenrw���r����)�seq�resultZ needquoterz���Zbs_buf�cr���r���r����list2cmdline��s4���� r����c���������� ���C���sl���yt�|�ddtd�}d}W�n.�tk rF�}�z|j}|j}W�dd}~X�Y�nX�|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 ���r���NrU���� )r-���r(���r ���r���r ���)r����dataZexitcodeZexr���r���r���r+���M��s����c�������������C���s���t�|��d�S�)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+���)r���r���r���r���r,���l��s���� c���������������@���s���e�Zd�ZdZdZdGdddd�d d �Zedd���Zejd d���Zdd��Z dd��Z dd��Zej 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 FrU���NTr���r���)�encoding�errorsr����c������������C���sZ��t����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��n���xDt#d|�j|�j|�jf�D�]*}y|�$���W�n�t%k �r����Y�nX��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,�$|��W�n�t%k �rF���Y�nX��qW���Y�nX�dS�)zCreate new Popen instance.NFrU���zbufsize must be an integerz0preexec_fn is not supported on Windows platformszpass_fds overriding close_fds.Tz2startupinfo is only supported on Windows platformsr���z4creationflags 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����r���r ����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����rC���rF����os)r���r]����bufsize� executabler����r���r ���� 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�fdr���r���r���r������s����� zPopen.__init__c�������������C���s���|�j�S�)N)r����)r���r���r���r���r����>��s����zPopen.universal_newlinesc�������������C���s���t�|�|�_d�S�)N)r����r����)r���r����r���r���r���r����D��s����c�������������C���s ���|��||�}|�dd��dd�S�)Nz r����� )�decode�replace)r���r����r����r����r���r���r����_translate_newlinesH��s����zPopen._translate_newlinesc�������������C���s���|�S�)Nr���)r���r���r���r���� __enter__L��s����zPopen.__enter__c�������������C���s����|�j�r|�j�����|�jr |�j����z|�jr2|�j����W�d�|tkrz|�jdkrpy|�j|�jd��W�n�tk rn���Y�nX�d|�_d�S�|�����X�d�S�)Nr���)r���) r���r����r ���r�����KeyboardInterruptr�����_waitr���r|���)r����exc_typer���� tracebackr���r���r����__exit__O��s ���� zPopen.__exit__c�������������C���sT���|�j�s d�S�|�jd�kr(|d|�j�t|�d��|�j|d��|�jd�krPtd�k rPt�|���d�S�)Nzsubprocess %s is still running)�source)rN���)�_child_createdr ���r�����ResourceWarningrP���rO���r\���)r���Z_maxsizeZ_warnr���r���r���rL���k��s���� z Popen.__del__c�������������C���s"���t�|�d�st�tjtj�|�_|�jS�)Nr����)r����r����r�����devnull�O_RDWRr����)r���r���r���r����_get_devnullz��s���� zPopen._get_devnullc���������� ���C���s����|rZy|�j��|��W�nD�tk r(���Y�n2�tk rX�}�z|jtjkrFn��W�d�d�}~X�Y�nX�y|�j�����W�nD�tk r|���Y�n2�tk r��}�z|jtjkr�n��W�d�d�}~X�Y�nX�d�S�)N)r�����write�BrokenPipeErrorr�����errnoZEINVALr����)r���r����r����r���r���r����_stdin_write��s"����zPopen._stdin_writec�������������C���sT��|�j�r|rtd��|dkr�|�j�s�|�j|�j|�jg�d�dkr�d}d}|�jrT|��|��n6|�jrp|�j���}|�j����n|�jr�|�j���}|�j����|�� ���n�|dk r�t ��|�}nd}z�y|��|||�\}}W�nh�tk �r,���|dk r�t |�j|��|��}n|�j}d|�_y|�j|d��W�n�tk �r$���Y�nX���Y�nX�W�dd|�_�X�|�j |��|�d�}||fS�)a9��Interact 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���)r���T)r����r���r����r���r ����countr�����readr����r|����_time�_communicater�����minr�����_remaining_timer����r���)r���r����r���r���r ����endtime�sigint_timeout�stsr���r���r���r�������sD���� zPopen.communicatec�������������C���s���|�����S�)zSCheck if child process has terminated. Set and return returncode attribute.)rP���)r���r���r���r���r�������s����z Popen.pollc�������������C���s���|dkrdS�|t����S�dS�)z5Convenience for _communicate when computing timeouts.N)r����)r���r����r���r���r���r�������s����zPopen._remaining_timec�������������C���sL���|dkrdS�|st���|krHt|�j||r0d�|�nd|r@d�|�ndd��dS�)z2Convenience for checking if a timeout has expired.Nr����)r���r ���)r����r���r]���r����)r���r�����orig_timeoutZ stdout_seqZ stderr_seq�skip_check_and_raiser���r���r����_check_timeout���s����zPopen._check_timeoutc�������������C���s����|dk rt���|�}y|�j|d�S��tk r����|dk rJt|�j|��|��}n|�j}d|�_y|�j|d��W�n�tk rz���Y�nX���Y�nX�dS�)z=Wait for child process to terminate; returns self.returncode.N)r���r���)r����r����r����r����r����r����r���)r���r���r����r����r���r���r���r|������s���� z Popen.waitc�������������C���s~��|dkr|dkr|dkrdS�d\}}d\}}d\}} |dkrtt��t�j�}|dkr�t��dd�\}} t|�}t��| ��nh|tkr�t��dd�\}}t|�t|��}}n<|tkr�t� |�� ���}n$t|t�r�t� |�}nt� |� ���}|��|�}|dk�r*t��t�j�}|dk�r�t��dd�\} }t|�}t��| ��nn|tk�rXt��dd�\}}t|�t|��}}n@|tk�rrt� |�� ���}n&t|t��r�t� |�}nt� |� ���}|��|�}|dk�r�t��t�j�} | 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)rU���rU���rU���rU���rU���rU���)rU���rU���r���)rK���ZGetStdHandler3���Z CreatePiperC���rE���r'���r/���r����Z get_osfhandler����r����rG����fileno�_make_inheritabler4���r5���r(���)r���r����r���r ���r����r����r����r����r����r�����_r���r���r���r������sn���� zPopen._get_handlesc�������������C���s&���t��t����|t����ddt�j�}t|�S�)z2Return a duplicate of handle, which is inheritabler���rm���)rK���ZDuplicateHandleZGetCurrentProcessZDUPLICATE_SAME_ACCESSrC���)r����handle�hr���r���r���r����Z��s ���� zPopen._make_inheritablec�������������C���s���t�dd��|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.c�������������S���s,���h�|�]$}|d�@�d�ks$t��|�t�jkr|�qS�)����)rK���ZGetFileTypeZFILE_TYPE_CHAR)�.0r����r���r���r���� <setcomp>j��s����z,Popen._filter_handle_list.<locals>.<setcomp>)r#���)r���r!���r���r���r����_filter_handle_listc��s����zPopen._filter_handle_listc�������������C���sX��|rt�d��t|t�st|�}|dkr.t��}n|���}d|||fk}|rj|�jtjO��_||_ ||_ ||_|j}t |o�d|ko�|d��}|s�|�r|�r|dkr�i��}|_t|�dg����}|d<�|r�|t|�t|�t|�g7�}|��|�|dd�<�|�r|�s t�dt��d}| �r�|�jtjO��_tj|_|�s�tj�d�}|�sxtj�dd �}tj�|d d�}tj�|��sxtd��tj�|��r�|}n|}d �||�}z@t�||ddt|��| ||dk �r�t� |�nd|� \}}}}W�d|dk�r�|�!���|dk�r|�!���|dk�r|�!���t"|�d��r,t�#|�j$��d|�_%X�d|�_&t'|�|�_(||�_)t�*|��dS�)z$Execute program (MS Windows version)z"pass_fds not supported on Windows.NrU���r!���z?startupinfo.lpAttributeList['handle_list'] overriding close_fdsFZComSpecZ SystemRootr����ZSystem32zcmd.exez:shell not found: neither %ComSpec% nor %SystemRoot% is setz {} /c "{}"r����T)+�AssertionErrorr�����strr����r���r$���r���rK���r7���r���r���r���r ���r����r#���r����rG���r����r����r����r����r8���r6���r���r�����environ�pathr�����isabs�FileNotFoundErrorr����Z CreateProcess�fspathrF���r����r����r����r����r����rC����_handler����rE���)r���r]���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�����tidr���r���r���r����p��s~���� zPopen._execute_childc�������������C���s,���|�j�dkr&||�jd�|kr&||�j�|�_�|�j�S�)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��)r���rN���Z_WaitForSingleObjectZ_WAIT_OBJECT_0Z_GetExitCodeProcessr���r���r���rP������s���� zPopen._internal_pollc�������������C���s^���|dkrt�j}nt|d��}|�jdkrXt��|�j|�}|t�jkrJt|�j|��t�� |�j�|�_|�jS�)z-Internal implementation of wait() on Windows.Ni���) rK���ZINFINITErG���r ����WaitForSingleObjectr��ZWAIT_TIMEOUTr���r]����GetExitCodeProcess)r���r���Ztimeout_millisr����r���r���r���r�������s���� zPopen._waitc�������������C���s���|��|�����|����d�S�)N)r\���r����r����)r���Zfh�bufferr���r���r���� _readerthread��s����zPopen._readerthreadc�������������C���s\��|�j�rBt|�d�sBg�|�_tj|�j|�j�|�jfd�|�_d|�j_|�j����|�j r�t|�d�s�g�|�_ tj|�j|�j |�j fd�|�_d|�j_|�j����|�jr�|�� |��|�j�d�k r�|�j�|��|���|�j���r�t|�j|��|�j d�k r�|�j�|��|���|�j���r�t|�j|��d�}d�}|�j��r|�j}|�j�����|�j �r0|�j }|�j ����|d�k �rB|d�}|d�k �rT|d�}||fS�)N�_stdout_buff)�targetr]���T�_stderr_buffr���)r���r����r ��r����ZThreadr��Z stdout_threadZdaemon�startr ���r��Z stderr_threadr����r����r����r����Zis_aliver���r]���r����)r���r����r����r����r���r ���r���r���r���r������sF���� zPopen._communicatec�������������C���sl���|�j�dk rdS�|tjkr"|�����nF|tjkr>t�|�jtj��n*|tjkrZt�|�jtj��nt d� |���dS�)zSend a signal to the process.NzUnsupported signal: {})r ���r����SIGTERM� terminateZCTRL_C_EVENTr����r}���r����ZCTRL_BREAK_EVENTr���r����)r����sigr���r���r����send_signal;��s���� zPopen.send_signalc�������������C���sX���|�j�dk rdS�yt�|�jd��W�n2�tk rR���t�|�j�}|tjkrH��||�_�Y�nX�dS�)zTerminates the process.Nrm���)r ���rK���ZTerminateProcessr���PermissionErrorr��ZSTILL_ACTIVE)r���Zrcr���r���r���r��I��s���� zPopen.terminatec������� ������C���s,��d\}}d\}}d\}} |dkr"n@|t�kr8t���\}}n*|tkrJ|����}nt|t�rZ|}n|���}|dkrln@|t�kr�t���\}}n*|tkr�|����}nt|t�r�|}n|���}|dkr�nf|t�kr�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 )rU���rU���NrU���)r'���r�����piper/���r����r����rG���r����r(���rQ���� __stdout__) r���r����r���r ���r����r����r����r����r����r����r���r���r���r����^��sJ���� c�������*���������s���t�|ttf�r|g}nt|�}| rLttd�r0dnd}|dg|�}��rL��|d<���dkr\|d�����}t���\}}g�}x |dk�r�|�|��t� |�}qrW�x|D�]}t� |��q�W��z�z�|dk �rg�}xL|���D�]:\}}t�|�}d|kr�t d ��|�|d�t�|����q�W�nd}t������tj�����r,��f}nt��fd d�t�|�D���}t|�}|�|��t�|||tttt|���||||| ||||||||�|�_d|�_W�dt� |��X�t|�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��qPW�W�dt� |��X�|�r�y6t� |�jd�\}!}"|!|�jk�r�|��!|"��ntj"|�_#W�n�t$k �r����Y�nX�y|�%dd�\}#}$}%|%�&��}%W�n,�t k �r.���d}#d}$d�'t|��}%Y�nX�tt(|#�&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-cr���Nr��������=z!illegal environment variable namec�������������3���s"���|�]}t�j�t��|����V��qd�S�)N)r����r����r�����fsencode)r�����dir)r����r���r���� <genexpr>���s���z'Popen._execute_child.<locals>.<genexpr>Tr����rU���iP�������:r����s���SubprocessError����0z#Bad exception data from child: {!r}�ascii����Znoexecr����z: )0r����r�����bytesr#���r����rQ���r����r��r\����dupr����rq���r��r���r�����dirname�tuple� get_exec_path�set�add�_posixsubprocessZ fork_exec�sorted�maprG���r����r����rr���r����� bytearrayr����r�����waitpid�_handle_exitstatusrR���r ����ChildProcessError�splitr����r�����builtinsr���� issubclassr�����strerrorr����ZENOENT�repr)*r���r]���r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����Z unix_shellZorig_executableZerrpipe_readZ errpipe_writeZlow_fds_to_closeZlow_fdZenv_list�krb���Zexecutable_listZfds_to_keepZ devnull_fdZerrpipe_data�partr����r����Zexception_nameZ hex_errnoZerr_msgZchild_exception_typeZ errno_numZchild_exec_never_calledZerr_filenamer���)r����r���r�������s����� c�������������C���sL���||�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���)r���r����Z_WIFSIGNALEDZ _WTERMSIGZ _WIFEXITEDZ_WEXITSTATUSZ_WIFSTOPPEDZ _WSTOPSIGr���r���r���r(��#��s����zPopen._handle_exitstatusc���������� ���C���s����|�j�dkr�|�j�d�sdS�z�y8|�j�dk r.|�j�S�||�j|�\}}||�jkrR|��|��W�nB�tk r��}�z$|dk rv||�_�n|j|kr�d|�_�W�dd}~X�Y�nX�W�d|�j����X�|�j�S�)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)r���rN���Z_waitpidZ_WNOHANGZ_ECHILDr����r�����er���r���r���rP���5��s ���� c�������������C���s>���yt��|�j|�\}}W�n�tk r4���|�j}d}Y�nX�||fS�)z:All callers to this function MUST hold self._waitpid_lock.r���)r����r'��r����r)��)r���Z wait_flagsr����r����r���r���r���� _try_waitX��s���� zPopen._try_waitc���������� ���C���s&��|�j�dk r|�j�S�|dk r�t��|�}d}x�|�j�d�r�zL|�j�dk rBP�|��tj�\}}||�jksh|dksht�||�jkr~|�� |��P�W�d|�j� ���X�|��|�}|dkr�t|�j |��t|d�|d�}t�|��q(W�nTxR|�j�dk�r|�j�6�|�j�dk r�P�|��d�\}}||�jk�r|�� |��W�dQ�R�X�q�W�|�j�S�)z+Internal implementation of wait() on POSIX.Ng����Mb@?Fr���r����g�������?)r ���r����r����r1��r4��r�����WNOHANGr����r����r(��r2��r����r���r]���r�����timeZsleep)r���r���r����Zdelayr����r����Z remainingr���r���r���r����e��s:���� c���������� ���C���s,��|�j�rX|�jsXy|�j�����W�n�tk r.���Y�nX�|sXy|�j�����W�n�tk rV���Y�nX�d�}d�}|�js�i�|�_|�jr~g�|�j|�j<�|�jr�g�|�j|�j<�|�jr�|�j|�j�}|�jr�|�j|�j�}|��|��|�j r�t |�j �}t�����}|�j�r�|r�|�|�j�t j��|�j�r|�jj�s|�|�jt j��|�j�r6|�jj�s6|�|�jt j���x^|����r�|��|�}|d�k �r~|dk��r~|�j||||dd��td��|�|�} |��||||��x�| D�]�\} }| j|�j�k�r<||�j|�jt���}y|��jt�| j|�7��_W�n,�tk �r���|�| j��| j����Y�n*X�|�jt|�j �k�r�|�| j��| j����nP| j|�j|�jfk�r�t�| jd�} | �sz|�| j��| j����|�j| j��| ���q�W��q:W�W�d�Q�R�X�|�j |��|�d��|d�k �r�d�!|�}|d�k �r�d�!|�}|�j"�r$|d�k �r|��#||�jj$|�jj%�}|d�k �r$|��#||�jj$|�jj%�}||fS�)Nr���T)r����zN_check_timeout(..., skip_check_and_raise=True) failed to raise TimeoutExpired.i����)r���r����)&r����r�����flushr����r����Z_fileobj2outputr���r ����_save_inputr����� memoryview�_PopenSelector�register� selectorsZEVENT_WRITErD���Z EVENT_READZget_mapr����r�����RuntimeError�selectZfileobj� _input_offset� _PIPE_BUFr����r����r����Z unregisterr����r����r\���r|���r����r����r����r����r����)r���r����r����r����r���r ���Z input_viewZselectorr���Zready�keyZevents�chunkr����r���r���r���r�������s����� ( c�������������C���sF���|�j�rB|�jd�krBd|�_||�_|d�k rB|�jrB|�j�|�j�j|�j�j�|�_d�S�)Nr���)r����r����r?��r�����encoder����r����)r���r����r���r���r���r8�����s����zPopen._save_inputc�������������C���s���|�j�dkrt�|�j|��dS�)zSend a signal to the process.N)r ���r����r}���r����)r���r��r���r���r���r�����s���� c�������������C���s���|���tj��dS�)z/Terminate the process with SIGTERM N)r��r���r ��)r���r���r���r���r����s����c�������������C���s���|���tj��dS�)z*Kill the process with SIGKILL N)r��r����SIGKILL)r���r���r���r���r}�����s����z Popen.kill)rU���NNNNNTFNNNNr���TFr���)NN)F)N)6r���r���r���r���r����r���r���r����r���r����r����r����rQ���rR���r����r����rL���r����r����r����r����r����r����r|���r����r����r����r����r����rK���r��Z WAIT_OBJECT_0r��rP���r����r��r����r��r��r}���r�����WIFSIGNALED�WTERMSIG� WIFEXITED�WEXITSTATUS� WIFSTOPPED�WSTOPSIGr(��r'��r5��r����ZECHILDr4��r8��r���r���r���r���r&���y��sl���-������� D H q46�" )f)Er���rQ����platformr����r����r����r6��r���r+��r����r����r���r����� Exceptionr���r ���r���r����r����rK���r���r#��r>��r<��rr���r@��r����r%���r:��ZSelectSelector�__all__r1���r2���r3���r4���r5���r6���r7���r8���r9���r:���r;���r<���r=���r>���r?���r@���rA���rB���rw���rG���rC���rO���rM���r'���r(���r/���r^���r{���r)���r*���r-����objectr0���r.���r����r+���r,���r&���r���r���r���r����<module>*���sz��� % P ;/"DI