a Z^!B@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddlm Z ddl Z z ddlZWneydZYn0z ddlZWneydZYn0gdZzddlZddlZdZWn.eydZddlZddlZddlZYn`0ddlmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*e+gdGd d d e,Z-Gd d d e-Z.Gd dde-Z/erGdddZ0Gddde1Z2n&e3eddZ4e5edrej6Z7nej8Z7erdZ9ddZ:n gZ9ddZ:dZ;dZddZ?dd d!d"Z@d#d$ZAdd d%d&ZBGd'd(d(eCZDddddd)d*d+ZEd,d-ZFd.d/ZGd0d1ZHd2d3ZIeIZJGd4d5d5eCZKdS)6aSubprocesses 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)PopenPIPESTDOUTcall check_callgetstatusoutput getoutput check_outputrunCalledProcessErrorDEVNULLSubprocessErrorTimeoutExpiredCompletedProcessTF)CREATE_NEW_CONSOLECREATE_NEW_PROCESS_GROUPSTD_INPUT_HANDLESTD_OUTPUT_HANDLESTD_ERROR_HANDLESW_HIDESTARTF_USESTDHANDLESSTARTF_USESHOWWINDOWABOVE_NORMAL_PRIORITY_CLASSBELOW_NORMAL_PRIORITY_CLASSHIGH_PRIORITY_CLASSIDLE_PRIORITY_CLASSNORMAL_PRIORITY_CLASSREALTIME_PRIORITY_CLASSCREATE_NO_WINDOWDETACHED_PROCESSCREATE_DEFAULT_ERROR_MODECREATE_BREAKAWAY_FROM_JOB)rrrrrrrr STARTUPINFOrrrrrrrr r!r"c@s eZdZdS)rN)__name__ __module__ __qualname__r'r'"/usr/lib64/python3.9/subprocess.pyrirc@s<eZdZdZd ddZddZeddZejd dZdS) r zRaised when run() is called with check=True and the process returns a non-zero exit status. Attributes: cmd, returncode, stdout, stderr, output NcCs||_||_||_||_dSN) returncodecmdoutputstderr)selfr+r,r-r.r'r'r(__init__sszCalledProcessError.__init__cCsf|jrR|jdkrRzd|jt|j fWStyNd|j|j fYS0nd|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,signalSignals ValueErrorr/r'r'r(__str__ys  zCalledProcessError.__str__cCs|jS)z+Alias for output attribute, to match stderrr-r4r'r'r(stdoutszCalledProcessError.stdoutcCs ||_dSr*r6r/valuer'r'r(r7s)NN r$r%r&__doc__r0r5propertyr7setterr'r'r'r(r ls   r c@s<eZdZdZd ddZddZeddZejd dZdS) rzThis exception is raised when the timeout expires while waiting for a child process. Attributes: cmd, output, stdout, stderr, timeout NcCs||_||_||_||_dSr*)r,timeoutr-r.)r/r,r>r-r.r'r'r(r0szTimeoutExpired.__init__cCsd|j|jfS)Nz'Command '%s' timed out after %s seconds)r,r>r4r'r'r(r5s zTimeoutExpired.__str__cCs|jSr*r6r4r'r'r(r7szTimeoutExpired.stdoutcCs ||_dSr*r6r8r'r'r(r7s)NNr:r'r'r'r(rs  rc@s,eZdZdddddddddZddZdS)r#rNdwFlags hStdInput hStdOutput hStdError wShowWindowlpAttributeListcCs0||_||_||_||_||_|p(dgi|_dS)N handle_listr?)r/r@rArBrCrDrEr'r'r(r0s zSTARTUPINFO.__init__cCs@|j}d|vr"t|d|d<t|j|j|j|j|j|dS)NrFr?) rEcopylistr#r@rArBrCrD)r/Z attr_listr'r'r(rGs zSTARTUPINFO.copy)r$r%r&r0rGr'r'r'r(r#s r#c@s2eZdZdZejfddZddZddZeZ dS) HandleFcCs|jsd|_||dS)NT)closed)r/ CloseHandler'r'r(Closesz Handle.ClosecCs |jsd|_t|StddS)NTzalready closed)rJintr3r4r'r'r(Detachsz Handle.DetachcCsd|jjt|fS)Nz%s(%d)) __class__r$rMr4r'r'r(__repr__szHandle.__repr__N) r$r%r&rJ_winapirKrLrNrP__del__r'r'r'r(rIs rIPIPE_BUFi PollSelectorcCsdSr*r'r'r'r'r(_cleanupsrUc CsZtdur dStddD]<}|jtjd}|durzt|WqtyRYq0qdS)N _deadstate)_active_internal_pollsysmaxsizeremover3)instresr'r'r(rUs cCs*g}tjj}|dkr&|dd||S)zgReturn a list of command-line arguments reproducing the current optimization settings in sys.flags.r-O)rZflagsoptimizeappend)argsr9r'r'r("_optim_args_from_interpreter_flagss rhc CsVddddddd}t}|D].\}}ttj|}|dkr |d ||q tjjrd|d n$tjjrv|d tjjr|d tj d d }tjj }ttdi}d|v}|dkr| dn|r| d|r| d|D]}|d|q|r | ddD]B}||vr||} | dur4|} n d|| f} | d| fq|S)z}Return a list of command-line arguments reproducing the current settings in sys.flags, sys.warnoptions and sys._xoptions.dBSvbq)debugdont_write_bytecodeno_siteverbose bytes_warningquietrrbz-Iz-Ez-sN _xoptionsdevzerror::BytesWarningzdefault::BytesWarningdefaultz-W)-Xrv) faulthandler tracemalloc importtime showrefcountutf8 oldparserTz%s=%sry) rhitemsgetattrrZrdrfisolatedignore_environment no_user_site warnoptionsrsr\extend) flag_opt_maprgflagoptrlwarnoptsrsxoptionsdev_moder9argr'r'r(_args_from_interpreter_flagssP             rr>cOsft|i|D}z|j|dWWdS|Yn0Wdn1sX0YdS)zRun 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)rwaitkill)r> popenargskwargspr'r'r(rUs rcOs:t|i|}|r6|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"]) rgNr)rgetr )rrretcoder,r'r'r(rfs   rcOsTd|vrtdd|vr<|ddur<|ddr4dnd|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. r7z3stdout argument not allowed, it will be overridden.inputNuniversal_newlinesFr)T)r7r>check)r3rr rr7)r>rrr'r'r(r ys#r c@s4eZdZdZd ddZddZeejZ ddZ 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). NcCs||_||_||_||_dSr*)rgr+r7r.)r/rgr+r7r.r'r'r(r0szCompletedProcess.__init__cCshd|jd|jg}|jdur4|d|j|jdurP|d|jdt|jd|S)Nz args={!r}zreturncode={!r}z stdout={!r}z stderr={!r}z{}({})z, ) formatrgr+r7rfr.typer$join)r/rgr'r'r(rPs    zCompletedProcess.__repr__cCs |jrt|j|j|j|jdS)z6Raise CalledProcessError if the exit code is non-zero.N)r+r rgr7r.r4r'r'r(check_returncodesz!CompletedProcess.check_returncode)NN) r$r%r&r;r0rP classmethodtypes GenericAlias__class_getitem__rr'r'r'r(rs   r)rcapture_outputr>rc Os<|dur&|ddurtdt|d<|r^|ddusF|ddurNtdt|d<t|d<t|i|}z|j||d\}}Wn`ty} z4|tr|\| _| _ n| WYd} ~ nd} ~ 0|Yn0| } |r | r t | |j ||dWdn1s"0Yt|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. Nstdinz/stdin and input arguments may not both be used.r7r.z@stdout and stderr arguments may not be used with capture_output.rr-r.)rr3rr communicaterr _mswindowsr7r.rpollr rgr) rrr>rrrprocessr7r.excrr'r'r(r s6 &r cCsg}d}ttj|D]}g}|r*|dd|vp>d|vp>| }|rN|d|D]b}|dkrj||qR|dkr|dt|dg}|dqR|r||g}||qR|r|||r|||dqd|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)maposfsdecoderflenrr)seqresult needquoterbs_bufcr'r'r( list2cmdlines4         rc Csnzt|ddtd}d}Wn0tyH}z|j}|j}WYd}~n d}~00|dddkrf|dd}||fS)aReturn (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)shelltextr.rNr_ )r rr r-r+)r,dataexitcodeexr'r'r(rZs 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' rw)r)r,r'r'r(r ys r c CststtdsdStjdkr dSzjtd}|jdd}t|dkrHt|d }t t t |dd }tjd kr|d kr|d krWdSWnt tt fyYn0dS)aCheck 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_spawnFdarwinTCS_GNU_LIBC_VERSIONrw)maxsplitrr.linuxglibc)r)rhasattrrrZplatformconfstrsplitrr3tuplerrMAttributeErrorOSError)verpartslibcversionr'r'r(_use_posix_spawns      rc@seZdZdZdZdMddddddddd d Zd d Zeej Z e d dZ e j ddZ ddZddZddZejejfddZddZddZdNddZddZd d!ZdOd"d#ZdPd$d%Zd&d'Zer4d(d)Zd*d+Z d,d-Z!d.d/Z"de#j$e#j%e#j&fd0d1Z'd2d3Z(d4d5Z)d6d7Z*d8d9Z+d:d;Z,e,Z-n~dZ.d?d/Z"e/j0e/j1e/j2fd@dAZ3de/j4e/j5e6j7fdBd1Z'dCdDZ8dEd3Z(dFd7Z*dGdHZ9dId9Z+dJd;Z,dKdLZ-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 Fr_NTrr')usergroup extra_groupsencodingerrorsrumaskc(CsFtt|_d|_d|_|dur(d}t|ts:tdt rP|durt dn8|rh|sht dt d}| durxt d|d krt d ||_d|_d|_d|_d|_d|_||_||_|dur| durt| t|krtd ||||\}}}}}}t rN|dkrt|d }|dkr4t|d }|dkrNt|d }|pb|pb|pb| |_d |_d|_|jr|d krd}d}nd}d} |durtt dst dnPt|t!rt"durt dt"#|j$} n$t|tr|} ntd%t&|| d krt d| d}!|durtt dsBt dnt|t!rVt dg}!|D]b}"t|"t!rt"durt d|!'t"#|"j$n*t|"tr|!'|"ntd%t&|"q^|!D]}#|#d krt d|#qd}$|durhtt ds t dnFt|t!r6t(dur(t dt()|j*}$nt|trH|}$ntd|$d krht d|$z|dkrt+,|d||_|jrt+j-|jd|||d|_|dkrt+,|d||_|jrt+j-|j||d |_|dkrt+,|d||_|jrt+j-|j||d |_|.|||||| | | || |||||||| |!|$||Wnt/d|j|j|jfD](}%z |%0Wnt1yYn0qd|js:g}&|t2kr|&'||t2kr|&'||t2kr|&'|t|d!r|&'|j3|&D]F}'z*t rt|'t4r|'5n t 0|'Wnt1y4Yn0qYn0dS)"zCreate new Popen instance.NFr_zbufsize 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?rwsetregidz>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_throughline_bufferingrrrb)rr_devnull)6rU threadingLock _waitpid_lock_input_communication_started isinstancerM TypeErrorrr3warningswarnRuntimeWarningrgrr7r.pidr+rrboolr _get_handlesmsvcrtopen_osfhandlerN text_mode_sigint_wait_secs_closed_child_pipe_fdsrrstrgrpgetgrnamgr_gidrrrfpwdgetpwnampw_uidioopen TextIOWrapper_execute_childfiltercloserrrrIrL)(r/rgbufsize executablerr7r. preexec_fn close_fdsrcwdenvr startupinfo creationflagsrestore_signalsstart_new_sessionpass_fdsrrrrrrrp2creadp2cwritec2preadc2pwriteerrreaderrwritergidgids extra_group gid_checkuidfto_closefdr'r'r(r0s.                                                    zPopen.__init__cCsDd|jjd|jdt|jd}t|dkr@|ddd}|S)NPLz...>)rOr$r+rHrgr)r/obj_reprr'r'r(rPs zPopen.__repr__cCs|jSr*)rr4r'r'r(rszPopen.universal_newlinescCst||_dSr*)rr)r/rr'r'r(rscCs |||}|ddddS)Nz r )decodereplace)r/rrrr'r'r(_translate_newliness zPopen._translate_newlinescCs|Sr*r'r4r'r'r( __enter__szPopen.__enter__cCs|jr|j|jr |jz^|jr2|jW|tkrv|jdkrlz|j|jdWntyjYn0d|_dS|nT|tkr|jdkrz|j|jdWntyYn0d|_YdS|0dS)Nrr) r7rr.rKeyboardInterruptr_waitrr)r/exc_typer9 tracebackr'r'r(__exit__s2         zPopen.__exit__cCsT|js dS|jdur(|d|jt|d|j|d|jdurPtdurPt|dS)Nzsubprocess %s is still running)sourcerV)_child_createdr+rResourceWarningrYrXrf)r/_maxsize_warnr'r'r(rRs   z Popen.__del__cCs"t|dsttjtj|_|jS)Nr)rrrdevnullO_RDWRrr4r'r'r( _get_devnull s zPopen._get_devnullc Cs|rZz|j|WnDty&Yn4tyX}z|jtjkrBnWYd}~n d}~00z|jWnDtyzYn4ty}z|jtjkrnWYd}~n d}~00dSr*)rwriteBrokenPipeErrorrerrnoEINVALr)r/rrr'r'r( _stdin_write%s"    zPopen._stdin_writec CsV|jr|rtd|dur|js|j|j|jgddkrd}d}|jrT||n6|jrp|j}|jn|jr|j}|j| n|durt |}nd}zz| |||\}}Wndt y(|durt |j||}n|j}d|_z|j|dWnty Yn0Yn0Wd|_nd|_0|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 communicationNrrrT)rr3rr7r.countr5readrr_time _communicater$minr_remaining_timer%r)r/rr>r7r.endtimesigint_timeoutstsr'r'r(r>sH         zPopen.communicatecCs|S)zSCheck if child process has terminated. Set and return returncode attribute.)rYr4r'r'r(rsz Popen.pollcCs|dur dS|tSdS)z5Convenience for _communicate when computing timeouts.N)r8)r/r<r'r'r(r;szPopen._remaining_timecCsL|dur dS|st|krHt|j||r0d|nd|r@d|ndddS)z2Convenience for checking if a timeout has expired.Nr)r)r8rrgr)r/r< orig_timeout stdout_seq stderr_seqskip_check_and_raiser'r'r(_check_timeoutszPopen._check_timeoutc Cs|durt|}z|j|dWSty|durJt|j||}n|j}d|_z|j|dWntyxYn0Yn0dS)z=Wait for child process to terminate; returns self.returncode.Nrr)r8r%r$r:rr;r)r/r>r<r=r'r'r(rs    z Popen.waitc Cst|dd}t}trX|dkr.||j|dkrB||j|dkr||jnr|dkr~|dkr~||kr~|tj||dkr|dkr||kr|tj||dkr|dkr||kr|tj||dur|tj|Wdn1s0Yd|_dS)Nrr_T) r contextlib ExitStackrcallbackrLrrr) r/r r rrrr devnull_fdstackr'r'r(_close_pipe_fdss$    ,zPopen._close_pipe_fdsc Cs~|dur|dur|durdSd\}}d\}}d\}} |durtttj}|durtdd\}} t|}t| nh|tkrtdd\}}t|t|}}n<|tkrt | }n$t |t rt |}nt | }||}|dur*ttj}|durtdd\} }t|}t| nn|tkrXtdd\}}t|t|}}n@|tkrrt | }n&t |t rt |}nt | }||}|durttj} | durdtdd\} } t| } t| n~|tkrtdd\}} t|t| }} nP|tkr$|} n@|tkr>t | } n&t |t rVt |} nt | } || } |||||| fS)|Construct and return tuple with IO objects: p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite N)r_r_r_r_r_r_r_r_r)rQZ GetStdHandlerZ CreatePiperIrKrr rZ get_osfhandler0rrMfileno_make_inheritablerrr) r/rr7r.r r rrrr_r'r'r(rsp                        zPopen._get_handlescCs&tt|tddtj}t|S)z2Return a duplicate of handle, which is inheritablerrw)rQZDuplicateHandleZGetCurrentProcessZDUPLICATE_SAME_ACCESSrI)r/handlehr'r'r(rMs  zPopen._make_inheritablecCstdd|DS)zFilter 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))rQZ GetFileTypeZFILE_TYPE_CHAR).0rOr'r'r( ,s  z,Popen._filter_handle_list..)rH)r/rFr'r'r(_filter_handle_list%szPopen._filter_handle_listc Cs8t|tr nNt|tr.| r"tdt|g}n,t|tjrR| rFtdt|g}nt|}|durlt|}|dur|t}n| }d| ||fv}|r|j t j O_ | |_ ||_||_|j}t|od|vo|d}|s|r^|r^|duri}|_t|dg}|d<|r0|t| t|t|g7}|||dd<|r^|sZtdtd}| r|j t jO_ t j|_tjdd }d ||}|durt|}td ||||z@t ||ddt| | ||| \}}}}W|!| | | |||n|!| | | |||0d |_"t#||_$||_%t &|dS) z$Execute program (MS Windows version)z$bytes args is not allowed on Windows0path-like args is not allowed when shell is trueNr_rFz?startupinfo.lpAttributeList['handle_list'] overriding close_fdsFZCOMSPECzcmd.exez {} /c "{}"subprocess.PopenT)'rrbytesrrrPathLikerr#rGr@rQrrArBrCrErrHrrMrTrrrrrrDenvironrrZauditZ CreateProcessrIr*rI_handlerrK) r/rgrrrr rrrrrr r rrrrZunused_restore_signalsZ unused_gidZ unused_gidsZ unused_uidZ unused_umaskZunused_start_new_sessionZuse_std_handlesZattribute_listZhave_handle_listrFZcomspecZhpZhtrtidr'r'r(r2s            zPopen._execute_childcCs,|jdur&||jd|kr&||j|_|jS)zCheck 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/rWZ_WaitForSingleObjectZ_WAIT_OBJECT_0Z_GetExitCodeProcessr'r'r(rYs  zPopen._internal_pollcCs^|durtj}n t|d}|jdurXt|j|}|tjkrJt|j|t |j|_|jS)z-Internal implementation of wait() on Windows.Ni) rQZINFINITErMr+WaitForSingleObjectr[Z WAIT_TIMEOUTrrgGetExitCodeProcess)r/r>Ztimeout_millisrr'r'r(r%s    z Popen._waitcCs|||dSr*)rfr7r)r/Zfhbufferr'r'r( _readerthreadszPopen._readerthreadcCs\|jrBt|dsBg|_tj|j|j|jfd|_d|j_|j|j rt|dsg|_ tj|j|j |j fd|_ d|j _|j |j r| ||jdur|j|||jrt|j||j dur|j |||j rt|j|d}d}|jr|j}|j|j r0|j }|j |durB|d}|durT|d}||fS)N _stdout_buff)targetrgT _stderr_buffr)r7rrarThreadr`Z stdout_threaddaemonstartr.rcZ stderr_threadrr5rr;is_aliverrgr)r/rr<r?r7r.r'r'r(r9sN               zPopen._communicatecCsl|jdurdS|tjkr"|nF|tjkr>t|jtjn*|tjkrZt|jtjnt d |dS)Send a signal to the process.NzUnsupported signal: {}) r+r1SIGTERM terminateZ CTRL_C_EVENTrrrZCTRL_BREAK_EVENTr3rr/sigr'r'r( send_signals     zPopen.send_signalcCsV|jdurdSzt|jdWn0tyPt|j}|tjkrF||_Yn0dS)zTerminates the process.Nrw)r+rQZTerminateProcessr[PermissionErrorr^Z STILL_ACTIVE)r/rcr'r'r(rj s    zPopen.terminatec Cs,d\}}d\}}d\}} |dur"n@|tkr8t\}}n*|tkrJ|}nt|trZ|}n|}|durln@|tkrt\}}n*|tkr|}nt|tr|}n|}|durnf|tkrt\}} nP|tkr|dkr|} n t j } n.|tkr|} nt|tr|} n|} |||||| fS)rJrKNr_) rrpiper r0rrMrLrrZ __stdout__) r/rr7r.r r rrrrr'r'r(rsL        c Cs|durtj}i} |rJg} dD]"} tt| d}|dur| |q| | d<g}||| fD]}|dkrX|tj|fqX|df|df| dffD]"\}}|dkr|tj||fq|r|| d<tj|||fi| |_d |_ | ||||| | dS) z'Execute program using os.posix_spawn().N)SIGPIPESIGXFZSIGXFSZ setsigdefr_rrwr file_actionsT) rrYrr1rfPOSIX_SPAWN_CLOSEPOSIX_SPAWN_DUP2rrr*rI)r/rgrrr r r rrrrrsigsetsignamesignumrvrfd2r'r'r( _posix_spawnTs8   zPopen._posix_spawnc-st|ttfr|g}n(t|tjr6| r.td|g}nt|}| rlttdrPdnd}|dg|}rl|d<dur||dt d|||t rFtj rF|durF|sF|sF|durF| d ks| d krF|d ks|d krF|d ks|d krF|sF|durF|durF|durF|dkrF| |||| | | ||| dS}t\}}g}|d kr|||t|}qZ|D]}t|qzhz|durg}|D]>\}}t|}d |vrtd ||d t|qnd}ttj rf} ntfddt|D} t|}!|!|t|| |tttt|!||| | | |||||||||||||_d|_Wt|n t|0| | | | |||t!}"t"|d}#|"|#7}"|#rt#|"dkrqqWt|n t|0|"rz6t$|jd\}$}%|$|jkr<|%|%ntj&|_'Wnt(yZYn0z|")dd \}&}'}(|(*}(Wn*tyd}&d}'d+t|"}(Yn0t,t-|&*dt.})t/|)t0r|'rt|'d}*|(dk}+|+rd}(|},n|},|*dkrt1|*}(|)|*|(|,|)|(dS)zExecute program (POSIX version)rUgetandroidapilevelz/system/bin/shz/bin/shz-crNrVr_rrQ=z!illegal environment variable namec3s"|]}tjt|VqdSr*)rpathrfsencode)rRdirrr'r( sz'Popen._execute_child..TiP:sSubprocessError0z#Bad exception data from child: {!r}asciinoexecr)2rrrWrrXrrHrrZrZ_USE_POSIX_SPAWNrdirnamer}rprfduprrrr3r get_exec_pathsetadd_posixsubprocess fork_execsortedrrMrr*rI bytearrayr7rwaitpid_handle_exitstatusr[r+ChildProcessErrorrr rrbuiltinsr issubclassrstrerror)-r/rgrrrr rrrrrr r rrrrr rrrrr  unix_shellorig_executable errpipe_read errpipe_writelow_fds_to_closelow_fdenv_listkrlexecutable_list fds_to_keep errpipe_datapartrr>exception_name hex_errnoerr_msgchild_exception_type errno_numchild_exec_never_called err_filenamer'rr(r{s                                 cCs$||r|| |_n |||_dS):All callers to this function MUST hold self._waitpid_lock.N)r+)r/r>waitstatus_to_exitcode _WIFSTOPPED _WSTOPSIGr'r'r(rszPopen._handle_exitstatusc Cs|jdur|jdsdSzzF|jdur<|jWW|jS||j|\}}||jkr`||WnDty}z,|dur||_n|j|krd|_WYd}~n d}~00W|jn |j0|jS)zCheck 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+racquirereleaserrrr3)r/rW_waitpid_WNOHANG_ECHILDrr>er'r'r(rY+s$      cCs<zt|j|\}}Wnty2|j}d}Yn0||fS)rr)rrrr)r/ wait_flagsrr>r'r'r( _try_waitNs   zPopen._try_waitcCsP|jdur|jS|durt|}d}|jdrzX|jdurLW|jq|tj\}}||jkr~| |W|jqW|jn |j0| |}|dkrt |j |t |d|d}t|q&nv|jdurJ|jP|jdurWdqJ|d\}}||jkr(| |Wdq1s>0Yq|jS)z+Internal implementation of wait() on POSIX.NgMb@?Frrg?)r+r8rrrrrWNOHANGrrr;rrgr:timesleep)r/r>r<delayrr> remainingr'r'r(r%[s>             ,c Cs2|jrT|jsTz|jWnty,Yn0|sTz|jWntyRYn0d}d}|jsi|_|jrzg|j|j<|jrg|j|j<|jr|j|j}|jr|j|j}|||j rt |j }t }|jr|r| |jt j|jr|jjs| |jt j|jr2|jjs2| |jt j|r||}|durv|dkrv|j||||ddtd||} |||||| D]\} } | j|jur0||j|jt} z|jt| j| 7_Wn*ty|| j| jYn*0|jt|j kr|| j| jnP| j|j|jfvrt| jd} | sn|| j| j|j| j| qq2Wdn1s0Y|j ||d|durd!|}|durd!|}|j"r*|dur |#||jj$|jj%}|dur*|#||jj$|jj%}||fS)NrT)rBzN_check_timeout(..., skip_check_and_raise=True) failed to raise TimeoutExpired.irr))&rrflushr2r_fileobj2outputr7r. _save_inputr memoryview_PopenSelectorregister selectors EVENT_WRITErJ EVENT_READget_mapr;rC RuntimeErrorselectfileobj _input_offset _PIPE_BUFrr1r unregisterrr7rfrrrr"rr)r/rr<r?r7r. input_viewselectorr>readykeyeventschunkrr'r'r(r9s                    :      cCsF|jrB|jdurBd|_||_|durB|jrB|j|jj|jj|_dS)Nr)rrrrencoderr)r/rr'r'r(rs zPopen._save_inputcCs(||jdurdSt|j|dS)rhN)rr+rrrrkr'r'r(rms cCs|tjdS)z/Terminate the process with SIGTERM N)rmr1rir4r'r'r(rjscCs|tjdS)z*Kill the process with SIGKILL N)rmr1SIGKILLr4r'r'r(rsz Popen.kill)r_NNNNNTFNNNNrTFr')NN)F)N):r$r%r&r;r*r0rPrrrrr<rr=r"r#r(rZr[rrrRr0r5rrr;rCrrIrrrMrTrrQr]Z WAIT_OBJECT_0r^rYr%r`r9rmrjrr}rr WIFSTOPPEDWSTOPSIGrrrr3ECHILDrrr'r'r'r(rs5 j    D H  o 46'&  # )f r)Lr;rr3rrrr1rZrrrDrr8rr ImportErrorr__all__rrQrModuleNotFoundErrorrrrrrrrrrrrrrrrrrrr r!r"r Exceptionrr rr#rMrIrrrrTrSelectSelectorrXrUrrr rhrrrr objectrr rrr rrrr'r'r'r( s"        P  %      ;/% EI /