ž ¦’fśc@sdZddlZejdkZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z yddlm ZWn"ek rÅddlmZYnXGdd„deƒZGdd „d eƒZGd d „d eƒZer[ddlZddlZddlZGd d „d ƒZGdd„dƒZnBddlZeedƒZddlZejZeeddƒZ ddddddddd dg Z!er?ddlm"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)e!j*dddd d!d"d#d$gƒGd%d&„d&e+ƒZ,nyej-d'ƒZ.Wnd(Z.YnXgZ/d)d*„Z0d;Z1d<Z2d=Z3d.d/„Z4d0d1„Z5d2dd3d„Z7d4d„Z8d2dd5d„Z9d6d7„Z:d8d„Z;d9d„Z<e=ƒZ>Gd:d„de=ƒZ?dS(>u€-subprocess - 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. This module intends to replace several older modules and functions: os.system os.spawn* Information about how the subprocess module can be used to replace these modules and functions can be found below. Using the subprocess module =========================== This module defines one class called Popen: class Popen(args, bufsize=-1, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=True, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0, restore_signals=True, start_new_session=False, pass_fds=()): Arguments are: args should be a string, or a sequence of program arguments. The program to execute is normally the first item in the args sequence or string, but can be explicitly set by using the executable argument. On POSIX, with shell=False (default): In this case, the Popen class uses os.execvp() to execute the child program. args should normally be a sequence. A string will be treated as a sequence with the string as the only item (the program to execute). On POSIX, with shell=True: If args is a string, it specifies the command string to execute through the shell. If args is a sequence, the first item specifies the command string, and any additional items will be treated as additional shell arguments. On Windows: the Popen class uses CreateProcess() to execute the child program, which operates on strings. If args is a sequence, it will be converted to a string using the list2cmdline method. Please note that not all MS Windows applications interpret the command line the same way: The list2cmdline is designed for applications using the same rules as the MS C runtime. bufsize will be supplied as the corresponding argument to the io.open() function when creating the stdin/stdout/stderr pipe file objects: 0 means unbuffered (read & write are one system call and can return short), 1 means line buffered, any other positive value means use a buffer of approximately that size. A negative bufsize, the default, means the system default of io.DEFAULT_BUFFER_SIZE will be used. stdin, stdout and stderr specify the executed programs' standard input, standard output and standard error file handles, respectively. Valid values are PIPE, an existing file descriptor (a positive integer), an existing file object, and None. PIPE indicates that a new pipe to the child should be created. With None, no redirection will occur; the child's file handles will be inherited from the parent. Additionally, stderr can be STDOUT, which indicates that the stderr data from the applications should be captured into the same file handle as for stdout. On POSIX, if preexec_fn is set to a callable object, this object will be called in the child process just before the child is executed. The use of preexec_fn is not thread safe, using it in the presence of threads could lead to a deadlock in the child process before the new executable is executed. If close_fds is true, all file descriptors except 0, 1 and 2 will be closed before the child process is executed. The default for close_fds varies by platform: Always true on POSIX. True when stdin/stdout/stderr are None on Windows, false otherwise. pass_fds is an optional sequence of file descriptors to keep open between the parent and child. Providing any pass_fds implicitly sets close_fds to true. if shell is true, the specified command will be executed through the shell. If cwd is not None, the current directory will be changed to cwd before the child is executed. On POSIX, if restore_signals is True all signals that Python sets to SIG_IGN are restored to SIG_DFL in the child process before the exec. Currently this includes the SIGPIPE, SIGXFZ and SIGXFSZ signals. This parameter does nothing on Windows. On POSIX, if start_new_session is True, the setsid() system call will be made in the child process prior to executing the command. If env is not None, it defines the environment variables for the new process. If universal_newlines is false, the file objects stdin, stdout and stderr are opened as binary files, and no line ending conversion is done. If universal_newlines is true, the file objects stdout and stderr are opened as a text files, but lines may be terminated by any of '\n', the Unix end-of-line convention, '\r', the old Macintosh convention or '\r\n', the Windows convention. All of these external representations are seen as '\n' by the Python program. Also, the newlines attribute of the file objects stdout, stdin and stderr are not updated by the communicate() method. The startupinfo and creationflags, if given, will be passed to the underlying CreateProcess() function. They can specify things such as appearance of the main window and priority for the new process. (Windows only) This module also defines some shortcut functions: call(*popenargs, **kwargs): Run command with arguments. Wait for command to complete, then return the returncode attribute. The arguments are the same as for the Popen constructor. Example: >>> retcode = subprocess.call(["ls", "-l"]) check_call(*popenargs, **kwargs): 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 Popen constructor. Example: >>> subprocess.check_call(["ls", "-l"]) 0 getstatusoutput(cmd): Return (status, output) of executing cmd in a shell. Execute the string 'cmd' in a shell with os.popen() and return a 2-tuple (status, output). cmd is actually run as '{ cmd ; } 2>&1', so that the returned output will contain output or error messages. A trailing newline is stripped from the output. The exit status for the command can be interpreted according to the rules for the C function wait(). Example: >>> subprocess.getstatusoutput('ls /bin/ls') (0, '/bin/ls') >>> subprocess.getstatusoutput('cat /bin/junk') (256, 'cat: /bin/junk: No such file or directory') >>> subprocess.getstatusoutput('/bin/junk') (256, 'sh: /bin/junk: not found') getoutput(cmd): 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: >>> subprocess.getoutput('ls /bin/ls') '/bin/ls' check_output(*popenargs, **kwargs): 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: >>> output = subprocess.check_output(["ls", "-l", "/dev/null"]) Exceptions ---------- Exceptions raised in the child process, before the new program has started to execute, will be re-raised in the parent. Additionally, the exception object will have one extra attribute called 'child_traceback', which is a string containing traceback information from the child's point of view. The most common exception raised is OSError. This occurs, for example, when trying to execute a non-existent file. Applications should prepare for OSErrors. A ValueError will be raised if Popen is called with invalid arguments. Exceptions defined within this module inherit from SubprocessError. check_call() and check_output() will raise CalledProcessError if the called process returns a non-zero return code. TimeoutExpired be raised if a timeout was specified and expired. Security -------- Unlike some other popen functions, this implementation will never call /bin/sh implicitly. This means that all characters, including shell metacharacters, can safely be passed to child processes. Popen objects ============= Instances of the Popen class have the following methods: poll() Check if child process has terminated. Returns returncode attribute. wait() Wait for child process to terminate. Returns returncode attribute. communicate(input=None) Interact 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 a string to be sent to the child process, or None, if no data should be sent to the child. communicate() returns a tuple (stdout, stderr). Note: The data read is buffered in memory, so do not use this method if the data size is large or unlimited. The following attributes are also available: stdin If the stdin argument is PIPE, this attribute is a file object that provides input to the child process. Otherwise, it is None. stdout If the stdout argument is PIPE, this attribute is a file object that provides output from the child process. Otherwise, it is None. stderr If the stderr argument is PIPE, this attribute is file object that provides error output from the child process. Otherwise, it is None. pid The process ID of the child process. returncode The child return code. A None value indicates that the process hasn't terminated yet. A negative value -N indicates that the child was terminated by signal N (POSIX only). Replacing older functions with the subprocess module ==================================================== In this section, "a ==> b" means that b can be used as a replacement for a. Note: All functions in this section fail (more or less) silently if the executed program cannot be found; this module raises an OSError exception. In the following examples, we assume that the subprocess module is imported with "from subprocess import *". Replacing /bin/sh shell backquote --------------------------------- output=`mycmd myarg` ==> output = Popen(["mycmd", "myarg"], stdout=PIPE).communicate()[0] Replacing shell pipe line ------------------------- output=`dmesg | grep hda` ==> p1 = Popen(["dmesg"], stdout=PIPE) p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE) output = p2.communicate()[0] Replacing os.system() --------------------- sts = os.system("mycmd" + " myarg") ==> p = Popen("mycmd" + " myarg", shell=True) pid, sts = os.waitpid(p.pid, 0) Note: * Calling the program through the shell is usually not required. * It's easier to look at the returncode attribute than the exitstatus. A more real-world example would look like this: try: retcode = call("mycmd" + " myarg", shell=True) if retcode < 0: print("Child was terminated by signal", -retcode, file=sys.stderr) else: print("Child returned", retcode, file=sys.stderr) except OSError as e: print("Execution failed:", e, file=sys.stderr) Replacing os.spawn* ------------------- P_NOWAIT example: pid = os.spawnlp(os.P_NOWAIT, "/bin/mycmd", "mycmd", "myarg") ==> pid = Popen(["/bin/mycmd", "myarg"]).pid P_WAIT example: retcode = os.spawnlp(os.P_WAIT, "/bin/mycmd", "mycmd", "myarg") ==> retcode = call(["/bin/mycmd", "myarg"]) Vector example: os.spawnvp(os.P_NOWAIT, path, args) ==> Popen([path] + args[1:]) Environment example: os.spawnlpe(os.P_NOWAIT, "/bin/mycmd", "mycmd", "myarg", env) ==> Popen(["/bin/mycmd", "myarg"], env={"PATH": "/usr/bin"}) iNuwin32(u monotonic(utimecBs|EeZdZdS(uSubprocessErrorN(u__name__u __module__u __qualname__(u __locals__((u//opt/alt/python33/lib64/python3.3/subprocess.pyuSubprocessErrorhsuSubprocessErrorcBs5|EeZdZdZddd„Zdd„ZdS(uCalledProcessErrorużThis exception is raised when a process run by check_call() or check_output() returns a non-zero exit status. The exit status will be stored in the returncode attribute; check_output() will also store the output in the output attribute. cCs||_||_||_dS(N(u returncodeucmduoutput(uselfu returncodeucmduoutput((u//opt/alt/python33/lib64/python3.3/subprocess.pyu__init__qs  uCalledProcessError.__init__cCsd|j|jfS(Nu-Command '%s' returned non-zero exit status %d(ucmdu returncode(uself((u//opt/alt/python33/lib64/python3.3/subprocess.pyu__str__usuCalledProcessError.__str__N(u__name__u __module__u __qualname__u__doc__uNoneu__init__u__str__(u __locals__((u//opt/alt/python33/lib64/python3.3/subprocess.pyuCalledProcessErrorksuCalledProcessErrorcBs5|EeZdZdZddd„Zdd„ZdS(uTimeoutExpiredu]This exception is raised when the timeout expires while waiting for a child process. cCs||_||_||_dS(N(ucmdutimeoutuoutput(uselfucmdutimeoutuoutput((u//opt/alt/python33/lib64/python3.3/subprocess.pyu__init__}s  uTimeoutExpired.__init__cCsd|j|jfS(Nu'Command '%s' timed out after %s seconds(ucmdutimeout(uself((u//opt/alt/python33/lib64/python3.3/subprocess.pyu__str__‚suTimeoutExpired.__str__N(u__name__u __module__u __qualname__u__doc__uNoneu__init__u__str__(u __locals__((u//opt/alt/python33/lib64/python3.3/subprocess.pyuTimeoutExpiredysuTimeoutExpiredcBs2|EeZdZdZdZdZdZdZdS(u STARTUPINFOiN( u__name__u __module__u __qualname__udwFlagsuNoneu hStdInputu hStdOutputu hStdErroru wShowWindow(u __locals__((u//opt/alt/python33/lib64/python3.3/subprocess.pyu STARTUPINFO‹s u STARTUPINFOcBs|EeZdZeZdS(u pywintypesN(u__name__u __module__u __qualname__uIOErroruerror(u __locals__((u//opt/alt/python33/lib64/python3.3/subprocess.pyu pywintypes‘su pywintypesupolluPIPE_BUFiuPopenuPIPEuSTDOUTucallu check_callugetstatusoutputu getoutputu check_outputuDEVNULL(uCREATE_NEW_CONSOLEuCREATE_NEW_PROCESS_GROUPuSTD_INPUT_HANDLEuSTD_OUTPUT_HANDLEuSTD_ERROR_HANDLEuSW_HIDEuSTARTF_USESTDHANDLESuSTARTF_USESHOWWINDOWuCREATE_NEW_CONSOLEuCREATE_NEW_PROCESS_GROUPuSTD_INPUT_HANDLEuSTD_OUTPUT_HANDLEuSTD_ERROR_HANDLEuSW_HIDEuSTARTF_USESTDHANDLESuSTARTF_USESHOWWINDOWcBsP|EeZdZdZejdd„Zdd„Zdd„Z eZ e Z dS( uHandlecCs#|jsd|_||ƒndS(NT(ucloseduTrue(uselfu CloseHandle((u//opt/alt/python33/lib64/python3.3/subprocess.pyuClose°s  u Handle.ClosecCs,|jsd|_t|ƒStdƒ‚dS(Nualready closedT(ucloseduTrueuintu ValueError(uself((u//opt/alt/python33/lib64/python3.3/subprocess.pyuDetachµs   u Handle.DetachcCsdt|ƒS(Nu Handle(%d)(uint(uself((u//opt/alt/python33/lib64/python3.3/subprocess.pyu__repr__»suHandle.__repr__NF( u__name__u __module__u __qualname__uFalseuclosedu_winapiu CloseHandleuCloseuDetachu__repr__u__del__u__str__(u __locals__((u//opt/alt/python33/lib64/python3.3/subprocess.pyuHandle­s   uHandleu SC_OPEN_MAXic Csixbtdd…D]P}|jdtjƒ}|dk rytj|ƒWqatk r]YqaXqqWdS(Nu _deadstate(u_activeu_internal_pollusysumaxsizeuNoneuremoveu ValueError(uinstures((u//opt/alt/python33/lib64/python3.3/subprocess.pyu_cleanupĢs  u_cleanupiiic Gs0x)y||ŒSWqtk r(wYqXqdS(N(uInterruptedError(ufuncuargs((u//opt/alt/python33/lib64/python3.3/subprocess.pyu_eintr_retry_callÜs  u_eintr_retry_callcCsĪi dd6dd6dd6dd6d d 6d d 6d d6dd6dd6dd6}g}xP|jƒD]B\}}ttj|ƒ}|dkr_|jd||ƒq_q_Wx"tjD]}|jd|ƒqÆW|S(unReturn a list of command-line arguments reproducing the current settings in sys.flags and sys.warnoptions.ududebuguOuoptimizeuBudont_write_bytecodeusu no_user_siteuSuno_siteuEuignore_environmentuvuverboseubu bytes_warninguququietuRuhash_randomizationiu-u-W(uitemsugetattrusysuflagsuappendu warnoptions(u flag_opt_mapuargsuflaguoptuv((u//opt/alt/python33/lib64/python3.3/subprocess.pyu_args_from_interpreter_flagsčs&  u_args_from_interpreter_flagsutimeoutcOsRt||Ž=}y|jd|ƒSWn|jƒ|jƒ‚YnXWdQXdS(uŽ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"]) utimeoutN(uPopenuwaitukill(utimeoutu popenargsukwargsup((u//opt/alt/python33/lib64/python3.3/subprocess.pyucalls  cOsSt||Ž}|rO|jdƒ}|dkr=|d}nt||ƒ‚ndS(uORun 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"]) uargsiN(ucallugetuNoneuCalledProcessError(u popenargsukwargsuretcodeucmd((u//opt/alt/python33/lib64/python3.3/subprocess.pyu check_calls   cOsķd|krtdƒ‚ntdt||Ž·}y|jd|ƒ\}}Wndtk r—|jƒ|jƒ\}}t|j|d|ƒ‚Yn|jƒ|jƒ‚YnX|jƒ}|rćt ||jd|ƒ‚nWdQX|S(uVRun 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' If universal_newlines=True is passed, the return value will be a string rather than bytes. ustdoutu3stdout argument not allowed, it will be overridden.utimeoutuoutputN( u ValueErroruPopenuPIPEu communicateuTimeoutExpiredukilluargsuwaitupolluCalledProcessError(utimeoutu popenargsukwargsuprocessuoutputu unused_erruretcode((u//opt/alt/python33/lib64/python3.3/subprocess.pyu check_output's"      !cCsGg}d}x+|D]#}g}|r5|jdƒnd|kpQd|kpQ| }|rj|jdƒnx|D]ˆ}|dkr“|j|ƒqq|dkrŠ|jdt|ƒdƒg}|jdƒqq|rģ|j|ƒg}n|j|ƒqqW|r|j|ƒn|r|j|ƒ|jdƒqqWdj|ƒS( u• 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. u u u"u\iu\"uF(uFalseuappendulenuextendujoin(usequresultu needquoteuargubs_bufuc((u//opt/alt/python33/lib64/python3.3/subprocess.pyu list2cmdlineQs4       u list2cmdlinecCs•y(t|dddddtƒ}d}Wn7tk ra}z|j}|j}WYdd}~XnX|d d…dkr‹|dd …}n||fS( u×Return (status, output) of executing cmd in a shell. Execute the string 'cmd' in a shell with os.popen() and return a 2-tuple (status, output). cmd is actually run as '{ cmd ; } 2>&1', so that the returned output will contain output or error messages. A trailing newline is stripped from the output. The exit status for the command can be interpreted according to the rules for the C function wait(). Example: >>> import subprocess >>> subprocess.getstatusoutput('ls /bin/ls') (0, '/bin/ls') >>> subprocess.getstatusoutput('cat /bin/junk') (256, 'cat: /bin/junk: No such file or directory') >>> subprocess.getstatusoutput('/bin/junk') (256, 'sh: /bin/junk: not found') ushelluuniversal_newlinesustderriNiu Ti’’’’i’’’’(u check_outputuTrueuSTDOUTuCalledProcessErroruoutputu returncode(ucmdudataustatusuex((u//opt/alt/python33/lib64/python3.3/subprocess.pyugetstatusoutputšs  cCst|ƒdS(u%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' i(ugetstatusoutput(ucmd((u//opt/alt/python33/lib64/python3.3/subprocess.pyu getoutputµs cBsQ|EeZdZdAZdBd@d@d@d@d@edAd@d@dAd@ddCdAfdd„Zdd„Z dd„Z d d „Z e j d d „Zd d„Zd@d@dd„Zdd„Zdd„Zdd„Zerldd„Zdd„Zdd„Zdd„Zd@ejejejdd „Zd@d@d!d"„Zd#d$„Zd%d&„Z d'd(„Z!d)d*„Z"e"Z#nįd+d„Zd,d-„Z$d.d„Ze%j&e%j'e%j(e%j)d/d0„Z*d@e%j+e%j,e%j-e.j/d1d „Zd2d3„Z0d@d@d4d"„Zd5d&„Z d6d7„Z1d8d9„Z2d:d;„Z3d<d(„Z!d=d*„Z"d>d?„Z#d@S(DuPopeniicCsjtƒd |_d|_|d kr.d}nt|tƒsLtdƒ‚ntrÓ|d k rmt dƒ‚n|d k pŽ|d k pŽ|d k }|t krµ|r¬d}qŠd}qD|rD|rDt dƒ‚qDnq|t krčd}n|r| rt j dtƒd}n| d k r)t dƒ‚n|dkrDt dƒ‚n||_d |_d |_d |_d |_d |_| |_|j|||ƒ\}}}}}}tr(|dkr×tj|jƒdƒ}n|dkržtj|jƒdƒ}n|dkr(tj|jƒdƒ}q(n|dkrstj|d |ƒ|_| rstj|jd dƒ|_qsn|dkrøtj|d |ƒ|_| røtj|jƒ|_qøn|dkrżtj|d |ƒ|_| rżtj|jƒ|_qżnd|_yD|j|||||| | | || ||||||||ƒWnxLtd |j|j|jfƒD])}y|j ƒWqrt!k ršYqrXqrW|js^g}|t"krŹ|j#|ƒn|t"krę|j#|ƒn|t"kr|j#|ƒnt$|d ƒr$|j#|j%ƒnx7|D],}yt&j |ƒWq+t!k rVYq+Xq+Wn‚YnXd S(uCreate new Popen instance.iubufsize must be an integeru0preexec_fn is not supported on Windows platformsuSclose_fds is not supported on Windows platforms if you redirect stdin/stdout/stderrupass_fds overriding close_fds.u2startupinfo is only supported on Windows platformsiu4creationflags is only supported on Windows platformsuwbu write_throughurbu_devnullNFi’’’’Ti’’’’i’’’’i’’’’i’’’’i’’’’i’’’’('u_cleanupuNoneu_inputuFalseu_communication_startedu isinstanceuintu TypeErroru mswindowsu ValueErroru_PLATFORM_DEFAULT_CLOSE_FDSuTrueuwarningsuwarnuRuntimeWarninguargsustdinustdoutustderrupidu returncodeuuniversal_newlinesu _get_handlesumsvcrtuopen_osfhandleuDetachuiouopenu TextIOWrapperu_closed_child_pipe_fdsu_execute_childufilterucloseuEnvironmentErroruPIPEuappenduhasattru_devnulluos(uselfuargsubufsizeu executableustdinustdoutustderru preexec_fnu close_fdsushellucwduenvuuniversal_newlinesu startupinfou creationflagsurestore_signalsustart_new_sessionupass_fdsu any_stdio_setup2creadup2cwriteuc2preaduc2pwriteuerrreaduerrwriteufuto_closeufd((u//opt/alt/python33/lib64/python3.3/subprocess.pyu__init__És¬                       '    !     (         uPopen.__init__cCs+|j|ƒ}|jddƒjddƒS(Nu u u (udecodeureplace(uselfudatauencoding((u//opt/alt/python33/lib64/python3.3/subprocess.pyu_translate_newlinesOsuPopen._translate_newlinescCs|S(N((uself((u//opt/alt/python33/lib64/python3.3/subprocess.pyu __enter__SsuPopen.__enter__cCsY|jr|jjƒn|jr2|jjƒn|jrK|jjƒn|jƒdS(N(ustdoutucloseustderrustdinuwait(uselfutypeuvalueu traceback((u//opt/alt/python33/lib64/python3.3/subprocess.pyu__exit__Vs   uPopen.__exit__cCsL|js dS|jd|ƒ|jdkrHtdk rHtj|ƒndS(Nu _deadstate(u_child_createdu_internal_pollu returncodeuNoneu_activeuappend(uselfu_maxsize((u//opt/alt/python33/lib64/python3.3/subprocess.pyu__del__`s  u Popen.__del__cCs4t|dƒs-tjtjtjƒ|_n|jS(Nu_devnull(uhasattruosuopenudevnulluO_RDWRu_devnull(uself((u//opt/alt/python33/lib64/python3.3/subprocess.pyu _get_devnulljsuPopen._get_devnullcCsÅ|jr|rtdƒ‚n|dkrR|j rR|j|j|jgjdƒdkrRd}d}|jrļ|rßy|jj|ƒWqßtk rŪ}z/|j t j krÉ|j t j krɂnWYdd}~XqßXn|jj ƒnV|jrt |jjƒ}|jj ƒn+|jrEt |jjƒ}|jj ƒn|jƒni|dk rntƒ|}nd}z|j|||ƒ\}}Wdd|_X|jd|j|ƒƒ}||fS(ucInteract 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 bytes to be sent to the child process, or None, if no data should be sent to the child. communicate() returns a tuple (stdout, stderr).u.Cannot send input after starting communicationiNutimeoutT(u_communication_startedu ValueErroruNoneustdinustdoutustderrucountuwriteuIOErroruerrnouEPIPEuEINVALucloseu_eintr_retry_callureaduwaitu_timeu _communicateuTrueu_remaining_time(uselfuinpututimeoutustdoutustderrueuendtimeusts((u//opt/alt/python33/lib64/python3.3/subprocess.pyu communicateos: ' $     uPopen.communicatecCs |jƒS(N(u_internal_poll(uself((u//opt/alt/python33/lib64/python3.3/subprocess.pyupoll”su Popen.pollcCs|dkrdS|tƒSdS(u5Convenience for _communicate when computing timeouts.N(uNoneu_time(uselfuendtime((u//opt/alt/python33/lib64/python3.3/subprocess.pyu_remaining_time„s uPopen._remaining_timecCs8|dkrdStƒ|kr4t|j|ƒ‚ndS(u2Convenience for checking if a timeout has expired.N(uNoneu_timeuTimeoutExpireduargs(uselfuendtimeu orig_timeout((u//opt/alt/python33/lib64/python3.3/subprocess.pyu_check_timeout­s uPopen._check_timeoutc Cs•|dkr(|dkr(|dkr(d Sd \}}d\}}d\}} |dkr­tjtjƒ}|dkrGtjddƒ\}} t|ƒ}tj| ƒqGnš|tkrķtjddƒ\}}t|ƒt|ƒ}}nZ|tkrt j |j ƒƒ}n6t |t ƒr2t j |ƒ}nt j |jƒƒ}|j|ƒ}|dkr·tjtjƒ}|dkrQtjddƒ\} }t|ƒ}tj| ƒqQnš|tkr÷tjddƒ\}}t|ƒt|ƒ}}nZ|tkrt j |j ƒƒ}n6t |t ƒr<t j |ƒ}nt j |jƒƒ}|j|ƒ}|dkrĮtjtjƒ} | dkrptjddƒ\} } t| ƒ} tj| ƒqpnÆ|tkrtjddƒ\}} t|ƒt| ƒ}} no|tkr|} nZ|tkr:t j |j ƒƒ} n6t |t ƒr[t j |ƒ} nt j |jƒƒ} |j| ƒ} |||||| fS(u|Construct and return tuple with IO objects: p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite iiNi’’’’i’’’’i’’’’i’’’’i’’’’i’’’’(i’’’’i’’’’i’’’’i’’’’i’’’’i’’’’i’’’’i’’’’(i’’’’i’’’’i’’’’i’’’’(i’’’’i’’’’i’’’’i’’’’(i’’’’i’’’’(uNoneu_winapiu GetStdHandleuSTD_INPUT_HANDLEu CreatePipeuHandleu CloseHandleuPIPEuDEVNULLumsvcrtu get_osfhandleu _get_devnullu isinstanceuintufilenou_make_inheritableuSTD_OUTPUT_HANDLEuSTD_ERROR_HANDLEuSTDOUT( uselfustdinustdoutustderrup2creadup2cwriteuc2preaduc2pwriteuerrreaduerrwriteu_((u//opt/alt/python33/lib64/python3.3/subprocess.pyu _get_handles¹sn$                    uPopen._get_handlescCs7tjtjƒ|tjƒddtjƒ}t|ƒS(u2Return a duplicate of handle, which is inheritableii(u_winapiuDuplicateHandleuGetCurrentProcessuDUPLICATE_SAME_ACCESSuHandle(uselfuhandleuh((u//opt/alt/python33/lib64/python3.3/subprocess.pyu_make_inheritables   uPopen._make_inheritablecCsˆtjjtjjtjdƒƒdƒ}tjj|ƒs„tjjtjjtjƒdƒ}tjj|ƒs„t dƒ‚q„n|S(u,Find and return absolut path to w9xpopen.exeiu w9xpopen.exeuZCannot locate w9xpopen.exe, which is needed for Popen to work with your shell or platform.( uosupathujoinudirnameu_winapiuGetModuleFileNameuexistsusysubase_exec_prefixu RuntimeError(uselfuw9xpopen((u//opt/alt/python33/lib64/python3.3/subprocess.pyu_find_w9xpopen s   uPopen._find_w9xpopencCsDt|tƒst|ƒ}n|dkr6tƒ}nd | ||fkr{|jtjO_| |_||_ ||_ n| r%|jtj O_tj |_ tjjddƒ}dj||ƒ}tjƒdksötjj|ƒjƒdkr%|jƒ}d||f}| tjO} q%nz|y>tj||ddt| ƒ| |||ƒ \}}}}Wn7tjk rŸ}zt|jŒ‚WYdd}~XnXWd| d kr½| jƒn|d krÖ|jƒn|d krļ|jƒnt|d ƒrtj |j!ƒnXd|_#t$|ƒ|_%||_&tj'|ƒdS(u$Execute program (MS Windows version)iuCOMSPECucmd.exeu {} /c "{}"lu command.comu"%s" %sNu_devnulli’’’’i’’’’i’’’’i’’’’T((u isinstanceustru list2cmdlineuNoneu STARTUPINFOudwFlagsu_winapiuSTARTF_USESTDHANDLESu hStdInputu hStdOutputu hStdErroruSTARTF_USESHOWWINDOWuSW_HIDEu wShowWindowuosuenvironugetuformatu GetVersionupathubasenameuloweru_find_w9xpopenuCREATE_NEW_CONSOLEu CreateProcessuintu pywintypesuerroru WindowsErroruargsuCloseuhasattrucloseu_devnulluTrueu_child_createduHandleu_handleupidu CloseHandle(uselfuargsu executableu preexec_fnu close_fdsupass_fdsucwduenvu startupinfou creationflagsushellup2creadup2cwriteuc2preaduc2pwriteuerrreaduerrwriteuunused_restore_signalsuunused_start_new_sessionucomspecuw9xpopenuhpuhtupidutidue((u//opt/alt/python33/lib64/python3.3/subprocess.pyu_execute_childsR          &        uPopen._execute_childcCsF|jdkr?||jdƒ|kr?||jƒ|_q?n|jS(uĪ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. iN(u returncodeuNoneu_handle(uselfu _deadstateu_WaitForSingleObjectu_WAIT_OBJECT_0u_GetExitCodeProcess((u//opt/alt/python33/lib64/python3.3/subprocess.pyu_internal_pollms uPopen._internal_pollcCs­|dk r|j|ƒ}n|dkr6tj}nt|dƒ}|jdkr¦tj|j|ƒ}|tjkrŽt |j |ƒ‚ntj |jƒ|_n|jS(uOWait for child process to terminate. Returns returncode attribute.ičN( uNoneu_remaining_timeu_winapiuINFINITEuintu returncodeuWaitForSingleObjectu_handleu WAIT_TIMEOUTuTimeoutExpireduargsuGetExitCodeProcess(uselfutimeoutuendtimeutimeout_millisuresult((u//opt/alt/python33/lib64/python3.3/subprocess.pyuwait~s     u Popen.waitcCs!|j|jƒƒ|jƒdS(N(uappendureaduclose(uselfufhubuffer((u//opt/alt/python33/lib64/python3.3/subprocess.pyu _readerthreadsuPopen._readerthreadcCs|jrht|dƒ rhg|_tjd|jd|j|jfƒ|_d|j_|jj ƒn|j rŠt|dƒ rŠg|_ tjd|jd|j |j fƒ|_ d|j _|j j ƒn|j rs|dk rcy|j j|ƒWqctk r_}zD|jtjkr#n*|jtjkrJ|jƒdk rJn‚WYdd}~XqcXn|j jƒn|jdk rĀ|jj|j|ƒƒ|jjƒrĀt|j|ƒ‚qĀn|j dk r|j j|j|ƒƒ|j jƒrt|j|ƒ‚qnd}d}|jr?|j}|jjƒn|j ra|j }|j jƒn|dk rz|d}n|dk r“|d}n||fS(Nu _stdout_buffutargetuargsu _stderr_buffiT(ustdoutuhasattru _stdout_buffu threadinguThreadu _readerthreadu stdout_threaduTrueudaemonustartustderru _stderr_buffu stderr_threadustdinuNoneuwriteuIOErroruerrnouEPIPEuEINVALupollucloseujoinu_remaining_timeuis_aliveuTimeoutExpireduargs(uselfuinputuendtimeu orig_timeoutueustdoutustderr((u//opt/alt/python33/lib64/python3.3/subprocess.pyu _communicate•sZ              uPopen._communicatecCs…|tjkr|jƒne|tjkrDtj|jtjƒn=|tjkrltj|jtjƒntdj |ƒƒ‚dS(u)Send a signal to the process uUnsupported signal: {}N( usignaluSIGTERMu terminateu CTRL_C_EVENTuosukillupiduCTRL_BREAK_EVENTu ValueErroruformat(uselfusig((u//opt/alt/python33/lib64/python3.3/subprocess.pyu send_signal×s uPopen.send_signalc Cs`ytj|jdƒWnBtk r[tj|jƒ}|tjkrN‚n||_YnXdS(u#Terminates the process iN(u_winapiuTerminateProcessu_handleuPermissionErroruGetExitCodeProcessu STILL_ACTIVEu returncode(uselfurc((u//opt/alt/python33/lib64/python3.3/subprocess.pyu terminatećs uPopen.terminatec Cs“d\}}d\}}d \}} |d kr3n]|tkrQtƒ\}}n?|tkrl|jƒ}n$t|tƒr„|}n |jƒ}|d krŸn]|tkr½tƒ\}}n?|tkrŲ|jƒ}n$t|tƒrš|}n |jƒ}|d kr nr|tkr)tƒ\}} nT|tkr>|} n?|tkrY|jƒ} n$t|tƒrq|} n |jƒ} |||||| fS( u|Construct and return tuple with IO objects: p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite ii’’’’i’’’’(i’’’’i’’’’i’’’’i’’’’(i’’’’i’’’’i’’’’i’’’’(i’’’’i’’’’N( uNoneuPIPEu _create_pipeuDEVNULLu _get_devnullu isinstanceuintufilenouSTDOUT( uselfustdinustdoutustderrup2creadup2cwriteuc2preaduc2pwriteuerrreaduerrwrite((u//opt/alt/python33/lib64/python3.3/subprocess.pyu _get_handlesösF                    cCsid}x=t|ƒD]/}||krtj||ƒ|d}qqW|tkretj|tƒndS(Nii(usorteduosu closerangeuMAXFD(uselfu fds_to_keepustart_fdufd((u//opt/alt/python33/lib64/python3.3/subprocess.pyu _close_fds)s  uPopen._close_fdsc%/s°t|ttfƒr!|g}n t|ƒ}| rYddg|}ˆrYˆ|ddsu'Popen._execute_child..Nu_devnulliiPĆs:is RuntimeErrors0sBad exception data from child: uasciiuerrorsu surrogatepassiunoexecuu: Ti’’’’i’’’’i’’’’i’’’’i’’’’i’’’’(+u isinstanceustrubytesulistuNoneu _create_pipeuitemsuosufsencodeu ValueErroruappendupathudirnameutupleu get_exec_pathusetuaddu_posixsubprocessu fork_execusortedupiduTrueu_child_createducloseugetattru_closed_child_pipe_fdsu bytearrayu_eintr_retry_callureadulenuwaitpiduOSErroruerrnouECHILDusplitureprubuiltinsudecodeu RuntimeErroru issubclassuintustrerroruENOENT(%uselfuargsu executableu preexec_fnu close_fdsupass_fdsucwduenvu startupinfou creationflagsushellup2creadup2cwriteuc2preaduc2pwriteuerrreaduerrwriteurestore_signalsustart_new_sessionuorig_executableu errpipe_readu errpipe_writeuenv_listukuvuexecutable_listu fds_to_keepu devnull_fdu errpipe_dataupartueuexception_nameu hex_errnouerr_msguchild_exception_typeu errno_numuchild_exec_never_called((u executableu//opt/alt/python33/lib64/python3.3/subprocess.pyu_execute_child3sŖ       %     $$$          cCsM||ƒr||ƒ |_n*||ƒr=||ƒ|_n tdƒ‚dS(NuUnknown child exit status!(u returncodeu RuntimeError(uselfustsu _WIFSIGNALEDu _WTERMSIGu _WIFEXITEDu _WEXITSTATUS((u//opt/alt/python33/lib64/python3.3/subprocess.pyu_handle_exitstatus°s   uPopen._handle_exitstatusc CsÆ|jdkrØy;||j|ƒ\}}||jkrI|j|ƒnWqØ|k r¤}z8|dk rw||_n|j|kr’d|_nWYdd}~XqØXn|jS(uõ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). iN(u returncodeuNoneupidu_handle_exitstatusuerrno( uselfu _deadstateu_waitpidu_WNOHANGu _os_erroru_ECHILDupidustsue((u//opt/alt/python33/lib64/python3.3/subprocess.pyu_internal_poll¾s   "cCs{y"ttj|j|ƒ\}}WnLtk rp}z,|jtjkrO‚n|j}d}WYdd}~XnX||fS(Ni(u_eintr_retry_calluosuwaitpidupiduOSErroruerrnouECHILD(uselfu wait_flagsupidustsue((u//opt/alt/python33/lib64/python3.3/subprocess.pyu _try_waitŁs" uPopen._try_waitcCsb|jdk r|jS|dk s.|dk rk|dkrJtƒ|}qk|dkrk|j|ƒ}qkn|dk rd}xŪ|jtjƒ\}}||jkrø|j|ƒPn|j|ƒ}|dkrčt |j |ƒ‚nt |d|dƒ}t j |ƒq€nJxG|jdkrZ|jdƒ\}}||jkr|j|ƒqqW|jS(uOWait for child process to terminate. Returns returncode attribute.gü©ńŅMb@?iigš™™™™™©?N(u returncodeuNoneu_timeu_remaining_timeu _try_waituosuWNOHANGupidu_handle_exitstatusuTimeoutExpireduargsuminutimeusleep(uselfutimeoutuendtimeudelayupidustsu remaining((u//opt/alt/python33/lib64/python3.3/subprocess.pyuwaitēs0     cCs1|jr9|j r9|jjƒ|s9|jjƒq9ntr]|j|||ƒ\}}n|j|||ƒ\}}|jd|j|ƒƒ|dk rÆdj |ƒ}n|dk rĶdj |ƒ}n|j r'|dk rż|j ||j jƒ}n|dk r'|j ||jjƒ}q'n||fS(Nutimeouts(ustdinu_communication_starteduflushucloseu _has_pollu_communicate_with_pollu_communicate_with_selectuwaitu_remaining_timeuNoneujoinuuniversal_newlinesu_translate_newlinesustdoutuencodingustderr(uselfuinputuendtimeu orig_timeoutustdoutustderr((u//opt/alt/python33/lib64/python3.3/subprocess.pyu _communicates,          cCsd|jr`|jdkr`d|_||_|jr`|dk r`|jj|jjƒ|_q`ndS(Ni(ustdinu_inputuNoneu _input_offsetuuniversal_newlinesuencodeuencoding(uselfuinput((u//opt/alt/python33/lib64/python3.3/subprocess.pyu _save_input2s   uPopen._save_inputc!sSd}d}ˆjs!iˆ_ntjƒ‰‡‡fdd†}‡‡fdd†}ˆjr||r||ˆjtjƒnˆjsÕiˆ_ˆjr°gˆjˆjj ƒ.register_and_appendcs2ˆj|ƒˆj|jƒˆjj|ƒdS(N(u unregisteru_fd2fileucloseupop(ufd(upolleruself(u//opt/alt/python33/lib64/python3.3/subprocess.pyuclose_unregister_and_removeIs uAPopen._communicate_with_poll..close_unregister_and_removeii€( uNoneu_communication_startedu_fd2fileuselectupollustdinuPOLLOUTu _fd2outputustdoutufilenoustderruPOLLINuPOLLPRIu _save_inputu_inputu memoryviewu_remaining_timeuTimeoutExpireduargsuerroruerrnouEINTRu_check_timeoutu _input_offsetu _PIPE_BUFuosuwriteuOSErroruEPIPEulenureaduappend(uselfuinputuendtimeu orig_timeoutustdoutustderruregister_and_appenduclose_unregister_and_removeuselect_POLLIN_POLLPRIu input_viewutimeoutureadyueufdumodeuchunkudata((upolleruselfu//opt/alt/python33/lib64/python3.3/subprocess.pyu_communicate_with_poll=sn                 uPopen._communicate_with_pollc$Cs·|jsg|_g|_|jr@|r@|jj|jƒn|jr_|jj|jƒn|jr|jj|jƒqn|j|ƒd}d}|jrÄ|jsøg|_ n|j }n|jrī|jsāg|_ n|j }nx¼|js|jr¬|j |ƒ}|dk r?|dkr?t |j |ƒ‚ny+tj|j|jg|ƒ\}}} WnGtjk r³} z$| j dtjkržwńn‚WYdd} ~ XnX|pĆ|pĆ| sŪt |j |ƒ‚n|j||ƒ|j|krć|j|j|jt…} ytj|jjƒ| ƒ} Wn]tk r•} z=| jtjkr€|jjƒ|jj|jƒn‚WYdd} ~ XqćX|j| 7_|jt|jƒkrć|jjƒ|jj|jƒqćn|j|krFtj|jjƒdƒ} | s6|jjƒ|jj|jƒn|j| ƒn|j|krńtj|jjƒdƒ} | s™|jjƒ|jj|jƒn|j| ƒqńqńW||fS(Nii(u_communication_startedu _read_setu _write_setustdinuappendustdoutustderru _save_inputuNoneu _stdout_buffu _stderr_buffu_remaining_timeuTimeoutExpireduargsuselectuerroruerrnouEINTRu_check_timeoutu_inputu _input_offsetu _PIPE_BUFuosuwriteufilenouOSErroruEPIPEucloseuremoveulenuread(uselfuinputuendtimeu orig_timeoutustdoutustderrutimeouturlistuwlistuxlistueuchunku bytes_writtenudata((u//opt/alt/python33/lib64/python3.3/subprocess.pyu_communicate_with_selectsz                   uPopen._communicate_with_selectcCstj|j|ƒdS(u)Send a signal to the process N(uosukillupid(uselfusig((u//opt/alt/python33/lib64/python3.3/subprocess.pyu send_signalįscCs|jtjƒdS(u/Terminate the process with SIGTERM N(u send_signalusignaluSIGTERM(uself((u//opt/alt/python33/lib64/python3.3/subprocess.pyu terminateęscCs|jtjƒdS(u*Kill the process with SIGKILL N(u send_signalusignaluSIGKILL(uself((u//opt/alt/python33/lib64/python3.3/subprocess.pyukillėsu Popen.killNFi’’’’T(4u__name__u __module__u __qualname__uFalseu_child_createduNoneu_PLATFORM_DEFAULT_CLOSE_FDSuTrueu__init__u_translate_newlinesu __enter__u__exit__usysumaxsizeu__del__u _get_devnullu communicateupollu_remaining_timeu_check_timeoutu mswindowsu _get_handlesu_make_inheritableu_find_w9xpopenu_execute_childu_winapiuWaitForSingleObjectu WAIT_OBJECT_0uGetExitCodeProcessu_internal_polluwaitu _readerthreadu _communicateu send_signalu terminateukillu _close_fdsuosu WIFSIGNALEDuWTERMSIGu WIFEXITEDu WEXITSTATUSu_handle_exitstatusuwaitpiduWNOHANGuerroruerrnouECHILDu _try_waitu _save_inputu_communicate_with_pollu_communicate_with_select(u __locals__((u//opt/alt/python33/lib64/python3.3/subprocess.pyuPopenÅsb  €    2    H  R  B  3 }   ' $ R R  i’’’’iž’’’iż’’’(@u__doc__usysuplatformu mswindowsuiouosutimeu tracebackugcusignalubuiltinsuwarningsuerrnou monotonicu_timeu ImportErroru ExceptionuSubprocessErroruCalledProcessErroruTimeoutExpiredu threadingumsvcrtu_winapiu STARTUPINFOu pywintypesuselectuhasattru _has_pollu_posixsubprocessu cloexec_pipeu _create_pipeugetattru _PIPE_BUFu__all__uCREATE_NEW_CONSOLEuCREATE_NEW_PROCESS_GROUPuSTD_INPUT_HANDLEuSTD_OUTPUT_HANDLEuSTD_ERROR_HANDLEuSW_HIDEuSTARTF_USESTDHANDLESuSTARTF_USESHOWWINDOWuextenduintuHandleusysconfuMAXFDu_activeu_cleanupuPIPEuSTDOUTuDEVNULLu_eintr_retry_callu_args_from_interpreter_flagsuNoneucallu check_callu check_outputu list2cmdlineugetstatusoutputu getoutputuobjectu_PLATFORM_DEFAULT_CLOSE_FDSuPopen(((u//opt/alt/python33/lib64/python3.3/subprocess.pyuTsr                 :      * I