ó zfc @sŠdZddlZejdkZddlZddlZddlZddlZddlZddl Z de fd„ƒYZ erÒddl Z ddl Z ddlZdfd„ƒYZdfd „ƒYZnoddlZeed ƒZyddl Z Wnek reZ nXddlZddlZeed d ƒZd ddddddgZerÄddlmZmZmZmZmZm Z m!Z!m"Z"ej#ddddddddgƒnyej$dƒZ%Wn dZ%nXgZ&d„Z'dZ(dZ)d „Z*d!„Z+d"„Z,d#„Z-d$„Z.d%„Z/d e0fd&„ƒYZ1d'„Z2d(„Z3e4d)kr†er|e3ƒne2ƒndS(*sö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 ======== 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 Popen(...): A class for flexibly executing a command in a new process Constants --------- PIPE: Special value that indicates a pipe should be created STDOUT: Special value that indicates that stderr should go to stdout iÿÿÿÿNtwin32tCalledProcessErrorcBs#eZdZdd„Zd„ZRS(s¥This exception is raised when a process run by check_call() or check_output() returns a non-zero exit status. Attributes: cmd, returncode, output cCs||_||_||_dS(N(t returncodetcmdtoutput(tselfRRR((s"/usr/lib64/python2.7/subprocess.pyt__init__3s  cCsd|j|jfS(Ns-Command '%s' returned non-zero exit status %d(RR(R((s"/usr/lib64/python2.7/subprocess.pyt__str__7sN(t__name__t __module__t__doc__tNoneRR(((s"/usr/lib64/python2.7/subprocess.pyR,s t STARTUPINFOcBs&eZdZdZdZdZdZRS(iN(RR tdwFlagsR t hStdInputt hStdOutputt hStdErrort wShowWindow(((s"/usr/lib64/python2.7/subprocess.pyR ?s t pywintypescBseZeZRS((RR tIOErrorterror(((s"/usr/lib64/python2.7/subprocess.pyREstpolltPIPE_BUFitPopentPIPEtSTDOUTtcallt check_callt check_output(tCREATE_NEW_CONSOLEtCREATE_NEW_PROCESS_GROUPtSTD_INPUT_HANDLEtSTD_OUTPUT_HANDLEtSTD_ERROR_HANDLEtSW_HIDEtSTARTF_USESTDHANDLEStSTARTF_USESHOWWINDOWRRRR R!R"R#R$t SC_OPEN_MAXicCs_xXtD]O}|jdtjƒ}|dk rytj|ƒWqWtk rSqWXqqWdS(Nt _deadstate(t_activet_internal_polltsystmaxintR tremovet ValueError(tinsttres((s"/usr/lib64/python2.7/subprocess.pyt_cleanupks  iþÿÿÿcGsVxOtrQy||ŒSWqttfk rM}|jtjkrGqn‚qXqWdS(N(tTruetOSErrorRterrnotEINTR(tfunctargste((s"/usr/lib64/python2.7/subprocess.pyt_eintr_retry_callzs cCsïi dd6dd6dd6dd6d d 6d d 6d d6dd6dd6}g}xP|jƒD]B\}}ttj|ƒ}|dkrX|jd||ƒqXqXWttjdƒdkrÆ|jdƒnx"tjD]}|jd|ƒqÐW|S(snReturn a list of command-line arguments reproducing the current settings in sys.flags and sys.warnoptions.tdtdebugtOtoptimizetBtdont_write_bytecodetst no_user_sitetStno_sitetEtignore_environmenttvtverbosetbt bytes_warningt3t py3k_warningit-thash_randomizations-Rs-W(titemstgetattrR)tflagstappendt warnoptions(t flag_opt_mapR5tflagtoptRD((s"/usr/lib64/python2.7/subprocess.pyt_args_from_interpreter_flagsˆs(  cOst||ŽjƒS(sÓ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 = call(["ls", "-l"]) (Rtwait(t popenargstkwargs((s"/usr/lib64/python2.7/subprocess.pyR¤scOsSt||Ž}|rO|jdƒ}|dkr=|d}nt||ƒ‚ndS(sSRun 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: check_call(["ls", "-l"]) R5iN(RtgetR R(RVRWtretcodeR((s"/usr/lib64/python2.7/subprocess.pyR¯s   cOs˜d|krtdƒ‚ntdt||Ž}|jƒ\}}|jƒ}|r”|jdƒ}|dkr||d}nt||d|ƒ‚n|S(sRun command with arguments and return its output as a byte string. 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"]) '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) 'ls: non_existent_file: No such file or directory\n' tstdouts3stdout argument not allowed, it will be overridden.R5iRN(R,RRt communicateRRXR R(RVRWtprocessRt unused_errRYR((s"/usr/lib64/python2.7/subprocess.pyRÂs    cCsGg}t}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(s• 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. t s t"s\is\"t(tFalseROtlentextendtjoin(tseqtresultt needquotetargtbs_buftc((s"/usr/lib64/python2.7/subprocess.pyt list2cmdlineãs4       cBsãeZdZeZdd!d!d!d!d!eed!d!ed!dd„ Zd„Zej d„Z d!d„Z d„Z e ríd„Zd„Zd „Zd „Zd!ejejejd „Zd „Zd „Zd„Zd„Zd„ZeZnôd„Zed„Zd„Zd„Z e!r)e!j"ƒZ#nde$fd„ƒYZ%e%ƒZ#d„Ze&j'e&j(e&j)e&j*e&j+e&j,d„Z-d!e&j.e&j/e&j0e1j2d„Zd„Zd„Zd„Z3d„Z4d„Zd„Zd „ZRS("sž Execute a child program in a new process. For a complete description of the arguments see the Python documentation. Arguments: args: A string, or a sequence of program arguments. bufsize: supplied as the buffering argument to the open() function when creating the stdin/stdout/stderr pipe file objects executable: A replacement program to execute. stdin, stdout and stderr: These specify the executed programs' standard input, standard output and standard error file handles, respectively. preexec_fn: (POSIX only) An object to be called in the child process just before the child is executed. close_fds: Controls closing or inheriting of file descriptors. shell: If true, the command will be executed through the shell. cwd: Sets the current directory before the child is executed. env: Defines the environment variables for the new process. universal_newlines: If true, use universal line endings for file objects stdin, stdout and stderr. startupinfo and creationflags (Windows only) Attributes: stdin, stdout, stderr, pid, returncode icCstƒt|ttfƒs+tdƒ‚ntrˆ|d k rLtdƒ‚n|r¾|d k sv|d k sv|d k r¾tdƒ‚q¾n6| d k r£tdƒ‚n|dkr¾tdƒ‚nd |_d |_ d |_ d |_ d |_ | |_ |j|||ƒ\\}}}}}}}yA|j||||| | | | || |||||||ƒWn{tk rßtjƒ\}}}xF|D]>}y$trª|jƒn tj|ƒWqŽtk rËqŽXqŽW|||‚nXtr^|d k r tj|jƒdƒ}n|d k r4tj|jƒdƒ}n|d k r^tj|jƒdƒ}q^n|d k r…tj|d|ƒ|_n|d k rÍ| r²tj|d|ƒ|_ qÍtj|d |ƒ|_ n|d k r| rútj|d|ƒ|_ qtj|d |ƒ|_ nd S( sCreate new Popen instance.sbufsize must be an integers0preexec_fn is not supported on Windows platformssSclose_fds is not supported on Windows platforms if you redirect stdin/stdout/stderrs2startupinfo is only supported on Windows platformsis4creationflags is only supported on Windows platformstwbtrUtrbN(R/t isinstancetinttlongt TypeErrort mswindowsR R,tstdinRZtstderrtpidRtuniversal_newlinest _get_handlest_execute_childt ExceptionR)texc_infotClosetostclosetEnvironmentErrortmsvcrttopen_osfhandletDetachtfdopen(RR5tbufsizet executableRtRZRut preexec_fnt close_fdstshelltcwdtenvRwt startupinfot creationflagstp2creadtp2cwritetc2preadtc2pwriteterrreadterrwritetto_closetexc_typet exc_valuet exc_tracetfd((s"/usr/lib64/python2.7/subprocess.pyRNsl          -            cCs(|jddƒ}|jddƒ}|S(Ns s s (treplace(Rtdata((s"/usr/lib64/python2.7/subprocess.pyt_translate_newlines°scCsL|js dS|jd|ƒ|jdkrHtdk rHtj|ƒndS(NR&(t_child_createdR(RR R'RO(Rt_maxint((s"/usr/lib64/python2.7/subprocess.pyt__del__¶s  cCs |j|j|jgjdƒdkrd}d}|jr©|r™y|jj|ƒWq™tk r•}|jtjkr–|jtj kr–‚q–q™Xn|jj ƒnV|jrÔt |jj ƒ}|jj ƒn+|jrÿt |jj ƒ}|jj ƒn|j ƒ||fS|j|ƒS(sfInteract 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).iN(RtRZRutcountR twriteRR2tEPIPEtEINVALR~R7treadRUt _communicate(RtinputRZRuR6((s"/usr/lib64/python2.7/subprocess.pyR[Äs( ' $     cCs |jƒS(sSCheck if child process has terminated. Set and return returncode attribute.(R((R((s"/usr/lib64/python2.7/subprocess.pyRæsc Cs5tƒ}|dkr7|dkr7|dkr7d|fSd\}}d\}}d\} } |dkr£tjtjƒ}|dkrtjddƒ\}} qnc|tkrÊtjddƒ\}}n<t|tt fƒrñt j |ƒ}nt j |j ƒƒ}|j |ƒ}|j|ƒ|tkr>|j|ƒn|dkr†tjtjƒ}|dkrétjddƒ\} }qénc|tkr­tjddƒ\}}n<t|tt fƒrÔt j |ƒ}nt j |j ƒƒ}|j |ƒ}|j|ƒ|tkr!|j|ƒn|dkritjtjƒ} | dkrátjddƒ\} } qánx|tkr�tjddƒ\} } nQ|tkr¥|} n<t|tt fƒrÌt j |ƒ} nt j |j ƒƒ} |j | ƒ} |j| ƒ|tkr|j| ƒn||||| | f|fS(s|Construct and return tuple with IO objects: p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite iN(NNNNNN(NN(NN(NN(tsetR t _subprocesst GetStdHandleRt CreatePipeRRoRpRqR€t get_osfhandletfilenot_make_inheritabletaddR R!R( RRtRZRuR“R�RŽR�R�R‘R’t_((s"/usr/lib64/python2.7/subprocess.pyRxðsd $                     cCs+tjtjƒ|tjƒddtjƒS(s2Return a duplicate of handle, which is inheritableii(R¦tDuplicateHandletGetCurrentProcesstDUPLICATE_SAME_ACCESS(Rthandle((s"/usr/lib64/python2.7/subprocess.pyR«6scCsˆtjjtjjtjdƒƒdƒ}tjj|ƒs„tjjtjjtjƒdƒ}tjj|ƒs„t dƒ‚q„n|S(s,Find and return absolut path to w9xpopen.exeis w9xpopen.exesZCannot locate w9xpopen.exe, which is needed for Popen to work with your shell or platform.( R}tpathRdtdirnameR¦tGetModuleFileNametexistsR)t exec_prefixt RuntimeError(Rtw9xpopen((s"/usr/lib64/python2.7/subprocess.pyt_find_w9xpopen=s   c st|tjƒs!t|ƒ}n|dkr9tƒ}nd| ||fkr~|jtjO_| |_ ||_ ||_ n| r(|jtj O_tj |_tjjddƒ}dj||ƒ}tjƒdksùtjj|ƒjƒdkr(|jƒ}d||f}| tjO} q(n‡fd†}zjy>tj||ddt| ƒ| |||ƒ \}}}}Wn%tjk rŸ}t|jŒ‚nXWd| dk r½|| ƒn|dk rÖ||ƒn|dk rï||ƒnXt|_ ||_!||_"|j#ƒdS( s$Execute program (MS Windows version)tCOMSPECscmd.exes {} /c "{}"I€s command.coms"%s" %scs|jƒˆj|ƒdS(N(R|R+(R—(R“(s"/usr/lib64/python2.7/subprocess.pyt_close_in_parentws N($Rottypest StringTypesRkR R R R¦R#RRRR$R"RR}tenvironRXtformatt GetVersionR²tbasenametlowerR¹Rt CreateProcessRpRRt WindowsErrorR5R0R›t_handleRvR|(RR5R…R†R‡R‰RŠRwR‹RŒRˆR“R�RŽR�R�R‘R’tcomspecR¸R»thpthtRvttidR6((R“s"/usr/lib64/python2.7/subprocess.pyRyNsR                 cCsF|jdkr?||jdƒ|kr?||jƒ|_q?n|jS(sÎ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(RR RÅ(RR&t_WaitForSingleObjectt_WAIT_OBJECT_0t_GetExitCodeProcess((s"/usr/lib64/python2.7/subprocess.pyR(Ÿs cCsD|jdkr=tj|jtjƒtj|jƒ|_n|jS(sOWait for child process to terminate. Returns returncode attribute.N(RR R¦tWaitForSingleObjectRÅtINFINITEtGetExitCodeProcess(R((s"/usr/lib64/python2.7/subprocess.pyRU°s   cCs|j|jƒƒdS(N(ROR¢(Rtfhtbuffer((s"/usr/lib64/python2.7/subprocess.pyt _readerthreadºscCsâd}d}|jrYg}tjd|jd|j|fƒ}|jtƒ|jƒn|jr¦g}tjd|jd|j|fƒ}|jtƒ|jƒn|j r%|dk ry|j j |ƒWqt k r}|j t j kröq|j t jkr q‚qXn|j jƒn|jr;|jƒn|jrQ|jƒn|dk rj|d}n|dk rƒ|d}n|jrÎttdƒrÎ|r³|j|ƒ}n|rÎ|j|ƒ}qÎn|jƒ||fS(NttargetR5itnewlines(R RZt threadingtThreadRÒt setDaemonR0tstartRuRtRŸRR2R R¡R~RdRwthasattrtfileRšRU(RR¤RZRut stdout_threadt stderr_threadR6((s"/usr/lib64/python2.7/subprocess.pyR£¾sP                  cCs…|tjkr|jƒne|tjkrDtj|jtjƒn=|tjkrltj|jtjƒntdj |ƒƒ‚dS(s)Send a signal to the process sUnsupported signal: {}N( tsignaltSIGTERMt terminatet CTRL_C_EVENTR}tkillRvtCTRL_BREAK_EVENTR,R¿(Rtsig((s"/usr/lib64/python2.7/subprocess.pyt send_signalùs cCsvytj|jdƒWnXtk rq}|jdkr>‚ntj|jƒ}|tjkre‚n||_nXdS(s#Terminates the process iiN(R¦tTerminateProcessRÅR1twinerrorRÏt STILL_ACTIVER(RR6trc((s"/usr/lib64/python2.7/subprocess.pyRßsc CsÃtƒ}d\}}d\}}d\} } |dkr<n^|tkrp|jƒ\}}|j||fƒn*t|ttfƒrŽ|}n |jƒ}|dkr©n^|tkrÝ|jƒ\}}|j||fƒn*t|ttfƒrû|}n |jƒ}|dkrn‘|tkrJ|jƒ\} } |j| | fƒn]|t kr}|dk rk|} q§t j jƒ} n*t|ttfƒr›|} n |jƒ} ||||| | f|fS(s|Construct and return tuple with IO objects: p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite N(NN(NN(NN( R¥R Rt pipe_cloexectupdateRoRpRqRªRR)t __stdout__( RRtRZRuR“R�RŽR�R�R‘R’((s"/usr/lib64/python2.7/subprocess.pyRxsF                   cCs~y tj}Wntk r&d}nXtj|tjƒ}|r_tj|tj||Bƒntj|tj||@ƒdS(Ni(tfcntlt FD_CLOEXECtAttributeErrortF_GETFDtF_SETFD(RR—tcloexect cloexec_flagtold((s"/usr/lib64/python2.7/subprocess.pyt_set_cloexec_flagNs   cCs6tjƒ\}}|j|ƒ|j|ƒ||fS(s#Create a pipe with FDs set CLOEXEC.(R}tpipeRô(Rtrtw((s"/usr/lib64/python2.7/subprocess.pyRé[s  cCs�ttdƒr6tjd|ƒtj|dtƒnGxDtdtƒD]3}||kr^qFnytj|ƒWqFqFXqFWdS(Nt closerangeii(RÙR}RøtMAXFDtxrangeR~(Rtbutti((s"/usr/lib64/python2.7/subprocess.pyt _close_fdsgs t_noop_context_managercBseZd„Zd„ZRS(cCsdS(N((R((s"/usr/lib64/python2.7/subprocess.pyt __enter__~R`cGsdS(N((RR5((s"/usr/lib64/python2.7/subprocess.pyt__exit__R`(RR RÿR(((s"/usr/lib64/python2.7/subprocess.pyRþ{s c!sŸt|tjƒr|g}n t|ƒ}| rVddg|}|rV||dtj||ƒndS(N(RôRaR R}tdup2(taRF(R(s"/usr/lib64/python2.7/subprocess.pyt_dup2Ås  iRûR`iÿi()RoR¼R½tlistR Rét_disabling_gc_locktgct isenabledtdisableR}tforkRvtenableR0R›R~tdupR¬tchdirRýtexecvptexecvpeR)R{t tracebacktformat_exceptionRdtchild_tracebackRŸtpickletdumpst_exitR7R¢ROtwaitpidR1R2tECHILDtloads(!RR5R…R†R‡R‰RŠRwR‹RŒRˆR“R�RŽR�R�R‘R’R»t errpipe_readt errpipe_writetgc_was_enabledRtclosedR—R”R•ttbt exc_linesR™t pickle_bitsR6tchild_exception((RR“s"/usr/lib64/python2.7/subprocess.pyRy„s®                       !       cCsl||ƒr||ƒ |_nI||ƒr=||ƒ|_n+||ƒr\||ƒ |_n tdƒ‚dS(NsUnknown child exit status!(RR·(Rtstst _WIFSIGNALEDt _WTERMSIGt _WIFEXITEDt _WEXITSTATUSt _WIFSTOPPEDt _WSTOPSIG((s"/usr/lib64/python2.7/subprocess.pyt_handle_exitstatuss   c Cs�|jdkr–y;||j|ƒ\}}||jkrI|j|ƒnWq–|k r’}|dk rt||_n|j|kr“d|_q“q–Xn|jS(sõ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(RR RvR'R2( RR&t_waitpidt_WNOHANGt _os_errort_ECHILDRvR R6((s"/usr/lib64/python2.7/subprocess.pyR(+s   cCs›x‘|jdkr“y"ttj|jdƒ\}}Wn:tk rp}|jtjkr^‚n|j}d}nX||jkr|j |ƒqqW|jS(sOWait for child process to terminate. Returns returncode attribute.iN( RR R7R}RRvR1R2RR'(RRvR R6((s"/usr/lib64/python2.7/subprocess.pyRUFs"  cCsý|jr/|jjƒ|s/|jjƒq/ntrM|j|ƒ\}}n|j|ƒ\}}|dk r€dj|ƒ}n|dk rždj|ƒ}n|jrét t dƒré|rÎ|j |ƒ}n|ré|j |ƒ}qén|j ƒ||fS(NR`RÔ( RttflushR~t _has_pollt_communicate_with_pollt_communicate_with_selectR RdRwRÙRÚRšRU(RR¤RZRu((s"/usr/lib64/python2.7/subprocess.pyR£[s$     cs>d}d}i‰i}tjƒ‰‡‡fd†}‡‡fd†}|jrm|rm||jtjƒntjtjB}|jr°||j|ƒg||jjƒ<}n|j rã||j |ƒg||j jƒ<}nd}xHˆr3yˆjƒ} Wn5tj k r9} | j dt j kr3qìn‚nXxó| D]ë\} } | tj@rß|||t!} y|tj| | ƒ7}Wn5tk r¼} | j t jkr¶|| ƒqÜ‚q,X|t|ƒkr,|| ƒq,qA| |@r"tj| dƒ}|s|| ƒn|| j|ƒqA|| ƒqAWqìW||fS(Ncs*ˆj|jƒ|ƒ|ˆ|jƒR`sLooking for 'hda'...tdmesgtgrepthdaRtsTrying a weird file...s/this/path/does/not/exists'The file didn't exist. I thought so...sChild traceback:tErrorsGosh. No error.(RRR[R}tgetuidRURZtreprR1R2tENOENTRR)Ru(tplisttptp1tp2R6((s"/usr/lib64/python2.7/subprocess.pyt _demo_posixs* ! cCsldGHtddtdtƒ}tdd|jdtƒ}t|jƒdƒGHdGHtd ƒ}|jƒdS( Ns%Looking for 'PROMPT' in set output...R¥RZRˆs find "PROMPT"RtisExecuting calc...tcalc(RRR0RZR^R[RU(RbRcRa((s"/usr/lib64/python2.7/subprocess.pyt _demo_windows+s t__main__(5R R)tplatformRsR}R¼RRRÝR2RzRRÕR€R¦R RR9RÙR-t ImportErrorR RìRRMR=t__all__RRRR R!R"R#R$RctsysconfRùR'R/RRR7RTRRRRkRMRRdRfR(((s"/usr/lib64/python2.7/subprocess.pytsp                :       ! FÿÿÿÜ )