Your IP : 172.28.240.42


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


=Nc@sSdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	yddl
Z
Wnek
reZ
Z
nXddlm
Z
ddlmZddlmZddlmZmZmZmZmZddlmZddlmZmZmZdd	lmZd
ej fdYZ!dej"fd
YZ#dej fdYZ$dej fdYZ%dej fdYZ&dej fdYZ'de%fdYZ(dej fdYZ)de)fdYZ*de)fdYZ+dej"fdYZ,d ej fd!YZ-d"fd#YZ.d$e.ej"fd%YZ/d&e.ej"fd'YZ0d(ej fd)YZ1d*ej"fd+YZ2d,ej fd-YZ3d.fd/YZ4d0e5fd1YZ6d2e5fd3YZ7e
ek	rd4e
j8fd5YZ9d6e
j:fd7YZ;d8e
j<fd9YZ=nd:ej"fd;YZ>d<ej"e4fd=YZ?d>ej"e4fd?YZ@d@e'fdAYZAdBej"fdCYZBdDej"fdEYZCdFej"fdGYZDdHej"fdIYZEdJej fdKYZFdLej"fdMYZGdNZHejIjJdOkpejKeereHe?_LeHe@_LeHe0_LeHe2_LnejIjJdPkpejKeer'eHeB_LeHe/_LeHeD_LeHeC_LnejKeerOeHe,_LeHeG_LndS(Qs
Test running processes.
iN(tprocess(tverifyObject(tmsg(treactortprotocolterrort
interfacestdefer(tunittest(tutiltruntimet	procutils(tsettStubProcessProtocolcBs;eZdZdZdZdZdZdZRS(s
    ProcessProtocol counter-implementation: all methods on this class raise an
    exception, so instances of this may be used to verify that only certain
    methods are called.
    cCs
tdS(N(tNotImplementedError(tselftdata((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytoutReceived)scCs
tdS(N(R(RR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyterrReceived,scCs
tdS(N(R(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytinConnectionLost/scCs
tdS(N(R(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytoutConnectionLost2scCs
tdS(N(R(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyterrConnectionLost5s(t__name__t
__module__t__doc__RRRRR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR
#s				tProcessProtocolTestscBsDeZdZdZdZdZdZdZdZRS(sj
    Tests for behavior provided by the process protocol base class,
    L{protocol.ProcessProtocol}.
    cCsttjtjdS(sD
        L{ProcessProtocol} implements L{IProcessProtocol}.
        N(RRtIProcessProtocolRtProcessProtocol(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_interface?scsXgdtffdY}d}|}|jd||j|gdS(s
        Verify that when stdout is delivered to
        L{ProcessProtocol.childDataReceived}, it is forwarded to
        L{ProcessProtocol.outReceived}.
        tOutProtocolcseZfdZRS(csj|dS(N(tappend(RR(treceived(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRNs(RRR((R(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRMstbytesiN(R
tchildDataReceivedtassertEqual(RRR tp((Rs=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_outReceivedFs	csXgdtffdY}d}|}|jd||j|gdS(sA
        Similar to L{test_outReceived}, but for stderr.
        tErrProtocolcseZfdZRS(csj|dS(N(R(RR(R(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR]s(RRR((R(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR%\sR iN(R
R!R"(RR%R R#((Rs=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_errReceivedWs	csOgdtffdY}|}|jd|jdgdS(s
        Verify that when stdin close notification is delivered to
        L{ProcessProtocol.childConnectionLost}, it is forwarded to
        L{ProcessProtocol.inConnectionLost}.
        tInLostProtocolcseZfdZRS(csjddS(N(RtNone(R(tlost(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRns(RRR((R)(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR'msiN(R
tchildConnectionLostR"R((RR'R#((R)s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_inConnectionLostfs
	
csOgdtffdY}|}|jd|jdgdS(sF
        Similar to L{test_inConnectionLost}, but for stdout.
        tOutLostProtocolcseZfdZRS(csjddS(N(RR((R(R)(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR|s(RRR((R)(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR,{siN(R
R*R"R((RR,R#((R)s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_outConnectionLostvs
	
csOgdtffdY}|}|jd|jdgdS(sF
        Similar to L{test_inConnectionLost}, but for stderr.
        tErrLostProtocolcseZfdZRS(csjddS(N(RR((R(R)(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRs(RRR((R)(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR.siN(R
R*R"R((RR.R#((R)s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_errConnectionLosts
	
(	RRRRR$R&R+R-R/(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR:s					tTrivialProcessProtocolcBs2eZdZdZdZdZdZRS(s
    Simple process protocol for tests purpose.

    @ivar outData: data received from stdin
    @ivar errData: data received from stderr
    cCs||_g|_g|_dS(sl
        Create the deferred that will be fired at the end, and initialize
        data structures.
        N(tdeferredtoutDataterrData(Rtd((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt__init__s		cCs||_|jjddS(N(treasonR1tcallbackR((RR6((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytprocessEndeds	cCs|jj|dS(N(R2R(RR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRscCs|jj|dS(N(R3R(RR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRs(RRRR5R8RR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR0s
				tTestProcessProtocolcBs,eZdZdZdZdZRS(cCs2dg|_d|_d|_|jjddS(Nittabcd(tstagesRterrt	transporttwrite(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytconnectionMades		cCs@|dkr|j|7_n|dkr<|j|7_ndS(s
        Override and disable the dispatch provided by the base class to ensure
        that it is really this method which is being called, and the transport
        is not going directly to L{outReceived} or L{errReceived}.
        iiN(RR=(RtchildFDR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR!scCs|dkrG|jjd|jdkr4tn|jjdn|dkr|jjd|jdkrdt|jGHtn|jjd|jjdn|dkr|jjd	nd
S(s
        Similarly to L{childDataReceived}, disable the automatic dispatch
        provided by the base implementation to verify that the transport is
        calling this method directly.
        iiR;t1234is
err != 1234: iiiN(R<RRtRuntimeErrorR>R?R=trepr(RRA((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR*s	cCs||_|jjddS(N(R6R1R7R((RR6((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR8s	(RRR@R!R*R8(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR9s			tEchoProtocolcBsHeZddZdZdZdZdZdZdZ	dZ
RS(	t1234567ii
icCs||_d|_dS(Ni(tonEndedtcount(RRG((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR5s	cCsy|jdkstx.t|jdD]}|jj|jq)W|jj|j|jg|j|j|_dS(Ni(tntAssertionErrortrangeR>R?tst
writeSequencetbuffer(Rti((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR@s
cCst|j|jt|t|krOd||jf|_|jjn=|jt|7_|jt|jkr|jjndS(Nswrong bytes received(RNRHtlentfailureR>t
closeStdin(RR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRs*cCsEd|_|jtjs1dt||_n|jj|dS(Nis#process didn't terminate normally: (tfinishedtcheckRtProcessDonetstrRQRGR7(RR6((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR8s	N(RRRLRIRSR(RQR5R@RR8(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyREs
				tSignalProtocolcBs2eZdZdZdZdZdZRS(s
    A process protocol that sends a signal when data is first received.

    @ivar deferred: deferred firing on C{processEnded}.
    @type deferred: L{defer.Deferred}

    @ivar signal: the signal to send to the process.
    @type signal: C{str}

    @ivar signaled: A flag tracking whether the signal has been sent to the
        child or not yet.  C{False} until it is sent, then C{True}.
    @type signaled: C{bool}
    cCs||_||_t|_dS(N(R1tsignaltFalsetsignaled(RR1tsig((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR5s		cCs=td|f|js9t|_|jj|jndS(s
        Handle the first output from the child process (which indicates it
        is set up and ready to receive the signal) by sending the signal to
        it.  Also log all output to help with debugging.
        sReceived %r from child stdoutN(RRZtTrueR>t
signalProcessRX(RR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRs		cCstd|fdS(s_
        Log all data received from the child's stderr to help with
        debugging.
        sReceived %r from child stderrN(R(RR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR#scCsKtd|jf|jtjsF|jjtd|fS|j}t	|j
trztt
d|j
}n	|j
}|j
dk	r|jjtd|j
|j
fS|j
|kr|jjtd|j
|j
|fStj|j|kr7|jjtd|j
tj|jfS|jjddS(sL
        Callback C{self.deferred} with C{None} if C{reason} is a
        L{error.ProcessTerminated} failure with C{exitCode} set to C{None},
        C{signal} set to C{self.signal}, and C{status} holding the status code
        of the exited process. Otherwise, errback with a C{ValueError}
        describing the problem.
        sChild exited: %rswrong termination: %stSIGsSIG%s: exitCode is %s, not Nones SIG%s: .signal was %s, wanted %ss	SIG%s: %sN(RtgetTracebackRTRtProcessTerminatedR1terrbackt
ValueErrortvaluet
isinstanceRXRVtgetattrtexitCodeR(tostWTERMSIGtstatusR7(RR6tvtsignalValue((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR8+s(						&(RRRR5RRR8(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRWs

			tTestManyProcessProtocolcBseZdZdZRS(cCstj|_dS(N(RtDeferredR1(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR5LscCsB||_|jtjr.|jjdn|jj|dS(N(R6RTRRUR1R7R(Ra(RR6((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR8Os	(RRR5R8(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRlKs	tUtilityProcessProtocolcBs_eZdZdZdZeeZdZdZdZ	dZ
dZdZRS(	s
    Helper class for launching a Python process and getting a result from it.

    @ivar program: A string giving a Python program for the child process to
    run.
    cCs?tj}|}|j|||d|jg|d||S(s9
        Run a Python process connected to a new instance of this protocol
        class.  Return the protocol instance.

        The Python process is given C{self.program} on the command line to
        execute, in addition to anything specified by C{argv}.  C{env} is
        the complete environment.
        s-ctenv(tsyst
executabletspawnProcesstprogram(tclsRtargvRotexeR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytrunas
			#cCsg|_g|_dS(N(R trequests(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR5rs	cCs
tdS(sR
        Called with all bytes received on stdout when the process exits.
        N(R(RR ((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytparseChunkswscCs tj}|jj||S(s{
        Return a Deferred which will fire with the result of L{parseChunks}
        when the child process exits.
        (RRmRxR(RR4((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt	getResult~scCs4|j}d|_x|D]}|j|qWdS(st
        Callback all Deferreds returned up until now by L{getResult}
        with the given result object.
        N(RxR(R7(RtresultRxR4((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt_fireResultDeferredss		
cCs|jj|dS(sE
        Accumulate output from the child process in a list.
        N(R R(RR ((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRscCs|j|j|jdS(su
        Handle process termination by parsing all received output and firing
        any waiting Deferreds.
        N(R|RyR (RR6((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR8sN(
RRRR(RsRwtclassmethodR5RyRzR|RR8(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRnXs				
		tGetArgumentVectorcBseZdZdZdZRS(sl
    Protocol which will read a serialized argv from a process and
    expose it to interested parties.
    sLfrom sys import stdout, argv
stdout.write(chr(0).join(argv))
stdout.flush()
cCsdj|jdS(s
        Parse the output from the process to which this protocol was
        connected, which is a single unterminated line of \0-separated
        strings giving the argv of that process.  Return this as a list of
        str objects.
        R:t(tjointsplit(Rtchunks((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRys(RRRRsRy(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR~stGetEnvironmentDictionarycBseZdZdZdZRS(sx
    Protocol which will read a serialized environment dict from a process
    and expose it to interested parties.
    sfrom sys import stdout
from os import environ
items = environ.iteritems()
stdout.write(chr(0).join([k + chr(0) + v for k, v in items]))
stdout.flush()
cCsydj|}|siSt|jd}i}x>y|j}Wntk
r[Pq7X|j}|||<q7|S(s
        Parse the output from the process to which this protocol was
        connected, which is a single unterminated line of \0-separated
        strings giving key value pairs of the environment from that process.
        Return this as a dictionary.
        R:R(RtiterRtnextt
StopIteration(RRt
environStringtenvironR4tkRj((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRys

(RRRRsRy(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRstProcessTestCasecBseZdZeZdZdZdZdZdZ	dZ
dZdZd	Z
gid
ZdZdZd
ZRS(sTest running a process.c
stj}tjtd}ttj}_it	j
jtjd6}t
j||d|gd|dddjjjdjjdjjd	jjfd
}|j|S(stwisted.internet.stdio test.sprocess_twisted.pyt
PYTHONPATHs-uRotpathtusePTYshello, worldtabct123cs<jjjddjjjjfdS(Nshello, worldabc123sBOutput follows:
%s
Error message from process_twisted follows:
%s
(R"toutFtgetvalueterrF(tign(RR#(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR8sN(RpRqR	tsibpatht__file__tAccumulatorRRmt
endedDeferredRgtpathsepRRRRrR(RR>R?RRtaddCallback(RRvt
scriptPathR4RoR8((RR#s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt	testStdios		!
cstj}t|}tj}tjtd}tj	||||gddjjfd}|j
j|j|S(s
        Test if pid is None/non-None before/after process termination.  This
        reuses process_echoer.py to get a process that blocks on stdin.
        sprocess_echoer.pyRocsjjddS(N(R"tpidR((tignored(Rt	procTrans(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytafterProcessEndsN(RRmR0RpRqR	RRRRrR(t
failUnlessRR>RRR(RRSR#RvRR((RRs=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt
test_unsetPids	
cs~tj}tjtd}tj}t|_t	j
||d|gddfd}|j||S(sp
        Test running a process: check its output, it exitCode, some property of
        signalProcess.
        sprocess_tester.pys-uRocsjjdddddgj}|jtjj|jjdjtj	j
jdyFddl}ddl
}x'|j
|jD]}tj|qWWnnXdS(	NiiiiiitINTi(R"R<R6ttrapRR`RcRftassertRaisestProcessExitedAlreadyR>R]tprocess_testertglobttest_file_matchRgtremove(RtfRR(RR#(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRTs"	N(
RpRqR	RRRRmR9R1RRrR(R(RRvRR4RT((RR#s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_process
s			"
c
sfd}tj}tjtd}|d|g}g}g}xStdD]E}t}|j|tj	|||dd|j|jqRWtj
|dt}	|	j|||	S(Ncsx~|D]v}j|jdddddgdt|jt|jf|j}|jtjj|j	j
dqWdS(Niiiiis[%d] stages = %si(R"R<tidR>RVR6RRR`RcRf(tresultst	protocolsR#R(R(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt_check,s

A	sprocess_tester.pys-ui2Rot
consumeErrors(RpRqR	RRtxrangeRlRRRrR(R1RtDeferredListR\R(
RRRvRtargsRt	deferredsROR#tdeferredList((Rs=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttestManyProcesses*s		
cstj}t|tj}tjtd}tj	|||gddfd}fd}|j|j|S(s
        A spawning a subprocess which echoes its stdin to its stdout via
        C{reactor.spawnProcess} will result in that echoed output being
        delivered to outReceived.
        sprocess_echoer.pyRocsbjjjjtdjtdjjtjj	dS(NRNR:(
tfailIfRQRthasattrR"RPRRNRLRI(R(RR#(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytassertsRscsjj|S(N(R>RR(R=(R#(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttakedownProcessWs
N(
RRmRERpRqR	RRRRrR(Rt
addErrback(RRSRvRRR((RR#s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt	test_echoEs	c	sddddddddd	g	tj}tjtd
}ttj}_t	j
||d|gddd
dfd}|j|S(Nsa\"b sa\b s a\\"bs a\\bs"foo bar" "s	abs"\sa"bsa'bsprocess_cmdline.pys-uRoRcsBjjjdjjj}j|dS(NR:(R"RRRt
splitlines(Rt	recvdArgs(RRR#(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR8gs(
RpRqR	RRRRRmRRRrR(R(RtpyExeRR4R8((RRR#s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttestCommandLine^s!		%c	Cs=tj}tj}idd6idd6idd6idd6g}|dgd|dgg}d	}y|jtjWnLtk
r|jid
|6|ji|d6|j||gnXx9|D]1}|jt	t
j|||dd
gd|qWx0|D](}|jt	t
j|||ddq
WdS(s
        Test invalid arguments to spawnProcess: arguments and environment
        must only contains string or unicode, and not null bytes.
        itfooteggatbaritbarfootspamtfoobaru☃svalue for bad unicode keyskey for bad unicode values-cR:RoN(
RpRqRRtencodetgetdefaultencodingtUnicodeEncodeErrorRRt	TypeErrorRRrR((RRvR#tbadEnvstbadArgst
badUnicodeRoR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_wrongArgumentsns0	


	
	
&
uUNICODEtUNICODEcCsS|j|jjtj|j|jtdt|j	t
||}|jS(s
        Check that a deprecation warning is emitted when passing unicode to
        spawnProcess for an argv value or an environment key or value.
        Check that the warning is of the right type, has the right message,
        and refers to the correct file.  Unfortunately, don't check that the
        line number is correct, because that is too hard for me to figure
        out.

        @param processProtocolClass: A L{UtilityProcessProtocol} subclass
        which will be instantiated to communicate with the child process.

        @param argv: The argv argument to spawnProcess.

        @param env: The env argument to spawnProcess.

        @return: A Deferred which fires when the test is complete.
        sgArgument strings and environment keys/values passed to reactor.spawnProcess should be str, not unicode.(R"tokayUnicodeRRpRtencodedValuetassertWarnstDeprecationWarningRRwRRz(RtprocessProtocolClassRuRoR#((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt_deprecatedUnicodeSupportTests
	cs;jtdjg}fd}|j||S(s
        Test that a unicode string passed for an argument value is allowed
        if it can be encoded with the default system encoding, but that a
        deprecation warning is emitted.
        Rucsj|djgdS(Ns-c(R"R(Ru(R(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytgotArgVectors(RR~RR(RR4R((Rs=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt!test_deprecatedUnicodeArgvSupports
csBjtdijj6}fd}|j||S(s
        Test that a unicode string passed for the key of the environment
        dictionary is allowed if it can be encoded with the default system
        encoding, but that a deprecation warning is emitted.
        Rocsj|jjdS(N(R"R(R(R(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytgotEnvironments(RRRRR(RR4R((Rs=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt#test_deprecatedUnicodeEnvKeySupports

csBjtdijj6}fd}|j||S(s
        Test that a unicode string passed for the value of the environment
        dictionary is allowed if it can be encoded with the default system
        encoding, but that a deprecation warning is emitted.
        Rocsj|jjdS(N(R"R(R(R(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRs(RRRRR(RR4R((Rs=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt%test_deprecatedUnicodeEnvValueSupports

(RRRRYRRRRRRRRRRRRRR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRs							6 	
	tTwoProcessProtocolcBs/eZdZdZdZdZdZRS(iicCstj|_dS(N(RRmR1(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR5scCsdS(N((RR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRscCsd|_|jjddS(Ni(RSR1R7R((RR6((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR8s	(RRtnumRSR5RR8(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRs
		tTestTwoProcessesBasecBs8eZdZddZdZdZdZRS(cCs4ddg|_ddg|_d|_d|_dS(Ni(R(t	processestpptdonetverbose(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytsetUps	ic	Cstj}tjtd}xldD]d}t|j|<||j|_tj	|j|||d|gddd|}||j|<q"WdS(Nsprocess_reader.pyiis-uRoR(ii(RpRqR	RRRRRRRrR(R(RRRvRRR#((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytcreateProcessess	
	cCsy|jrd|GHn|j|}|j|}|j|jd|j|jru|jdjG|jdjGHndS(Nsclosing stdin [%d]sProcess finished too earlyii(RRRRRStloseConnection(RRR#R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytcloses	


	cCs&tjg|jD]}|j^qS(N(Rt
gatherResultsRR1(RR#((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt_onClosescCsQ|jrdGHn|jtjd|jdtjd|jd|jS(Nsstarting processesiii(RRRt	callLaterRR(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt	testCloses	
(RRRRRRR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRs
			tTestTwoProcessesNonPosixcBseZRS((RR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR$stTestTwoProcessesPosixcBs5eZdZdZdZdZdZRS(cCsjx]t|j|jD]F\}}|jsytj|jtjWq\t	k
rXq\XqqW|j
S(N(tzipRRRSRgtkillRRXtSIGTERMtOSErrorR(RRtpr((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttearDown(s"	
cCs|jrd|GHn|j|}|j|}|j|jdtj|jtj	|jr|jdjG|jdjGHndS(Nskill [%d] with SIGTERMsProcess finished too earlyii(
RRRRRSRgRRRXR(RRR#R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR3s	

	cCsW|jrdGHn|jddtjd|jdtjd|jd|jS(Nsstarting processesRiii(RRRRRR(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttestKill;s	cCsW|jrdGHn|jddtjd|jdtjd|jd|jS(Nsstarting processesRiii(RRRRRR(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttestClosePtyBs	cCsW|jrdGHn|jddtjd|jdtjd|jd|jS(Nsstarting processesRiii(RRRRRR(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttestKillPtyIs	(RRRRRRR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR's
				t	FDCheckercBsPeZdZdZdZdZdZdZdZ	dZ
dZRS(	iR:cCs
||_dS(N(R1(RR4((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR5UscCs||_|jjddS(N(tfailedR1R7R((Rtwhy((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytfailXs	cCs |jjddd|_dS(NiR;i(R>twriteToChildtstate(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR@\scCs|jdkr|dkr6|jd||fdS|j|7_t|jdkr|jdkr|jd|jdSd|_d|_|jjdd	dSn|jdkr|jd
||fdS|jdkrh|dkr
|jd||fdS|j|7_t|jdkrd|jdkrX|jd
|jdSd|_ndS|jdkr|jd||fdSdS(Nis)read '%s' on fd %d (not 1) during state 1itrightos"got '%s' on fd1, expected 'righto'R:iitefghs!read '%s' on fd %s during state 2s)read '%s' on fd %s (not 1) during state 3tcloseds"got '%s' on fd1, expected 'closed'is!read '%s' on fd %s during state 4(RRRRPR>R(RRAR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR!`sD						cCsu|jdkr$|jd|dS|jdkrq|dkrT|jd|dSd|_|jjddSdS(Nis%got connectionLost(%d) during state 1iis-got connectionLost(%d) (not 4) during state 2ii(RRR>tcloseChildFD(RRA((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR*s		cCs|jj}|jdkr0|jd|dS|jjdkr]|jd|jjdS|dkr~|jd|dS|jjddS(NisprocessEnded early, rc %dsprocessEnded with signal %sisprocessEnded with rc %d(RcRfRRRXR(R1R7(RRitrc((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR8sN(RRRRR(RR5RR@R!R*R8(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRPs				&	
tFDTestcBseZdZdZRS(cstj}tjtd}tj}t|tj	||d|gdddddidd6dd	6d
d
6dd6dd6dd
6|jfd|S(Nsprocess_fds.pys-uRoRtchildFDstwitriiiiicsjjjS(N(RR(tx(RR#(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt<lambda>s(RpRqR	RRRRmRRRrR(R(RRvRR4((RR#s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttestFDs	!cstj}tjtd}ttj}_t	j
||d|gdddddidd6dd6fd	}|j|S(
Nsprocess_linger.pys-uRoRRRiicsjjjddS(Nshere is some text
goodbye
(R"RR(R(RR#(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR8s(
RpRqR	RRRRRmRRRrR(R(RRvRR4R8((RR#s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt
testLingers		!(RRRR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRs	RcBsPeZdZdZdZdZdZdZdZ	dZ
dZRS(	sAccumulate data from a process.icCs"tj|_tj|_dS(N(tStringIORR(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR@scCs|jj|dS(N(RR?(RR4((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRscCs|jj|dS(N(RR?(RR4((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRscCsdS(N((R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRscCsdS(N((R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRscCs?d|_|jdk	r;|jd}|_|jdndS(Ni(RRR(R7(RR6R4((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR8s	N(RRRRR(RR@RRRRR8(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRs					tPosixProcessBasecBsweZdZeZdZdZdZdZdZ	dZ
dZdZd	Z
d
ZdZRS(s!
    Test running processes.
    cCsitjjd|fr)d|f}n<tjjd|frRd|f}ntd|f|S(sq
        Return the path of the shell command named C{commandName}, looking at
        common locations.
        s/bin/%ss/usr/bin/%ss %s not found in /bin or /usr/bin(RgRtexistsRC(RtcommandNametcmd((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt
getCommandscsojd}tj}t|tj|dgdddjfd}|j||S(NttrueRoRcsIjjtjjjjjdjjjjddS(Ni(	R6RRRUR"RcRfRXR((R(RR#(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRTs(	R
RRmR0RRrR(RR(RRR4RT((RR#s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttestNormalTerminations

csotj}tj}t|tj||ddgdddjfd}|j	||S(s
        When a process terminates with a system exit code set to 1,
        C{processEnded} is called with a L{error.ProcessTerminated} error,
        the C{exitCode} attribute reflecting the system exit code.
        s-csimport sys; sys.exit(1)RoRcsIjjtjjjjjdjjjjddS(Ni(	R6RRR`R"RcRfRXR((R(RR#(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRTsN(
RpRqRRmR0RRrR(RR(RRvR4RT((RR#s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_abnormalTerminations	
cCsetj}tjtd}tj}t||}tj	|||d|gddd|j|S(Nsprocess_signal.pys-uRoR(RpRqR	RRRRmRWRRrR(R(RR[RvRR4R#((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt_testSignals	!
cCs
|jdS(si
        Sending the SIGHUP signal to a running process interrupts it, and
        C{processEnded} is called with a L{error.ProcessTerminated} instance
        with the C{exitCode} set to C{None} and the C{signal} attribute set to
        C{signal.SIGHUP}. C{os.WTERMSIG} can also be used on the C{status}
        attribute to extract the signal value.
        tHUP(R(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_signalHUP!scCs
|jdS(si
        Sending the SIGINT signal to a running process interrupts it, and
        C{processEnded} is called with a L{error.ProcessTerminated} instance
        with the C{exitCode} set to C{None} and the C{signal} attribute set to
        C{signal.SIGINT}. C{os.WTERMSIG} can also be used on the C{status}
        attribute to extract the signal value.
        R(R(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_signalINT,scCs
|jdS(sk
        Sending the SIGKILL signal to a running process interrupts it, and
        C{processEnded} is called with a L{error.ProcessTerminated} instance
        with the C{exitCode} set to C{None} and the C{signal} attribute set to
        C{signal.SIGKILL}. C{os.WTERMSIG} can also be used on the C{status}
        attribute to extract the signal value.
        tKILL(R(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_signalKILL7scCs
|jdS(sk
        Sending the SIGTERM signal to a running process interrupts it, and
        C{processEnded} is called with a L{error.ProcessTerminated} instance
        with the C{exitCode} set to C{None} and the C{signal} attribute set to
        C{signal.SIGTERM}. C{os.WTERMSIG} can also be used on the C{status}
        attribute to extract the signal value.
        tTERM(R(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_signalTERMBscCsGtj}tj|tj}|jtjtj||jtjS(s
        The disposition of signals which are ignored in the parent
        process is reset to the default behavior for the child
        process.
        (RXtSIGUSR1tSIG_IGNt
addCleanupR(Rtwhichthandler((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_childSignalHandlingMs	csjd}tj}t|d}tj}|t_zHtj|dgdddj	fd}|j
|Wd|t_X|S(sJ
        Raise an error during execvpe to check error management.
        tfalsecSstddS(NtOuch(RC(tcommandRtenvironment((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytbuggyexecvpepsRoRcs=djjj}jd|jd|dS(NR:sUpon execvpeR (RR3R2tassertIn(RR3(RR#(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRTxsN(R
RRmR0RgtexecvpeRRrR(RR(RRR4R#t
oldexecvpeRT((RR#s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_executionErrorhs			

cstjtjtj}tjtd}dtjffdY}t	j
||||gddddgfd}j|fd}j|S(	s
        The handler which reaps a process is removed when the process is
        reaped, even if the protocol's C{processEnded} method raises an
        exception.
        sprocess_twisted.pytErrorInProcessEndedcs,eZdZfdZfdZRS(sM
            A protocol that raises an error in C{processEnded}.
            csj|dS(N(R7(RR>(t	connected(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytmakeConnectionscs&tjdjdtddS(NisDeliberate error(RRR7R(RC(RR6(tended(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR8s(RRRR*R8((R+R)(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR(sRoRcs4j|jj|jtj|jdS(N(RRR$RtreapProcessHandlersR(R>(RR(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytcbConnectedscs@jt}jt|djdtjdS(Nii(tflushLoggedErrorsRCR"RPtassertNotInRR,(Rtexcs(RR(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytcheckTerminatedsN(
RRmRpRqR	RRRRRRrR(R(RtpythonExecutableRR(R-R1((RRR+R)s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_errorInProcessEndeds	"	


(RRRRYRR
RRRRRRRRR'R3(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR	s				
						t
MockSignalcBs eZdZdZdZRS(sF
    Neuter L{signal.signal}, but pass other attributes unscathed
    cCs
tj|S(N(RXt	getsignal(RR[taction((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRXscCs
tt|S(N(ReRX(Rtattr((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt__getattr__s(RRRRXR8(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR4s	tMockOScBsjeZdZeZeZd"ZeZ	d"Z
d"Zd"ZdZ
dZd"ZdZdZdZdZdZdZdZd	Zd
ZdZdZd
ZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-d Z.d!Z/RS(#sh
    The mock OS: overwrite L{os}, L{fcntl} and {sys} functions with fake ones.

    @ivar exited: set to True when C{_exit} is called.
    @type exited: C{bool}

    @ivar O_RDWR: dumb value faking C{os.O_RDWR}.
    @type O_RDWR: C{int}

    @ivar O_NOCTTY: dumb value faking C{os.O_NOCTTY}.
    @type O_NOCTTY: C{int}

    @ivar WNOHANG: dumb value faking C{os.WNOHANG}.
    @type WNOHANG: C{int}

    @ivar raiseFork: if not C{None}, subsequent calls to fork will raise this
        object.
    @type raiseFork: C{NoneType} or C{Exception}

    @ivar raiseExec: if set, subsequent calls to execvpe will raise an error.
    @type raiseExec: C{bool}

    @ivar fdio: fake file object returned by calls to fdopen.
    @type fdio: C{StringIO.StringIO}

    @ivar actions: hold names of some actions executed by the object, in order
        of execution.

    @type actions: C{list} of C{str}

    @ivar closed: keep track of the file descriptor closed.
    @param closed: C{list} of C{int}

    @ivar child: whether fork return for the child or the parent.
    @type child: C{bool}

    @ivar pipeCount: count the number of time that C{os.pipe} has been called.
    @type pipeCount: C{int}

    @ivar raiseWaitPid: if set, subsequent calls to waitpid will raise an
        the error specified.
    @type raiseWaitPid: C{None} or a class

    @ivar waitChild: if set, subsequent calls to waitpid will return it.
    @type waitChild: C{None} or a tuple

    @ivar euid: the uid returned by the fake C{os.geteuid}
    @type euid: C{int}

    @ivar egid: the gid returned by the fake C{os.getegid}
    @type egid: C{int}

    @ivar seteuidCalls: stored results of C{os.seteuid} calls.
    @type seteuidCalls: C{list}

    @ivar setegidCalls: stored results of C{os.setegid} calls.
    @type setegidCalls: C{list}

    @ivar path: the path returned by C{os.path.expanduser}.
    @type path: C{str}
    icCsdg|_g|_d|_d|_d|_d|_d|_d|_g|_g|_	dS(s-
        Initialize data structures.
        iiiicSsdS(Ni((R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRscSsdS(Ni((R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRsN(
tactionsRt	pipeCounttO_RDWRtO_NOCTTYtWNOHANGtWEXITSTATUSt	WIFEXITEDtseteuidCallstsetegidCalls(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR5
s							cCsdS(se
        Fake C{os.open}. Return a non fd number to be sure it's not used
        elsewhere.
        i((Rtdevtflags((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytopenscCs
tjdS(sT
        Fake C{os.fstat}.  Return a C{os.stat_result} filled with garbage.
        ii
(i(
iiiiiiiiii(Rgtstat_result(Rtfd((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytfstat"scCstj|_|jS(sy
        Fake C{os.fdopen}. Return a StringIO object whose content can be tested
        later via C{self.fdio}.
        (Rtfdio(RRGtflag((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytfdopen)scCsdS(s0
        Fake C{os.setsid}. Do nothing.
        N((R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytsetsid2scCsL|jjdtjf|jdk	r7|jn|jrDdSdSdS(s
        Fake C{os.fork}. Save the action in C{self.actions}, and return 0 if
        C{self.child} is set, or a dumb number.
        tforkiiN(R:Rtgct	isenabledt	raiseForkR(tchild(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRM8s	cCs|jj|dS(sK
        Fake C{os.close}, saving the closed fd in C{self.closed}.
        N(RR(RRG((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRGscCsdS(s.
        Fake C{os.dup2}. Do nothing.
        N((Rtfd1tfd2((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytdup2NscCsdS(s/
        Fake C{os.write}. Do nothing.
        N((RRGR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR?TscCs,|jjd|jr(tdndS(sn
        Fake C{os.execvpe}. Save the action, and raise an error if
        C{self.raiseExec} is set.
        texectBarN(R:Rt	raiseExecRC(RR!RRo((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR%Zs	cCs+|jd7_d|jdd|jfS(s
        Fake C{os.pipe}. Return non fd numbers to be sure it's not used
        elsewhere, and increment C{self.pipeCount}. This is used to uniquify
        the result.
        ii(R;(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytpipedscCsdS(s;
        Fake C{os.ttyname}. Return a dumb string.
        R((RRG((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytttynamenscCs&|jjdt|_tdS(ss
        Fake C{os._exit}. Save the action, set the C{self.exited} flag, and
        raise C{SystemError}.
        texitN(R:RR\texitedtSystemError(Rtcode((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt_exitus	cCsdS(s6
        Override C{fcntl.ioctl}. Do nothing.
        N((RRGRDtarg((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytioctlscCsdS(s?
        Override C{fdesc.setNonBlocking}. Do nothing.
        N((RRG((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytsetNonBlockingscCsE|jjd|jdk	r+|jn|jdk	rA|jSdS(s
        Override C{os.waitpid}. Return values meaning that the child process
        has exited, save executed action.
        twaitpidiiN(ii(R:RtraiseWaitPidR(t	waitChild(RRtoptions((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRbscCsdS(sD
        Override C{sys.settrace} to keep coverage working.
        N((RR_((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytsettracescCsdS(s>
        Override C{os.getgid}. Return a dumb number.
        i((R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytgetgidscCsdS(s>
        Override C{os.getuid}. Return a dumb number.
        i((R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytgetuidscCs|jjd|fdS(s4
        Override C{os.setuid}. Do nothing.
        tsetuidN(R:R(Rtval((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRiscCs|jjd|fdS(s4
        Override C{os.setgid}. Do nothing.
        tsetgidN(R:R(RRj((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRkscCs|jjd||fdS(s6
        Override C{os.setregid}. Do nothing.
        tsetregidN(R:R(Rtval1tval2((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRlscCs|jjd||fdS(s<
        Override C{os.setreuid}.  Save the action.
        tsetreuidN(R:R(RRmRn((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRoscCs|jjd||fdS(s>
        Override C{util.switchuid}. Save the action.
        t	switchuidN(R:R(Rtuidtgid((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt	switchUIDscCsdS(sK
        Override C{pty.openpty}, returning fake file descriptors.
        ii(ii((R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytopenptyscCs|jS(sE
        Mock C{os.geteuid}, returning C{self.euid} instead.
        (teuid(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytgeteuidscCs|jS(sE
        Mock C{os.getegid}, returning C{self.egid} instead.
        (tegid(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytgetegidscCs|jj|dS(s3
        Mock C{os.seteuid}, store result.
        N(RAR(RRw((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytseteuidscCs|jj|dS(s3
        Mock C{os.setegid}, store result.
        N(RBR(RRw((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytsetegidscCs|jS(s-
        Mock C{os.path.expanduser}.
        (R(RR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt
expanduserscCsdS(s'
        Mock C{pwd.getpwnam}.
        iii(iiii((Rtuser((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytgetpwnamscCsdS(sN
        Override C{os.listdir}, returning fake contents of '/dev/fd'
        s-1s-2(s-1s-2((RR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytlistdirsN(0RRRRYR[RWR(RIR\RQRcRPRdRuRwRR5RERHRKRLRMRRTR?R%RXRYR^R`RaRbRfRgRhRiRkRlRoRsRtRvRxRyRzR{R}R~(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR9sV=											
	
					
															tDumbProcessWritercBseZdZdZRS(sA
        A fake L{process.ProcessWriter} used for tests.
        cCsdS(sD
            Here's the faking: don't do anything here.
            N((R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytstartReadings(RRRR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR
stDumbProcessReadercBseZdZdZRS(sA
        A fake L{process.ProcessReader} used for tests.
        cCsdS(sD
            Here's the faking: don't do anything here.
            N((R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRs(RRRR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRstDumbPTYProcesscBseZdZdZRS(s>
        A fake L{process.PTYProcess} used for tests.
        cCsdS(sD
            Here's the faking: don't do anything here.
            N((R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR's(RRRR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR"stMockProcessTestCasecBseZdZedkr!dZndZdZdZdZ	dZ
dZdZd	Z
d
ZdZdZd
ZdZdZdZdZdZdZdZdZdZdZdZRS(s?
    Mock a process runner to test forked child code path.
    s1twisted.internet.process is never used on WindowscCs,tjr|jtjn|jtjt|_d|j_d|j_|j	t
d|j|j	t
d|j|j	t
d|j|j	t
d|jj|j	t
d|j|j	t
jdt
|j	t
jd	t|j	t
d
|jt|_|j	t
d|jdS(
s|
        Replace L{process} os, fcntl, sys, switchUID, fdesc and pty modules
        with the mock class L{MockOS}.
        iiRgtfcntlRpRstfdesctprocessReaderFactorytprocessWriterFactorytptyRXN(RNRORtenabletdisableR9tmockosRuRwtpatchRRstProcessRRR4tmocksig(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR5s cCs
it_dS(s6
        Reset processes registered for reap.
        N(RR,(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRNscCstjd}tj}t|}y&tj||dgdd	dtWnIt	k
r|j
|jj|j
|jjdtfddgnX|jd|jtjd	S(
sk
        Test a classic spawnProcess. Check the path of the client code:
        fork, exec, exit.
        s
/mock/ouchtouchRoRRMRURZsShould not be hereN(RNRRRmR0RRrR(RYR\tassert_RR[R"R:RtassertFalseRO(RRR4R#((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt
test_mockForkUs

#
cCst|j_d}tj}t|}tj||dgdd
dt|j	t
|jjt
dddg|j	|jjdtfd	gd
S(s
        Assert that in the main process, spawnProcess disables the garbage
        collector, calls fork, closes the pipe file descriptors it created for
        the child process, and calls waitpid.
        s
/mock/ouchRRoRiiiRMRbN(
RYRRQRRmR0RRrR(R"RRR:(RRR4R#((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt_mockForkInParentTestns+cCs+tj|j|jtjdS(s
        The garbage collector should be enabled when L{reactor.spawnProcess}
        returns if it was initially enabled.

        @see L{_mockForkInParentTest}
        N(RNRRt
assertTrueRO(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt,test_mockForkInParentGarbageCollectorEnableds

cCs+tj|j|jtjdS(s
        The garbage collector should be disabled when L{reactor.spawnProcess}
        returns if it was initially disabled.

        @see L{_mockForkInParentTest}
        N(RNRRRRO(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt-test_mockForkInParentGarbageCollectorDisableds

cCsd}tj}t|}y&tj||dgdd	dtWnItk
r|j|j	j
|j|j	jdt
fddgnX|jdd	S(
sg
        Test a TTY spawnProcess: check the path of the client code:
        fork, exec, exit.
        s
/mock/ouchRRoRRMRURZsShould not be hereN(RRmR0RRrR(R\R\RRR[R"R:RYR(RRR4R#((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_mockForkTTYs
#cCs`ttjd|j_td}|jttj	|d|j
|jjdtfgdS(s
        Assert that if the fork call fails, no other process setup calls are
        made and that spawnProcess raises the exception fork raised.
        RMN(
RterrnotEAGAINR(RRPR0RRRrR"R:RY(RR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt_mockWithForkErrorscCs+tj|j|jtjdS(s
        The garbage collector should be enabled when L{reactor.spawnProcess}
        raises because L{os.fork} raised, if it was initially enabled.
        N(RNRRRRO(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt-test_mockWithForkErrorGarbageCollectorEnableds

cCs+tj|j|jtjdS(s
        The garbage collector should be disabled when
        L{reactor.spawnProcess} raises because L{os.fork} raised, if it was
        initially disabled.
        N(RNRRRRO(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt.test_mockWithForkErrorGarbageCollectorDisableds

c	CsB|j|jt|jjtddddddgdS(s}
        When C{os.fork} raises an exception, the file descriptors created
        before are closed and don't leak.
        iiiiiiN(RR"RRR(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_mockForkErrorCloseFDss
c	Csttjd|j_td}|jttj	|ddidd6dd6dd6|j
|jjdtfg|j
|jj
g|jttj	|ddid	d6dd6dd6|j
t|jj
td
dgdS(
s
        When C{os.forks} raises an exception and that file descriptors have
        been specified with the C{childFDs} arguments of
        L{reactor.spawnProcess}, they are not closed.
        RiiiiiiRMRiiN(RRRR(RRPR0RRRrR"R:RYRR(RR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_mockForkErrorGivenFDsscCsttjd|j_td}|jttj	|ddt
|j|jjdt
fg|jt|jjtddgdS(s
        When C{os.fork} raises an exception, the file descriptors created by
        C{pty.openpty} are closed and don't leak, when C{usePTY} is set to
        C{True}.
        RRMiiN(RRRR(RRPR0RRRrR\R"R:RYRR(RR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_mockForkErrorClosePTYsc	Cs|ttjd|j_td}|jttj	|ddd|j
|jjdtfg|j
|jj
gdS(s
        If a tuple is passed to C{usePTY} to specify slave and master file
        descriptors and that C{os.fork} raises an exception, these file
        descriptors aren't closed.
        RiiRRMN(iisfoo(RRRR(RRPR0RRRrR"R:RYR(RR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_mockForkErrorPTYGivenFDsscCsd}tj}t|}t|j_y&tj||dgdd
dt	Wnt
k
r|j|jj|j
|jjdt	fddg|jd|jj|jd	|jj|jd
|jj|jd|jjjnX|jdd
S(s
        Spawn a process but simulate an error during execution in the client
        path: C{os.execvpe} raises an error. It should close all the standard
        fds, try to print the error encountered, and exit cleanly.
        s
/mock/ouchRRoRRMRURZiiisRuntimeError: BarsShould not be hereN(RRmR0R\RRWRRrR(RYR\RR[R"R:R$RRIRR(RRR4R#((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_mockWithExecErrors 
 c
Csd}tj}t|}y,tj||dgdddtddWnRtk
r|j|j	j
|j|j	jddd
tfdd
dgnX|j
ddS(s
        Try creating a process with setting its uid: it's almost the same path
        as the standard path, but with a C{switchUID} call before the exec.
        s
/mock/ouchRRoRRqiRiiRkRMRpiRURZsShould not be hereN(ssetuidi(ssetgidi(s	switchuidii(RRmR0RRrR(RYR\RRR[R"R:R(RRR4R#((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_mockSetUid s
c
Cst|j_d}tj}t|}tj||dgdddtdd|j	|jj
ddd
tfdddgdS(s
        Try creating a process with setting its uid, in the parent path: it
        should switch to root before fork, then restore initial uid/gids.
        s
/mock/ouchRRoRRqiRiiRkRMRliiRoiiRbN(ssetuidi(ssetgidi(ssetregidii(ssetreuidii(RYRRQRRmR0RRrR(R"R:(RRR4R#((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_mockSetUidInParent5s
c
Csd}tj}t|}y,tj||dgdddtddWnRtk
r|j|j	j
|j|j	jddd
t
fdd
dgnX|jddS(s
        Try creating a PTY process with setting its uid: it's almost the same
        path as the standard path, but with a C{switchUID} call before the
        exec.
        s
/mock/ouchRRoRRqiRiiRkRMRpiRURZsShould not be hereN(ssetuidi(ssetgidi(s	switchuidii(RRmR0RRrR(R\R\RRR[R"R:RYR(RRR4R#((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_mockPTYSetUidFs
c
Cst|j_d}tj}t|}tj}z5tt_t	j
||dgdddtddWd|t_X|j
|jjdddtfdddgdS(s
        Try creating a PTY process with setting its uid, in the parent path: it
        should switch to root before fork, then restore initial uid/gids.
        s
/mock/ouchRRoRRqiNRiiRkRMRliiRoiiRb(ssetuidi(ssetgidi(ssetregidii(ssetreuidii(RYRRQRRmR0Rt
PTYProcessRRRrR(R\R"R:(RRR4R#t
oldPTYProcess((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_mockPTYSetUidInParent\s		
cCst|j_d}d
|j_tj}t|}tj||dgdd	dt}|j
|jjdtfdgt|j_
|j|j}|j
t|d|djtd	S(s;
        Test that reapProcess logs errors raised.
        s
/mock/ouchiRRoRRMRbiN(ii(RYRRQRdRRmR0RRrR(R"R:RRctreapProcessR.RPR(RRR4R#tprocterrors((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_mockWithWaitErrorrs	"
cCst|j_d}d	|j_tj}t|}tj||dgdddt}|j
|jjdtfdgt|j_
tj|jj
_|jdS(
s{
        Test that reapProcess doesn't log anything when waitpid raises a
        C{OSError} with errno C{ECHILD}.
        s
/mock/ouchiRRoRRMRbN(ii(RYRRQRdRRmR0RRrR(R"R:RRcRtECHILDR(RRR4R#R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt!test_mockErrorECHILDInReapProcesss	"csddddgfd}||j_td}|jttj|d|j|jj	g|jt
|jjt
ddddgdS(s
        If C{os.pipe} raises an exception after some pipes where created, the
        created pipes are closed and don't leak.
        iiiicsAy jdjdfSWntk
r<tnXdS(Ni(tpopt
IndexErrorR((tpipes(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRXs 
N(RRXR0R(RRRRrR"R:RR(RRXR((Rs=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_mockErrorInPipesc	Csrttjd
|j_td
}|jttj	|d
dd|j
|jjdddtfddgd
S(s
        If C{os.fork} raises an exception and a UID change has been made, the
        previous UID and GID are restored.
        RqiRiiRkRMRliiRoiiN(ssetuidi(ssetgidi(ssetregidii(ssetreuidii(
RRRR(RRPR0RRRrR"R:RY(RR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_mockErrorInForkRestoreUIDsN(RRRRR(tskipRRRRRRRRRRRRRRRRRRRRRRR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR.s4										
														tPosixProcessTestCasecBseZdZdZRS(c
stj}dttj}_tj||ddfgdd	dddj	fd}|j
|S(
s
        Bytes written to stderr by the spawned process are passed to the
        C{errReceived} callback on the C{ProcessProtocol} passed to
        C{spawnProcess}.
        t42s-cs"import sys; sys.stderr.write('%s')RoRs/tmpRcsjjjdS(N(R"RR(R(RRcR#(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR8sN(RpRqRRRmRRRrR(RR(RRR4R8((RRcR#s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_stderrs		
c
sjd}ddttj}_tj||dgdddddjj	j
j	jfd	}|j|S(
Ntgzipsthere's no place like home!
is-cRoRs/tmpRcsEj}|jddtjd|}j|jdS(Nitfileobj(RtseekRtGzipFileR"tread(RRtgf(R#RRL(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR8s	(
R
RRRmRRRrR(RR>R?RRR(RRR4R8((RR#RLs=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttestProcesss
	$

(RRRR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRs	tPosixProcessTestCasePTYcBs&eZdZeZdZdZRS(sH
    Just like PosixProcessTestCase, but use ptys instead of pipes.
    c
stj}tjtd}ttj}_t	j
||d|gdddddjj
jdfd}|j|S(Nsprocess_tty.pys-uRoRRs
hello world!
csIjtjjjdjjjddjjdS(NRshello world!
hello world!
s-Error message from process_tty follows:

%s

(RRRR>R]R"RR(R(RR#(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR8s(RpRqR	RRRRRmRRRrR(RR>R?R(RRvRR4R8((RR#s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttestOpeningTTYs		!cCsWtj}|dddg}t}|jttj|||dddidd6dS(Ns-us-cs
print 'hello'RiRR(RpRqRRRbRRr(RRtpyArgsR#((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttestBadArgs	s
		(RRRR\RRR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRs	tWin32SignalProtocolcBseZdZdZRS(s
    A win32-specific process protocol that handles C{processEnded}
    differently: processes should exit with exit code 1.
    cCs{|jtjs/|jjtd|fS|j}|jdkrg|jjtd|jfS|jjddS(s
        Callback C{self.deferred} with C{None} if C{reason} is a
        L{error.ProcessTerminated} failure with C{exitCode} set to 1.
        Otherwise, errback with a C{ValueError} describing the problem.
        swrong termination: %sisWrong exit code: %sN(
RTRR`R1RaRbRcRfR7R((RR6Rj((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR8s			(RRRR8(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRstWin32ProcessTestCasecBsMeZdZdZdZdZdZdZdZdZ	RS(s?
    Test process programs that are packaged with twisted.
    cstj}tjtd}ttj}_t	j
||d|gddddjj
djjfd}|j|S(Nsprocess_stdinreader.pys-uRoRshello, worldcs6jjjdjjjddS(Nserr
err
sout
hello, world
out
(R"RRR(R(RR#(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR88s(RpRqR	RRRRRmRRRrR(R>R?RRR(RRRR4R8((RR#s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttestStdinReader.s		!
c
Cstj}|dddg}t}|jttj|||dd|jttj|||dd|jttj|||dd|jttj|||did	d6dS(
Ns-us-cs
print 'hello'RqiRrRRR(RpRqRRRbRRr(RRRR#((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR>s						cCs\tj}tjtd}tj}t||}tj	|||d|gdd|S(Nsprocess_signal.pys-uRo(RpRqR	RRRRmRRRrR((RR[RvRR4R#((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRLs	"cCs
|jdS(s
        Sending the SIGTERM signal terminates a created process, and
        C{processEnded} is called with a L{error.ProcessTerminated} instance
        with the C{exitCode} attribute set to 1.
        R(R(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRUscCs
|jdS(s
        Sending the SIGINT signal terminates a created process, and
        C{processEnded} is called with a L{error.ProcessTerminated} instance
        with the C{exitCode} attribute set to 1.
        R(R(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR^scCs
|jdS(s
        Sending the SIGKILL signal terminates a created process, and
        C{processEnded} is called with a L{error.ProcessTerminated} instance
        with the C{exitCode} attribute set to 1.
        R(R(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRgscsddltjtjdtjffdY}|}tj}|dddg}tj|||fd}j	|fd	}j	|tj
gS(
sU
        The win32 handles should be properly closed when the process exits.
        iNtSimpleProtocolcs,eZdZfdZfdZRS(sZ
            A protocol that fires deferreds when connected and disconnected.
            csj|dS(N(R7(RR>(R)(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR*}scsjddS(N(R7R((RR6(R+(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR8s(RRRR*R8((R+R)(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRyss-us-cs
print 'hello'csLj|jjjjj_j_dS(N(tassertIdenticaltGetHandleInformationthProcessthThread(R>(RRtwin32api(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR-s
csujjdjjdjjdjjjjjjjjdS(N(RRR(RRRRR(R(RRR(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR1s(RRRmRRRpRqRRrRR(RRR#RRR-R1((RR+R)RRs=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_closeHandlesps"
		


(
RRRRRRRRRR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR)s										tWin32UnicodeEnvironmentTestcBs#eZdZdZdZdZRS(s2
    Tests for Unicode environment on Windows
    uUNICODEcsfjtjj<jtjtjjtjt	gi}fd}|j
j|S(s
        Test C{os.environ} (inherited by every subprocess on Windows) that
        contains an ascii-encodable Unicode string. This is different from
        passing Unicode environment explicitly to spawnProcess (which is not
        supported).
        cs0j|jjdjjddS(Ntascii(R"tgoodKeyRt	goodValue(R(R(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRs(RRgRRRtoperatortdelitemRRwRRzR(RR#R((Rs=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt test_encodableUnicodeEnvironments
(RRRRRR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRstDumbwin32procPidTestcBseZdZdZRS(s@
    Simple test for the pid attribute of Process on win32.
    c
sddlm}ddlm}j|d|tj}tjt	d}t
j}t|}t
tjd}|d||g}|jt|d|idjdjjd	tfd
}	|j|	S(s
        Launch process with mock win32process. The only mock aspect of this
        module is that the pid of the process created will always be 42.
        i(t_dumbwin32proc(tmock_win32processtwin32processsprocess_cmdline.pytCOMSPECs/ci*s<Process pid=42>csjdjdS(N(R"R(R(R{(R#R(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt
pidCompleteCbsN(ttwisted.internetRttwisted.testRRRpRqR	RRRRmR0RVRgRRRR(R"RRDR(
RRRRvRR4tprocessPrototcomspecRR((RR#s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_pids&			(RRRR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRstUtilTestCasecBs;eZdZdZdZdZdZdZRS(s\
    Tests for process-related helper functions (currently only
    L{procutils.which}.
    cCstjj}|j}||d|_||d|_||jd|_||jd|_||jd|_||jd|_	x3|j|j|j|j	fD]}tj
|qWx||jddf||jddf||jddf||jddf||j	ddfgD]5\}}t|d}|jtj
||q6Wtjjd	d
|_tjj|j|j|j|j	ftjd	<d
S(s
        Create several directories and files, some of which are executable
        and some of which are not.  Save the current PATH setting.
        RtbazRRqisexecutable.biniRtPATHN(RgRRtmktempRRtfoobartfoobaztbazfootbazbartmakedirstfileRtchmodRtgetR(toldPathR(RtjtbaseR4tnametmodeR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRs*%%
	cCsmtjtjj|jdtj|jdkrYytj	d=Wqit
k
rUqiXn|jtj	d<dS(s
        Restore the saved PATH setting, and set all created files readable
        again so that they can be deleted easily.
        RqRN(RgRRRRtstattS_IWUSRRR(RtKeyError(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR	s%
cCs'tjd=|jtjdgdS(s}
        Test that if C{os.environ} does not have a C{'PATH'} key,
        L{procutils.which} returns an empty list.
        RRqN(RgRR"RR(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_whichWithoutPATH	s
cCs~tjj}tjd}||jd||jdg}tjj	rj|j
||jdn|j||dS(NRq(
RgRRRRRRR
tplatformt	isWindowsRRR"(RRtpathst
expectedPaths((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt	testWhich	scCstjj}tjjdd}tjjdtjd<ztjd}Wd|dkritjd=n
|tjd<X||j	d||j
d||j
dg}tjj
r|j||jdn|j||dS(NtPATHEXTs.bins.exes.shRqsexecutable.bin(s.bins.exes.sh(RgRRRRR(RRRRRR
RRRRR"(RRtoldRR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttestWhichPathExt)	s
(RRRRRRRR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRs	!				
tClosingPipesProcessProtocolcBs8eZdZdZdZdZdZdZRS(R:cCstj|_||_dS(N(RRmR1toutOrErr(RR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR5A	scCs|jj|dS(N(R1R7(RR6((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR8E	scCs|j|7_dS(N(toutput(RR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRH	scCs|j|7_dS(N(terrput(RR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRK	s(RRRRR5R8RR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR=	s			tClosingPipescBs,eZdZdZdZdZRS(cCstt}|j|jtj|jj|j|tj	|t
jt
jddd|fgdd|dkr|j
jn"|dkr|j
jnt|j
jd|j
j|jS(	s
        Create a child process and close one of its output descriptors using
        L{IProcessTransport.closeStdout} or L{IProcessTransport.closeStderr}.
        Return a L{Deferred} which fires after verifying that the descriptor was
        really closed.
        s-us-cssraw_input()
import sys, os, time
for i in range(1000):
    os.write(%d, "foo\n")
    time.sleep(0.01)
sys.exit(42)
Roiisgo
N(RR\t
assertFailureR1RR`Rt_endProcessRRrRpRqR(R>tcloseStdouttcloseStderrRCR?RR(RRGR#((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pytdoitR	s"		

cCs4|j|jdd||j|jd|jS(so
        Check that a failed write prevented the process from getting to its
        custom exit code.
        i*sprocess reason was %rR:(tassertNotEqualsRfR"RR(RR6R#((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR{	scs/jd}fd}|j||S(sQ
        ProcessProtocol.transport.closeStdout actually closes the pipe.
        ics<jd|tjjdkr8jd|ndS(NRtwin32sBroken pipe(R$R
RtgetType(R(R(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR	s(RR(RR4R((Rs=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyttest_stdout	s
cs/jd}fd}|j||S(sQ
        ProcessProtocol.transport.closeStderr actually closes the pipe.
        icsj|ddS(NR:(R"(R(R(s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR	s(RR(RR4R((Rs=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyR	s
(RRRRRR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyRP	s	)		
s9wrong platform or reactor doesn't support IReactorProcesstposixR(MRRRgRpRXRRRNRRRtImportErrorR(RRtzope.interface.verifyRttwisted.python.logRRRRRRt
twisted.trialRttwisted.pythonR	R
Rttwisted.python.compatRRR
tTestCaseRR0R9RERWRlRnR~RRRRRRRRRR	tobjectR4R9t
ProcessWriterRt
ProcessReaderRRRRRRRRRRRRRtskipMessageRRtIReactorProcessR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_process.pyt<module>s
(Y.%I
L$$)Q!I-(z$\Q(			(