Ϫf(1RdZddlZddlZddlmZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl mZmZddlmZddlmZmZmZddlmZe j0Zde_d ZGd d ej8Zd Zd ZeeeeGddej@eZ!y)z< Windows Process Management, used with reactor.spawnProcess N) implementer) _pollingfileerror) BaseProcess) IConsumerIProcessTransport IProducer)quoteArgumentscVt|tjjyN)printsysstdoutflush)msgs A/usr/lib/python3/dist-packages/twisted/internet/_dumbwin32proc.pydebugr$s #JJJceZdZdZdZy)_Reaperc||_yr )proc)selfrs r__init__z_Reaper.__init__*s  rc$tj|jjdtjk7ryt j |jj}|j|jj|yNr) win32eventWaitForSingleObjectrhProcess WAIT_OBJECT_0 win32processGetExitCodeProcess deactivate processEnded)rexitCodes r checkWorkz_Reaper.checkWork-sh  * *499+=+=q A'' (224993E3EF  x(rN)__name__ __module__ __qualname__rr'rrrr)s  rrct|5}|jddk(r+|jdjd}|cdddS dddy#1swYyxYw)a  Look for a #! line, and return the value following the #! if one exists, or None if this file is not a script. I don't know if there are any conventions for quoting in Windows shebang lines, so this doesn't support any; therefore, you may not pass any arguments to scripts invoked as filters. That's probably wrong, so if somebody knows more about the cultural expectations on Windows, please feel free to fix. This shebang line support was added in support of the CGI tests; appropriately enough, I determined that shebang lines are culturally accepted in the Windows world through this page:: http://www.cgi101.com/learn/connect/winxp.html @param filename: str representing a filename @return: a str representing another filename. z#!i N)openreadreadlinestrip)filenamefexes r _findShebangr69s[* h1 66!9 **T"((.C s 6AAc&|jddk(S)z Determine if a pywintypes.error is telling us that the given process is 'not a valid win32 application', i.e. not a PE format executable. @param pywinerr: a pywintypes.error instance raised by CreateProcess @return: a boolean r)args)pywinerrs r_invalidWin32Appr;Ts == s ""rceZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdefdZy)Processa A process that integrates with the Twisted event loop. If your subprocess is a python program, you need to: - Run python.exe with the '-u' command line option - this turns on unbuffered I/O. Buffering stdout/err/in can cause problems, see e.g. http://support.microsoft.com/default.aspx?scid=kb;EN-US;q1903 - If you don't want Windows messing with data passed over stdin/out/err, set the pipes to be in binary mode:: import os, sys, mscvrt msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY) rc tjj|tj|t j }d|_tj|d\_ }tj|d\_ } tj|d\} _ tjjtjddtj|_| _| _tj&_t+j,} t+j.| j| ddt0j2} t5j6j| _ t+j.| j| ddt0j2} t5j6j| _ t+j.| j| ddt0j2} t5j6j| _ t8j:j=j?|xsijAD cic].\} }t9jB| t9jB|0c}} |Dcgc]}t9jB|}}tE|rt9jBnrt9jBnfd} |t5j6| t5j6|t5j6| tjTjfdjV_,tjTjfd jZ_.tj^jj`_1jXj\jbfD]}je|jfjijetkycc}} wcc}w#tFjH$r}tK|s tM|tO}|tMdztQ|}|jSdtE|}| |nB#tFjH$r,}tK|rtM|d|dtM|d}~wwxYwYd}~d}~wwxYw) z- Create a new child process. r rNc tj}tjddd| \___}yNr )win32conCREATE_NO_WINDOWr" CreateProcessr hThreadpid)flagsdwTid StartupInfocmdlinecommandenvpathrs rdoCreatez"Process.__init__..doCreates@--E;G;U;U$aT;< 8DM4<5rzD%r is neither a Windows executable, nor a script with a shebang linez has an invalid shebang line: z is not a valid executablec<jjd|Sr@protochildDataReceiveddatars rz"Process.__init__..55a>rc<jjd|SNr-rOrRs rrTz"Process.__init__..rUr)6r _PollingTimerrr win32securitySECURITY_ATTRIBUTESbInheritHandle win32pipe CreatePipehStdoutRhStderrRhStdinWSetNamedPipeHandleState PIPE_NOWAITr" STARTUPINFO hStdOutput hStdError hStdInputSTARTF_USESTDHANDLESdwFlagswin32apiGetCurrentProcessDuplicateHandlerADUPLICATE_SAME_ACCESS win32file CloseHandleosenvironcopyupdateitemsfsdecoder pywintypesrr;OSErrorr6listinsert_PollableReadPipeoutConnectionLostrerrConnectionLoststderr_PollableWritePipeinConnectionLoststdin_addPollableResourcerPmakeConnectionr)rreactorprotocolrJr9 environmentrLsAttrshStdoutWhStderrWhStdinR currentPidtmpkeyvaluexrMpwtesheborigcmdpwte2 pipewatcherrHrIrKs` ` ` @@@rrzProcess.__init__|sJ ""++D':T8,224 !#,"6"6vq"A x"+"6"6vq"A x ) 4 4VQ ?)) LL)//t #..0 !)  (  ' *?? //1 &&  z1a9W9W  dmm, &&  z1a9W9W  dmm, &&  j!Q8V8V  dll+ jjoo ;$"%FIiikR Ur{{3U!33R)--1 A-- &+2"++g&w$(r{{4 d   - JD h'h'g&#44 MM >  " "  #44 MM >  " "  "44 LL$//   ;; TZZ? 3K  % %k 2 3 !!$' !!'$-0aS." -#D)dm#$G,<!;=DE  :DKK7+,T2G%G"G - %++-+E2")BI4!Q#&en,-#- -sI3Q-=Q3#Q88T> AT9)S10T91T0'T++T00T99T>c|jtj|dvr!tj|j dyy)N)INTTERMKILLr )rErProcessExitedAlreadyr"TerminateProcessr )rsignalIDs r signalProcesszProcess.signalProcesss= 88 ,,. . . .  ) )$-- ; /rc`|dk(rtj|Stj|Sr)r ProcessDoneProcessTerminated)rstatuss r _getReasonzProcess._getReason s+ Q;$$V, ,&&v..rc:|jj|y)zQ Write data to the process' stdin. @type data: C{bytes} N)rwrite)rrSs rrz Process.writes rc:|jj|y)z[ Write data to the process' stdin. @type seq: C{list} of C{bytes} N)r writeSequence)rseqs rrzProcess.writeSequences   %rcZ|dk(r|jj|yt|)a; Similar to L{ITransport.write} but also allows the file descriptor in the child process which will receive the bytes to be specified. This implementation is limited to writing to the child's standard input. @param fd: The file descriptor to which to write. Only stdin (C{0}) is supported. @type fd: C{int} @param data: The bytes to write. @type data: C{bytes} @return: L{None} @raise KeyError: If C{fd} is anything other than the stdin file descriptor (C{0}). rN)rrKeyError)rfdrSs r writeToChildzProcess.writeToChilds'& 7 JJ  T "2, rc|dk(r|jy|dk(r|jy|dk(r|jytd)Nrr r-z4Only standard-IO file descriptors available on win32) closeStdin closeStdout closeStderrNotImplementedError)rrs r closeChildFDzProcess.closeChildFD7sI 7 OO  1W     1W    %F rc8|jjy)zClose the process' stdin.N)rclosers rrzProcess.closeStdinCs rc8|jjyr )r|rrs rrzProcess.closeStderrG rc8|jjyr )rrrs rrzProcess.closeStdoutJrrcd|j|j|jy)z8 Close the process' stdout, in and err. N)rrrrs rloseConnectionzProcess.loseConnectionMs&   rcZ|jjd|jyr@rPchildConnectionLostconnectionLostNotifyrs rrzzProcess.outConnectionLostU  &&q) !!#rcZ|jjd|jyrWrrs rr{zProcess.errConnectionLostYrrcZ|jjd|jyrrrs rr~zProcess.inConnectionLost]rrcN|xjdz c_|jy)zS Will be called 3 times, by stdout/err threads and process handle. r N)closedNotifiesmaybeCallProcessEndedrs rrzProcess.connectionLostNotifyas! q  ""$rc|jdk(ro|jrbtj|jtj|j d|_d|_t j|yyy)N)r lostProcessrmrnr rDrrrs rrzProcess.maybeCallProcessEndedhs`   ! #(8(8  ! !$-- 0  ! !$,, / DMDL  - -d 3 )9 #rc<|jj||yr )rregisterProducer)rproducer streamings rrzProcess.registerProducerqs ##Hi8rc8|jjyr )runregisterProducerrs rrzProcess.unregisterProducerts %%'rc$|jyr )_pausers rpauseProducingzProcess.pauseProducingxs  rc$|jyr )_unpausers rresumeProducingzProcess.resumeProducing{s  rc$|jyr )rrs r stopProducingzProcess.stopProducing~s rctd)NzUnimplemented: Process.getHostrrs rgetHostzProcess.getHost!"BCCrctd)NzUnimplemented: Process.getPeerrrs rgetPeerzProcess.getPeerrrreturncPd|jjd|jdS)z@ Return a string representation of the process. ) __class__r(rErs r__repr__zProcess.__repr__s(4>>**+5 !<rs   &05OO/;::<()% l,,  6#"  95g=l((+g=6g=r