B œ< "b#+ã@s`dZddlZejdkZddlZddlZddlZddlZddlZddl Z ddl Z ddlm Z Gdd„de ƒZGdd„deƒZGd d „d eƒZer¶ddlZddlZddlZGd d „d ƒZnDddlZddlZddlZddlZeed dƒZeedƒrôejZnejZddddddddddddd dgZer°ddlmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0e 1ddddd d!d"d#d d$d%d&d'd(d)d*d+d,d-g¡Gd.d/„d/e2ƒZ3erÄdZ4d0d1„Z5n gZ4d2d1„Z5d3Z6d4Z7d5Z8d6d7„Z9d8d9„Z:dd:œd;d„Z;dd„de>ƒZ?dd?dd?d@œdAd„Z@dBdC„ZAdDd„ZBdEd„ZCGdFd„de>ƒZDdS)Ga•Subprocesses with accessible I/O streams This module allows you to spawn processes, connect to their input/output/error pipes, and obtain their return codes. For a complete description of this module see the Python documentation. Main API ======== run(...): Runs a command, waits for it to complete, then returns a CompletedProcess instance. Popen(...): A class for flexibly executing a command in a new process Constants --------- DEVNULL: Special value that indicates that os.devnull should be used PIPE: Special value that indicates a pipe should be created STDOUT: Special value that indicates that stderr should go to stdout Older API ========= call(...): Runs a command, waits for it to complete, then returns the return code. check_call(...): Same as call() but raises CalledProcessError() if return code is not 0 check_output(...): Same as check_call() but returns the contents of stdout instead of a return code getoutput(...): Runs a command in the shell, waits for it to complete, then returns the output getstatusoutput(...): Runs a command in the shell, waits for it to complete, then returns a (exitcode, output) tuple éNZwin32)Ú monotonicc@s eZdZdS)ÚSubprocessErrorN)Ú__name__Ú __module__Ú __qualname__©rrú-/opt/alt/python37/lib/python3.7/subprocess.pyr9src@s<eZdZdZd dd„Zdd„Zedd„ƒZejd d„ƒZdS) ÚCalledProcessErrorz£Raised when run() is called with check=True and the process returns a non-zero exit status. Attributes: cmd, returncode, stdout, stderr, output NcCs||_||_||_||_dS)N)Ú returncodeÚcmdÚoutputÚstderr)Úselfr r r r rrrÚ__init__CszCalledProcessError.__init__cCsb|jrN|jdkrNyd|jt |j ¡fStk rJd|j|j fSXnd|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 )rr rr r rrrrhszTimeoutExpired.__init__cCsd|j|jfS)Nz'Command '%s' timed out after %s seconds)r r)rrrrrnszTimeoutExpired.__str__cCs|jS)N)r )rrrrrrszTimeoutExpired.stdoutcCs ||_dS)N)r )rrrrrrvs)NN) rrrrrrrrrrrrrras   rc@s,eZdZdddddddœdd„Zdd„ZdS)Ú STARTUPINFOrN)ÚdwFlagsÚ hStdInputÚ hStdOutputÚ hStdErrorÚ wShowWindowÚlpAttributeListcCs0||_||_||_||_||_|p(dgi|_dS)NÚ handle_list)rrrrrr )rrrrrrr rrrr‚s zSTARTUPINFO.__init__cCs@|j ¡}d|kr"t|dƒ|d<t|j|j|j|j|j|dS)Nr!)rrrrrr ) r ÚcopyÚlistrrrrrr)rZ attr_listrrrÚ_copy‹s zSTARTUPINFO._copy)rrrrr$rrrrrsrZPIPE_BUFiÚ PollSelectorÚPopenÚPIPEÚSTDOUTÚcallÚ check_callÚgetstatusoutputÚ getoutputÚ check_outputÚrunÚDEVNULLÚCompletedProcess)ÚCREATE_NEW_CONSOLEÚCREATE_NEW_PROCESS_GROUPÚSTD_INPUT_HANDLEÚSTD_OUTPUT_HANDLEÚSTD_ERROR_HANDLEÚSW_HIDEÚSTARTF_USESTDHANDLESÚSTARTF_USESHOWWINDOWÚABOVE_NORMAL_PRIORITY_CLASSÚBELOW_NORMAL_PRIORITY_CLASSÚHIGH_PRIORITY_CLASSÚIDLE_PRIORITY_CLASSÚNORMAL_PRIORITY_CLASSÚREALTIME_PRIORITY_CLASSÚCREATE_NO_WINDOWÚDETACHED_PROCESSÚCREATE_DEFAULT_ERROR_MODEÚCREATE_BREAKAWAY_FROM_JOBr1r2r3r4r5r6r7r8r9r:r;r<r=r>r?r@rArBc@s6eZdZdZejfdd„Zdd„Zdd„ZeZ eZ dS) ÚHandleFcCs|jsd|_||ƒdS)NT)Úclosed)rÚ CloseHandlerrrÚCloseÊsz Handle.ClosecCs |jsd|_t|ƒStdƒ‚dS)NTzalready closed)rDÚintr)rrrrÚDetachÏsz Handle.DetachcCsd|jjt|ƒfS)Nz%s(%d))Ú __class__rrG)rrrrÚ__repr__ÕszHandle.__repr__N) rrrrDÚ_winapirErFrHrJÚ__del__rrrrrrCÇs rCcCsdS)NrrrrrÚ_cleanupçsrMc Cs`tdkr dSxNtdd…D]>}|jtjd}|dk ryt |¡Wqtk rVYqXqWdS)N)Ú _deadstate)Ú_activeÚ_internal_pollÚsysÚmaxsizeÚremover)ÚinstZresrrrrMðséÿÿÿÿéþÿÿÿéýÿÿÿcCs*g}tjj}|dkr&| dd|¡|S)zgReturn a list of command-line arguments reproducing the current optimization settings in sys.flags.rú-ÚO)rQÚflagsÚoptimizeÚappend)ÚargsrrrrÚ"_optim_args_from_interpreter_flagss r^c Csbdddddddœ}tƒ}x:| ¡D].\}}ttj|ƒ}|dkr"| d ||¡q"Wtjjrh| d ¡n$tjjrz| d ¡tjjrŒ| d ¡tj d d …}tjj }ttdiƒ}d|k}|dkrÊ|  d¡n|rØ|  d¡|ræ|  d¡x|D]}| d|¡qìW|r|  d¡xJdD]B}||kr||} | dkr>|} n d|| f} |  d| f¡qW|S)z}Return a list of command-line arguments reproducing the current settings in sys.flags, sys.warnoptions and sys._xoptions.ÚdÚBÚSÚvÚbÚq)ÚdebugÚdont_write_bytecodeÚno_siteÚverboseÚ bytes_warningÚquietrrXz-Iz-Ez-sNÚ _xoptionsÚdevézerror::BytesWarningzdefault::BytesWarningÚdefaultz-W)z-Xrl)Z faulthandlerÚ tracemallocZ importtimeZshowalloccountZ showrefcountÚutf8Tz%s=%sz-X) r^ÚitemsÚgetattrrQrZr\ÚisolatedÚignore_environmentÚ no_user_siteÚ warnoptionsrirSÚextend) Z flag_opt_mapr]ÚflagZoptrbZwarnoptsriZxoptionsÚdev_moderÚargrrrÚ_args_from_interpreter_flagssN              r{)rc Os>t||Ž*}y |j|dS| ¡‚YnXWdQRXdS)zÞRun command with arguments. Wait for command to complete or timeout, then return the returncode attribute. The arguments are the same as for the Popen constructor. Example: retcode = call(["ls", "-l"]) )rN)r&ÚwaitÚkill)rÚ popenargsÚkwargsÚprrrr)Ks   cOs6t||Ž}|r2| d¡}|dkr(|d}t||ƒ‚dS)aORun command with arguments. Wait for command to complete. If the exit code was zero then return, otherwise raise CalledProcessError. The CalledProcessError object will have the return code in the returncode attribute. The arguments are the same as for the call function. Example: check_call(["ls", "-l"]) r]Nr)r)Úgetr )r~rÚretcoder rrrr*\s   cOsTd|krtdƒ‚d|kr<|ddkr<| dd¡r4dnd|d<t|t|d d œ|—ŽjS) aRun command with arguments and return its output. If the exit code was non-zero it raises a CalledProcessError. The CalledProcessError object will have the return code in the returncode attribute and output in the output attribute. The arguments are the same as for the Popen constructor. Example: >>> check_output(["ls", "-l", "/dev/null"]) b'crw-rw-rw- 1 root root 1, 3 Oct 18 2007 /dev/null\n' The stdout argument is not allowed as it is used internally. To capture standard error in the result, use stderr=STDOUT. >>> check_output(["/bin/sh", "-c", ... "ls -l non_existent_file ; exit 0"], ... stderr=STDOUT) b'ls: non_existent_file: No such file or directory\n' There is an additional optional argument, "input", allowing you to pass a string to the subprocess's stdin. If you use this argument you may not also use the Popen constructor's "stdin" argument, as it too will be used internally. Example: >>> check_output(["sed", "-e", "s/foo/bar/"], ... input=b"when in the course of fooman events\n") b'when in the course of barman events\n' By default, all communication is in bytes, and therefore any "input" should be bytes, and the return value will be bytes. If in text mode, any "input" should be a string, and the return value will be a string decoded according to locale encoding, or by "encoding" if set. Text mode is triggered by setting any of text, encoding, errors or universal_newlines. rz3stdout argument not allowed, it will be overridden.ÚinputNÚuniversal_newlinesFÚóT)rrÚcheck)rrr.r'r)rr~rrrrr-os #c@s*eZdZdZd dd„Zdd„Zdd„ZdS) r0aEA process that has finished running. This is returned by run(). Attributes: args: The list or str args passed to run(). returncode: The exit code of the process, negative for signals. stdout: The standard output (None if not captured). stderr: The standard error (None if not captured). NcCs||_||_||_||_dS)N)r]r rr )rr]r rr rrrr©szCompletedProcess.__init__cCshd |j¡d |j¡g}|jdk r4| d |j¡¡|jdk rP| d |j¡¡d t|ƒjd |¡¡S)Nz args={!r}zreturncode={!r}z stdout={!r}z stderr={!r}z{}({})z, ) Úformatr]r rr\r ÚtyperÚjoin)rr]rrrrJ¯s   zCompletedProcess.__repr__cCs |jrt|j|j|j|jƒ‚dS)z6Raise CalledProcessError if the exit code is non-zero.N)r r r]rr )rrrrÚcheck_returncode¸sz!CompletedProcess.check_returncode)NN)rrrrrrJr‹rrrrr0žs   F)rƒÚcapture_outputrr‡c Os |dk r&| d¡dk rtdƒ‚t|d<|r^| d¡dk sF| d¡dk rNtdƒ‚t|d<t|d<t||Ž¢}y|j||d\}}Wn^tk rÊ} z,| ¡tr°| ¡\| _| _ n|  ¡‚Wdd} ~ XYn| ¡‚YnX|  ¡} |r| rt | |j ||d‚WdQRXt|j | ||ƒS) aKRun command with arguments and return a CompletedProcess instance. The returned instance will have attributes args, returncode, stdout and stderr. By default, stdout and stderr are not captured, and those attributes will be None. Pass stdout=PIPE and/or stderr=PIPE in order to capture them. If check is True and the exit code was non-zero, it raises a CalledProcessError. The CalledProcessError object will have the return code in the returncode attribute, and output & stderr attributes if those streams were captured. If timeout is given, and the process takes too long, a TimeoutExpired exception will be raised. There is an optional argument "input", allowing you to pass bytes or a string to the subprocess's stdin. If you use this argument you may not also use the Popen constructor's "stdin" argument, as it will be used internally. By default, all communication is in bytes, and therefore any "input" should be bytes, and the stdout and stderr will be bytes. If in text mode, any "input" should be a string, and stdout and stderr will be strings decoded according to locale encoding, or by "encoding" if set. Text mode is triggered by setting any of text, encoding, errors or universal_newlines. The other arguments are the same as for the Popen constructor. NÚstdinz/stdin and input arguments may not both be used.rr z@stdout and stderr arguments may not be used with capture_output.)r)r r )rrr'r&Ú communicaterr}Ú _mswindowsrr r|Úpollr r]r0) rƒrŒrr‡r~rZprocessrr Úexcr‚rrrr.¿s4  cCsèg}d}xÔ|D]Ì}g}|r$| d¡d|kp8d|kp8| }|rH| d¡xj|D]b}|dkrf| |¡qN|dkr”| dt|ƒd¡g}| d¡qN|r¦| |¡g}| |¡qNW|rÂ| |¡|r| |¡| d¡qWd |¡S) a• Translate a sequence of arguments into a command line string, using the same rules as the MS C runtime: 1) Arguments are delimited by white space, which is either a space or a tab. 2) A string surrounded by double quotation marks is interpreted as a single argument, regardless of white space contained within. A quoted string can be embedded in an argument. 3) A double quotation mark preceded by a backslash is interpreted as a literal double quotation mark. 4) Backslashes are interpreted literally, unless they immediately precede a double quotation mark. 5) If backslashes immediately precede a double quotation mark, every pair of backslashes is interpreted as a literal backslash. If the number of backslashes is odd, the last backslash escapes the next double quotation mark as described in rule 3. Fú ú ú"ú\éz\"r…)r\ÚlenrwrŠ)ÚseqÚresultZ needquoterzZbs_bufÚcrrrÚ list2cmdlines4         r›c Cslyt|ddtd}d}Wn.tk rF}z|j}|j}Wdd}~XYnX|dd…dkrd|dd…}||fS)aöReturn (exitcode, output) of executing cmd in a shell. Execute the string 'cmd' in a shell with 'check_output' and return a 2-tuple (status, output). The locale encoding is used to decode the output and process newlines. A trailing newline is stripped from the output. The exit status for the command can be interpreted according to the rules for the function 'wait'. Example: >>> import subprocess >>> subprocess.getstatusoutput('ls /bin/ls') (0, '/bin/ls') >>> subprocess.getstatusoutput('cat /bin/junk') (1, 'cat: /bin/junk: No such file or directory') >>> subprocess.getstatusoutput('/bin/junk') (127, 'sh: /bin/junk: not found') >>> subprocess.getstatusoutput('/bin/kill $$') (-15, '') T)ÚshellÚtextr rNrUÚ )r-r(r r r )r ÚdataZexitcodeZexrrrr+Ms cCs t|ƒdS)a%Return output (stdout or stderr) of executing cmd in a shell. Like getstatusoutput(), except the exit status is ignored and the return value is a string containing the command's output. Example: >>> import subprocess >>> subprocess.getoutput('ls /bin/ls') '/bin/ls' rm)r+)r rrrr,ls c@s˜eZdZdZdZdGddddœd d „Zed d „ƒZejd d „ƒZdd„Z dd„Z dd„Z e j ejfdd„Zdd„Zdd„ZdHdd„Zdd„Zdd„ZdId d!„ZdJd"d#„Zerd$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„Z4d?d/„Z"d@d3„Z$dAdB„Z5dCd5„Z%dDd7„Z&dEdF„Z'dS)Kr&aâ Execute a child program in a new process. For a complete description of the arguments see the Python documentation. Arguments: args: A string, or a sequence of program arguments. bufsize: supplied as the buffering argument to the open() function when creating the stdin/stdout/stderr pipe file objects executable: A replacement program to execute. stdin, stdout and stderr: These specify the executed programs' standard input, standard output and standard error file handles, respectively. preexec_fn: (POSIX only) An object to be called in the child process just before the child is executed. close_fds: Controls closing or inheriting of file descriptors. shell: If true, the command will be executed through the shell. cwd: Sets the current directory before the child is executed. env: Defines the environment variables for the new process. text: If true, decode stdin, stdout and stderr using the given encoding (if set) or the system default otherwise. universal_newlines: Alias of text, provided for backwards compatibility. startupinfo and creationflags (Windows only) restore_signals (POSIX only) start_new_session (POSIX only) pass_fds (POSIX only) encoding and errors: Text mode encoding and error handling to use for file objects stdin, stdout and stderr. Attributes: stdin, stdout, stderr, pid, returncode FrUNTrr)ÚencodingÚerrorsrcCsZtƒ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|dkrt | ¡d ¡}|dkr4t | ¡d ¡}|dkrNt | ¡d ¡}|pb|pb|pb| |_d |_d|_yÜ|dkr²t  |d |¡|_|jr²tj!|jd|dk||d|_|dkrèt  |d|¡|_|jrètj!|j||d|_|dkrt  |d|¡|_|jrtj!|j||d|_| "|||||| | | || ||||||||¡WnxDt#d|j|j|jfƒD]*}y | $¡Wnt%k r”YnXqnW|jsNg}|t&kr¼| '|¡|t&krÐ| '|¡|t&krä| '|¡t(|dƒrü| '|j)¡xP|D]H}y*t r$t|t*ƒr$| +¡n t, $|¡Wnt%k rFYnXqW‚YnXdS)zCreate new Popen instance.NFrUzbufsize must be an integerz0preexec_fn is not supported on Windows platformszpass_fds overriding close_fds.Tz2startupinfo is only supported on Windows platformsrz4creationflags is only supported on Windows platformszlCannot disambiguate when both text and universal_newlines are supplied but different. Pass one or the other.gÐ?Úwbrm)Ú write_throughÚline_bufferingr r¡Úrb)r r¡Ú_devnull)-rMÚ threadingZLockÚ _waitpid_lockÚ_inputÚ_communication_startedÚ isinstancerGÚ TypeErrorrrÚwarningsÚwarnÚRuntimeWarningr]rrr Úpidr r r¡ÚboolrÚ _get_handlesÚmsvcrtZopen_osfhandlerHÚ text_modeÚ_sigint_wait_secsÚ_closed_child_pipe_fdsÚioÚopenÚ TextIOWrapperÚ_execute_childÚfilterÚcloseÚOSErrorr'r\Úhasattrr¦rCrFÚos)rr]ÚbufsizeÚ executablerrr Ú preexec_fnÚ close_fdsrœÚcwdÚenvr„Ú startupinfoÚ creationflagsÚrestore_signalsÚstart_new_sessionÚpass_fdsr r¡rÚp2creadÚp2cwriteÚc2preadÚc2pwriteÚerrreadÚerrwriteÚfZto_closeÚfdrrrr©s°                            zPopen.__init__cCs|jS)N)r´)rrrrr„>szPopen.universal_newlinescCst|ƒ|_dS)N)r±r´)rr„rrrr„DscCs | ||¡}| dd¡ dd¡S)Nz ržú )ÚdecodeÚreplace)rrŸr r¡rrrÚ_translate_newlinesHs zPopen._translate_newlinescCs|S)Nr)rrrrÚ __enter__LszPopen.__enter__cCsˆ|jr|j ¡|jr |j ¡z|jr2|j ¡Wd|tkrz|jdkrpy|j|jdWntk rnYnXd|_dS| ¡XdS)Nr)r) rr¼r rÚKeyboardInterruptrµÚ_waitrr|)rÚexc_typerÚ tracebackrrrÚ__exit__Os    zPopen.__exit__cCsT|js dS|jdkr(|d|jt|d|j|d|jdkrPtdk rPt |¡dS)Nzsubprocess %s is still running)Úsource)rN)Ú_child_createdr r°ÚResourceWarningrPrOr\)rZ_maxsizeZ_warnrrrrLks    z Popen.__del__cCs"t|dƒst tjtj¡|_|jS)Nr¦)r¾r¿r¸ÚdevnullÚO_RDWRr¦)rrrrÚ _get_devnullzs zPopen._get_devnullc Cs²|rZy|j |¡WnDtk r(Yn2tk rX}z|jtjkrFn‚Wdd}~XYnXy|j ¡WnDtk r|Yn2tk r¬}z|jtjkršn‚Wdd}~XYnXdS)N)rÚwriteÚBrokenPipeErrorr½ÚerrnoZEINVALr¼)rrƒr‘rrrÚ _stdin_writes"  zPopen._stdin_writec CsT|jr|rtdƒ‚|dkr”|js”|j|j|jg d¡dkr”d}d}|jrT| |¡n6|jrp|j ¡}|j ¡n|jrŠ|j ¡}|j ¡|  ¡n¸|dk r¨t ƒ|}nd}z„y|  |||¡\}}Wnht k r,|dk ròt |j| |¡ƒ}n|j}d|_y|j|dWntk r$YnX‚YnXWdd|_X|j | |¡d}||fS)a9Interact with process: Send data to stdin and close it. Read data from stdout and stderr, until end-of-file is reached. Wait for process to terminate. The optional "input" argument should be data to be sent to the child process, or None, if no data should be sent to the child. communicate() returns a tuple (stdout, stderr). By default, all communication is in bytes, and therefore any "input" should be bytes, and the (stdout, stderr) will be bytes. If in text mode (indicated by self.text_mode), any "input" should be a string, and (stdout, stderr) will be strings decoded according to locale encoding, or by "encoding" if set. Text mode is triggered by setting any of text, encoding, errors or universal_newlines. z.Cannot send input after starting communicationNr–r)rT)rªrrrr ÚcountræÚreadr¼r|Ú_timeÚ _communicaterØÚminrµÚ_remaining_timerÙr)rrƒrrr ÚendtimeÚsigint_timeoutÚstsrrrrŽ˜sD         zPopen.communicatecCs| ¡S)zSCheck if child process has terminated. Set and return returncode attribute.)rP)rrrrrÜsz Popen.pollcCs|dkr dS|tƒSdS)z5Convenience for _communicate when computing timeouts.N)ré)rrírrrrìâszPopen._remaining_timecCsL|dkr dS|stƒ|krHt|j||r0d |¡nd|r@d |¡ndd‚dS)z2Convenience for checking if a timeout has expired.Nr†)r r )rérr]rŠ)rríÚ orig_timeoutZ stdout_seqZ stderr_seqÚskip_check_and_raiserrrÚ_check_timeoutêszPopen._check_timeoutc Csˆ|dk rtƒ|}y |j|dStk r‚|dk rJt|j| |¡ƒ}n|j}d|_y|j|dWntk rzYnX‚YnXdS)z=Wait for child process to terminate; returns self.returncode.N)rr)rérÙrØrërµrìr)rrrírîrrrr|ös  z Popen.waitc Cs~|dkr|dkr|dkrdSd\}}d\}}d\}} |dkrtt tj¡}|dkrÜt dd¡\}} t|ƒ}t | ¡nh|tkr t dd¡\}}t|ƒt|ƒ}}n<|tkr¸t  |  ¡¡}n$t |t ƒrÎt  |¡}nt  |  ¡¡}| |¡}|dkr*t tj¡}|dkr˜t dd¡\} }t|ƒ}t | ¡nn|tkrXt dd¡\}}t|ƒt|ƒ}}n@|tkrrt  |  ¡¡}n&t |t ƒrŠt  |¡}nt  |  ¡¡}| |¡}|dkræt tj¡} | dkrdt dd¡\} } t| ƒ} t | ¡n~|tkrt dd¡\}} t|ƒt| ƒ}} nP|tkr$|} n@|tkr>t  |  ¡¡} n&t |t ƒrVt  |¡} nt  |  ¡¡} | | ¡} |||||| fS)z|Construct and return tuple with IO objects: p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite N)rUrUrUrUrUrU)rUrUr)rKZ GetStdHandler3Z CreatePiperCrEr'r/r³Z get_osfhandlerâr«rGÚfilenoÚ_make_inheritabler4r5r() rrrr rËrÌrÍrÎrÏrÐÚ_rrrr²sn                        zPopen._get_handlescCs&t t ¡|t ¡ddtj¡}t|ƒS)z2Return a duplicate of handle, which is inheritablerrm)rKZDuplicateHandleZGetCurrentProcessZDUPLICATE_SAME_ACCESSrC)rÚhandleÚhrrrrôZs  zPopen._make_inheritablecCstdd„|DƒƒS)z°Filter out console handles that can't be used in lpAttributeList["handle_list"] and make sure the list isn't empty. This also removes duplicate handles.cSs,h|]$}|d@dks$t |¡tjkr|’qS)é)rKZ GetFileTypeZFILE_TYPE_CHAR)Ú.0rörrrú js z,Popen._filter_handle_list..)r#)rr!rrrÚ_filter_handle_listcszPopen._filter_handle_listc CsDt|tƒst|ƒ}|dkr"tƒ}n| ¡}d| ||fk}|r^|jtjO_| |_||_ ||_ |j }t |oxd|kox|dƒ}|sˆ|rú|rú|dkrši}|_ t | dg¡ƒ}|d<|rÐ|t| ƒt|ƒt|ƒg7}| |¡|dd…<|rú|söt dt¡d}| rˆ|jtjO_tj|_|sxtj d¡}|sdtj dd¡}tj |d d ¡}tj |¡sdtd ƒ‚tj |¡r||}n|}d  ||¡}z@t ||ddt| ƒ| ||dk r¶t |¡nd|¡ \}}}}Wd| dkrÜ|   ¡|dkrî|  ¡|dkr|  ¡t!|d ƒrt "|j#¡d|_$Xd|_%t&|ƒ|_'||_(t )|¡dS)z$Execute program (MS Windows version)NrUr!z?startupinfo.lpAttributeList['handle_list'] overriding close_fdsFZComSpecZ SystemRootr…ZSystem32zcmd.exez:shell not found: neither %ComSpec% nor %SystemRoot% is setz {} /c "{}"r¦T)*r«Ústrr›rr$rrKr7rrrr r±r#rrGrûr­r®r¯r8r6rr¿ÚenvironÚpathrŠÚisabsÚFileNotFoundErrorrˆZ CreateProcessÚfspathrFr¾r¼r¦r¶rÞrCÚ_handler°rE)rr]rÁrÂrÃrÊrÄrÅrÆrÇrœrËrÌrÍrÎrÏrÐZunused_restore_signalsZunused_start_new_sessionZuse_std_handlesZattribute_listZhave_handle_listr!ZcomspecZ system_rootZhpZhtr°Útidrrrrºps|            zPopen._execute_childcCs,|jdkr&||jdƒ|kr&||jƒ|_|jS)zÎCheck if child process has terminated. Returns returncode attribute. This method is called by __del__, so it can only refer to objects in its local scope. Nr)r r)rrNZ_WaitForSingleObjectZ_WAIT_OBJECT_0Z_GetExitCodeProcessrrrrPás  zPopen._internal_pollcCs^|dkrtj}n t|dƒ}|jdkrXt |j|¡}|tjkrJt|j|ƒ‚t  |j¡|_|jS)z-Internal implementation of wait() on Windows.Niè) rKZINFINITErGr ÚWaitForSingleObjectrZ WAIT_TIMEOUTrr]ÚGetExitCodeProcess)rrZtimeout_millisr™rrrrÙòs    z Popen._waitcCs| | ¡¡| ¡dS)N)r\rèr¼)rZfhÚbufferrrrÚ _readerthreadszPopen._readerthreadcCs\|jrBt|dƒsBg|_tj|j|j|jfd|_d|j_|j ¡|j r„t|dƒs„g|_ tj|j|j |j fd|_ d|j _|j  ¡|j r”|  |¡|jdk rÆ|j | |¡¡|j ¡rÆt|j|ƒ‚|j dk rø|j  | |¡¡|j  ¡røt|j|ƒ‚d}d}|jr|j}|j ¡|j r0|j }|j  ¡|dk rB|d}|dk rT|d}||fS)NÚ _stdout_buff)Útargetr]TÚ _stderr_buffr)rr¾rr§ZThreadrZ stdout_threadZdaemonÚstartr r Z stderr_threadrrærŠrìZis_aliverr]r¼)rrƒrírðrr rrrrêsF             zPopen._communicatecCsl|jdk rdS|tjkr"| ¡nF|tjkr>t |jtj¡n*|tjkrZt |jtj¡nt d  |¡ƒ‚dS)zSend a signal to the process.NzUnsupported signal: {}) r rÚSIGTERMÚ terminateZ CTRL_C_EVENTr¿r}r°ZCTRL_BREAK_EVENTrrˆ)rÚsigrrrÚ send_signal;s     zPopen.send_signalcCsX|jdk rdSyt |jd¡Wn2tk rRt |j¡}|tjkrH‚||_YnXdS)zTerminates the process.Nrm)r rKZTerminateProcessrÚPermissionErrorrZ STILL_ACTIVE)rZrcrrrr Is   zPopen.terminatec Cs,d\}}d\}}d\}} |dkr"n@|tkr8t ¡\}}n*|tkrJ| ¡}nt|tƒrZ|}n| ¡}|dkrln@|tkr‚t ¡\}}n*|tkr”| ¡}nt|tƒr¤|}n| ¡}|dkr¶nf|tkrÌt ¡\}} nP|tkrî|dkrâ|} n t j  ¡} n.|tkr| ¡} nt|tƒr|} n| ¡} |||||| fS)z|Construct and return tuple with IO objects: p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite )rUrUNrU) r'r¿Úpiper/râr«rGrór(rQÚ __stdout__) rrrr rËrÌrÍrÎrÏrÐrrrr²^sJ        c*sÂt|ttfƒr|g}nt|ƒ}| rLttdƒr0dnd}|dg|}ˆrLˆ|d<ˆdkr\|d‰ˆ}t ¡\}}g}x |dkr| |¡t  |¡}qrWx|D]}t  |¡q˜WzÖzî|dk rg}xL|  ¡D]:\}}t  |¡}d|krêt d ƒ‚| |dt  |¡¡qÈWnd}t  ˆ¡‰tj ˆ¡r,ˆf}nt‡fd d „t |¡Dƒƒ}t|ƒ}| |¡t |||tttt|ƒƒƒ||| | | ||||||||¡|_d |_Wdt  |¡Xt|d dƒ}| dkrÞ| dkrÞ| |krÞt  | ¡|dkr| dkr||krt  |¡|dkr.|dkr.||kr.t  |¡|dk rBt  |¡d |_tƒ}x0t |d¡} || 7}| rxt|ƒdkrPPqPWWdt  |¡X|r¾y6t  |jd¡\}!}"|!|jkrÂ| !|"¡ntj"|_#Wnt$k râYnXy| %dd¡\}#}$}%|% &¡}%Wn,t k r.d}#d}$d 't|ƒ¡}%YnXtt(|# &d¡t)ƒ}&t*|&t+ƒr¶|$r¶t|$dƒ}'|%dk}(|(rvd}%|})n|})|'dkrªt ,|'¡}%|'t-j.krª|%dt/|)ƒ7}%|&|'|%|)ƒ‚|&|%ƒ‚dS)zExecute program (POSIX version)Zgetandroidapilevelz/system/bin/shz/bin/shz-crNrøó=z!illegal environment variable namec3s"|]}tj t |¡ˆ¡VqdS)N)r¿rþrŠÚfsencode)rùÚdir)rÁrrú Ïsz'Popen._execute_child..Tr¦rUiPÃó:r–sSubprocessErroró0z#Bad exception data from child: {!r}ÚasciiéZnoexecr…z: )0r«rüÚbytesr#r¾rQr¿rr\Údupr¼rqrrrþÚdirnameÚtupleÚ get_exec_pathÚsetÚaddÚ_posixsubprocessZ fork_execÚsortedÚmaprGr°rÞrrr¶Ú bytearrayrèr—ÚwaitpidÚ_handle_exitstatusrRr ÚChildProcessErrorÚsplitrÔrˆÚbuiltinsrÚ issubclassr½ÚstrerrorråZENOENTÚrepr)*rr]rÁrÂrÃrÊrÄrÅrÆrÇrœrËrÌrÍrÎrÏrÐrÈrÉZ unix_shellZorig_executableZ errpipe_readZ errpipe_writeZlow_fds_to_closeZlow_fdZenv_listÚkrbZexecutable_listZ fds_to_keepZ devnull_fdZ errpipe_dataÚpartr°rïZexception_nameZ hex_errnoZerr_msgZchild_exception_typeZ errno_numZchild_exec_never_calledZ err_filenamer)rÁrrº”s¾                                 cCsL||ƒr||ƒ |_n2||ƒr*||ƒ|_n||ƒr@||ƒ |_ntdƒ‚dS)z:All callers to this function MUST hold self._waitpid_lock.zUnknown child exit status!N)r r)rrïZ _WIFSIGNALEDZ _WTERMSIGZ _WIFEXITEDZ _WEXITSTATUSZ _WIFSTOPPEDZ _WSTOPSIGrrrr'#s zPopen._handle_exitstatusc Cs®|jdkr¨|j d¡sdSz€y8|jdk r.|jS||j|ƒ\}}||jkrR| |¡WnBtk r–}z$|dk rv||_n|j|kr†d|_Wdd}~XYnXWd|j ¡X|jS)zõCheck if child process has terminated. Returns returncode attribute. This method is called by __del__, so it cannot reference anything outside of the local scope (nor can any methods it calls). NFr)r r¨Úacquirer°r'r½råÚrelease)rrNZ_waitpidZ_WNOHANGZ_ECHILDr°rïÚerrrrP5s      cCs>yt |j|¡\}}Wntk r4|j}d}YnX||fS)z:All callers to this function MUST hold self._waitpid_lock.r)r¿r&r°r()rZ wait_flagsr°rïrrrÚ _try_waitXs  zPopen._try_waitc Cs|jdk r|jS|dk r¶tƒ|}d}xà|j d¡rxz6|jdk rBP| tj¡\}}||jkrh| |¡PWd|j  ¡X|  |¡}|dkr–t |j |ƒ‚t |d|dƒ}t |¡q(WnRxP|jdkr|j4|jdk rØP| d¡\}}||jkrú| |¡WdQRXq¸W|jS)z+Internal implementation of wait() on POSIX.Ngü©ñÒMb@?Frr–gš™™™™™©?)r rér¨r0r3r¿ÚWNOHANGr°r'r1rìrr]rëÚtimeZsleep)rrríZdelayr°rïZ remainingrrrrÙes8           c Cs,|jrX|jsXy|j ¡Wntk r.YnX|sXy|j ¡Wntk rVYnXd}d}|jsi|_|jr~g|j|j<|jrg|j|j<|jr¢|j|j}|jr´|j|j}| |¡|j rÎt |j ƒ}t ƒÆ}|jrò|rò|  |jt j¡|jr|jjs|  |jt j¡|jr6|jjs6|  |jt j¡x^| ¡r–| |¡}|dk r~|dkr~|j||||ddtdƒ‚| |¡} | ||||¡xø| D]ð\} } | j|jkr<||j|jt…} y|jt | j| ¡7_Wn,tk r| | j¡| j ¡Yn*X|jt|j ƒkrŒ| | j¡| j ¡nP| j|j|jfkržt | jd¡} | sz| | j¡| j ¡|j| j | ¡qžWq:WWdQRX|j | |¡d|dk rÈd !|¡}|dk rÜd !|¡}|j"r$|dk r| #||jj$|jj%¡}|dk r$| #||jj$|jj%¡}||fS)NrT)rñzN_check_timeout(..., skip_check_and_raise=True) failed to raise TimeoutExpired.i€)rr†)&rrªÚflushrär¼Z_fileobj2outputrr Ú _save_inputr©Ú memoryviewÚ_PopenSelectorÚregisterÚ selectorsZ EVENT_WRITErDZ EVENT_READZget_maprìròÚ RuntimeErrorÚselectZfileobjÚ _input_offsetÚ _PIPE_BUFr¿rãrÒZ unregisterr—rèr\r|rŠr´rÖr r¡)rrƒrírðrr Z input_viewZselectorrZreadyÚkeyZeventsÚchunkrŸrrrrêŽs–                (        cCsF|jrB|jdkrBd|_||_|dk rB|jrB|j |jj|jj¡|_dS)Nr)rr©r>r´Úencoder r¡)rrƒrrrr7ôs  zPopen._save_inputcCs|jdkrt |j|¡dS)zSend a signal to the process.N)r r¿r}r°)rrrrrrs cCs| tj¡dS)z/Terminate the process with SIGTERM N)rrr )rrrrr scCs| tj¡dS)z*Kill the process with SIGKILL N)rrÚSIGKILL)rrrrr} sz Popen.kill)rUNNNNNTFNNNNrTFr)NN)F)N)6rrrrrÞrrr„rrÖr×rÜrQrRr­r®rLrârærŽrrìròr|rr²rôrûrºrKrZ WAIT_OBJECT_0rrPrÙrrêrr r}r¿Ú WIFSIGNALEDÚWTERMSIGÚ WIFEXITEDÚ WEXITSTATUSÚ WIFSTOPPEDÚWSTOPSIGr'r&r4råZECHILDr3r7rrrrr&ysl-  D H  q46" )f )ErrQÚplatformrr·r¿r5rr*r­rårréÚ Exceptionrr rr§r³rKrr"r=r;rrr?r¾r%r9ZSelectSelectorÚ__all__r1r2r3r4r5r6r7r8r9r:r;r<r=r>r?r@rArBrwrGrCrOrMr'r(r/r^r{r)r*r-Úobjectr0r.r›r+r,r&rrrrÚ*sz  %     P      ;/"DI