Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/internet/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pyc


ƇNc@sGdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ej
Zde_ddl
mZddlmZmZmZddlmZddlmZddlmZdd	lmZd
ZdejfdYZd
ZdZdejefdYZ dS(s4
http://isometric.sixsided.org/_/gates_in_the_head/
iNi(t
implements(tIProcessTransportt	IConsumert	IProducer(tquoteArguments(terror(t_pollingfile(tBaseProcesscCs"ddl}|GH|jjdS(Ni(tsyststdouttflush(tmsgR((sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pytdebug$st_ReapercBseZdZdZRS(cCs
||_dS(N(tproc(tselfR((sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pyt__init__+scCsXtj|jjdtjkr%dStj|jj}|j|jj|dS(Ni(	t
win32eventtWaitForSingleObjectRthProcesst
WAIT_OBJECT_0twin32processtGetExitCodeProcesst
deactivatetprocessEnded(RtexitCode((sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pyt	checkWork.s!
(t__name__t
__module__RR(((sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pyR
)s	cCsDt|d}|jddkr@|jdjd}|SdS(s 
    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.
    trUis#!is
N(tfiletreadtreadlinetstrip(tfilenametftexe((sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pyt_findShebang7scCs|jddkS(s
    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
    ii(targs(tpywinerr((sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pyt_invalidWin32AppQstProcesscBseZdZeeeedZdZdZ	dZ
dZdZdZ
dZd	Zd
ZdZdZd
ZdZdZdZdZdZdZdZdZdZdZRS(sA 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)

    ics6tjj|tj|tj}d|_tj|d\_	}tj|d\_
}	tj|d\}
_tjjtj
d	d	tj|_|	_|
_tj_tj}tj|j	|ddtj}tjj	|_	tj|j
|ddtj}tjj
|_
tj|j|ddtj}tjj|_tjjj |pit!|fd}
yy|
Wnnt"k
re}|j#d
krni}x0j$D]"\}}t%||t%|<q/W||
nXWnt&j'k
rN}t(|st)|qOt*}|d	krt)dqOt+|}|j,dt!|}|y|
WqOt&j'k
rJ}t(|r;t)d||fnt)|qOXnXtj|	tj|tj|
tj-j	fdj._/tj-j
fdj0_1tj2jj3_4x-j/j1j4fD]}j5|qWj6j7j5t8d	S(s-
        Create a new child process.
        iic
s@tjdddd	\___}dS(Nii(Rt
CreateProcesstNoneRthThreadtpid(tdwTid(RtStartupInfotcmdlinetcommandtenvtpath(sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pytdoCreatess<All dictionary items must be strings, or all must be unicodesD%r is neither a Windows executable, nor a script with a shebang lines<%r has an invalid shebang line: %r is not a valid executablecsjjd|S(Ni(tprototchildDataReceived(tdata(R(sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pyt<lambda>scsjjd|S(Ni(R5R6(R7(R(sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pyR8sN(s<All dictionary items must be strings, or all must be unicode(9Rt
_PollingTimerRRt
win32securitytSECURITY_ATTRIBUTEStbInheritHandlet	win32pipet
CreatePipethStdoutRthStderrRthStdinWtSetNamedPipeHandleStatetPIPE_NOWAITR+RtSTARTUPINFOt
hStdOutputt	hStdErrort	hStdInputtSTARTF_USESTDHANDLEStdwFlagstwin32apitGetCurrentProcesstDuplicateHandletwin32contDUPLICATE_SAME_ACCESSt	win32filetCloseHandletostenvirontcopytupdateRt	TypeErrorR&titemstunicodet
pywintypesRR(tOSErrorR%tlisttinsertt_PollableReadPipetoutConnectionLostR	terrConnectionLosttstderrt_PollableWritePipetinConnectionLosttstdint_addPollableResourceR5tmakeConnectionR
(RtreactortprotocolR1R&tenvironmentR3tsAttrsthStdoutWthStderrWthStdinRt
currentPidttmpR4tetnewenvtkeytvaluetpwtetshebtorigcmdtpwte2tpipewatcher((R0R/RR2R1R3sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pyRws							



cCsD|jdkrtjn|dkr@tj|jdndS(NtINTtTERMtKILLi(RwRxRy(R-R+RtProcessExitedAlreadyRtTerminateProcessR(RtsignalID((sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pyt
signalProcessscCs&|dkrtj|Stj|S(Ni(RtProcessDonetProcessTerminated(Rtstatus((sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pyt
_getReasons
cCs|jj|dS(sO
        Write data to the process' stdin.

        @type data: C{str}
        N(Rbtwrite(RR7((sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pyRscCs|jj|dS(sZ
        Write data to the process' stdin.

        @type data: C{list} of C{str}
        N(Rbt
writeSequence(Rtseq((sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pyRscCs/|dkr|jj|nt|dS(s9
        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{str}

        @return: C{None}

        @raise KeyError: If C{fd} is anything other than the stdin file
            descriptor (C{0}).
        iN(RbRtKeyError(RtfdR7((sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pytwriteToChildscCs[|dkr|jn>|dkr2|jn%|dkrK|jntddS(Niiis4Only standard-IO file descriptors available on win32(t
closeStdintcloseStdouttcloseStderrtNotImplementedError(RR((sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pytcloseChildFD3s


cCs|jjdS(s"Close the process' stdin.
        N(Rbtclose(R((sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pyR=scCs|jjdS(N(R_R(R((sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pyRBscCs|jjdS(N(R	R(R((sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pyREscCs"|j|j|jdS(s&Close the process' stdout, in and err.N(RRR(R((sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pytloseConnectionHs

cCs|jjd|jdS(Ni(R5tchildConnectionLosttconnectionLostNotify(R((sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pyR]OscCs|jjd|jdS(Ni(R5RR(R((sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pyR^TscCs|jjd|jdS(Ni(R5RR(R((sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pyRaYscCs|jd7_|jdS(sS
        Will be called 3 times, by stdout/err threads and process handle.
        iN(tclosedNotifiestmaybeCallProcessEnded(R((sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pyR^scCs^|jdkrZ|jrZtj|jtj|jd|_d|_tj|ndS(Ni(	RtlostProcessRORPRR,R+RR(R((sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pyRfs		cCs|jj||dS(N(RbtregisterProducer(Rtproducert	streaming((sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pyRpscCs|jjdS(N(RbtunregisterProducer(R((sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pyRsscCs|jdS(N(t_pause(R((sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pytpauseProducingwscCs|jdS(N(t_unpause(R((sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pytresumeProducingzscCs|jdS(N(R(R((sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pyt
stopProducing}scCsd|jj|jfS(s@
        Return a string representation of the process.
        s<%s pid=%s>(t	__class__RR-(R((sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pyt__repr__s(RRt__doc__RRRRRRR}RRRRRRRRRR]R^RaRRRRRRRR(((sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pyR)as2									
									
					(!RRQRJRMRROR=RR:RXR;tPIPE_ATTRS_INHERITABLER<tzope.interfaceRttwisted.internet.interfacesRRRttwisted.python.win32Rttwisted.internetRRttwisted.internet._baseprocessRRt_PollableResourceR
R%R(R9R)(((sC/usr/lib/python2.7/dist-packages/twisted/internet/_dumbwin32proc.pyt<module>s,