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_internet.pyc


=Nc@sdZddlZddlZddlZddlmZddlmZmZm	Z	m
Z
mZddlmZm
Z
yddlmZWnek
reZnXeoejreZnddlmZmZddlmZmZd	ejfd
YZdejfdYZd
ejfdYZdejfdYZdejfdYZdZdejfdYZ dejfdYZ!ej"eerde!_#ndejfdYZ$dej%fdYZ&dej'fdYZ(dejfd YZ)d!e*fd"YZ+d#e
j,fd$YZ-d%e+fd&YZ.d'ejfd(YZ/d)ejfd*YZ0dS(+sB
Tests for lots of functionality provided by L{twisted.internet}.
iN(tunittest(treactortprotocolterrortabstracttdefer(t
interfacestbase(tssl(tDeferredt
maybeDeferred(tutiltruntimetThreePhaseEventTestscBseZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZdZdZdZdZdZdZRS(sQ
    Tests for the private implementation helpers for system event triggers.
    cCs+d|_t|_tj|_dS(sR
        Create a trigger, an argument, and an event to be used by tests.
        cSsdS(N(tNone(tx((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt<lambda>$sN(ttriggertobjecttargRt_ThreePhaseEventtevent(tself((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytsetUp scCs)|jt|jjd|j|jdS(st
        L{_ThreePhaseEvent.addTrigger} should raise L{KeyError} when called
        with an invalid phase.
        txxxN(tassertRaisestKeyErrorRt
addTriggerRR(R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttest_addInvalidPhase)scCsK|jjd|j|j|j|jj|j|jfifgdS(s
        L{_ThreePhaseEvent.addTrigger} should accept C{'before'} as a phase, a
        callable, and some arguments and add the callable with the arguments to
        the before list.
        tbeforeN(RRRRtassertEqualR(R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttest_addBeforeTrigger3s	cCsK|jjd|j|j|j|jj|j|jfifgdS(s
        L{_ThreePhaseEvent.addTrigger} should accept C{'during'} as a phase, a
        callable, and some arguments and add the callable with the arguments to
        the during list.
        tduringN(RRRRRR (R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttest_addDuringTrigger?s	cCsK|jjd|j|j|j|jj|j|jfifgdS(s
        L{_ThreePhaseEvent.addTrigger} should accept C{'after'} as a phase, a
        callable, and some arguments and add the callable with the arguments to
        the after list.
        tafterN(RRRRRR"(R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttest_addAfterTriggerKs	cCsH|jjd|j|j}|jj||j|jjgdS(s
        L{_ThreePhaseEvent.removeTrigger} should accept an opaque object
        previously returned by L{_ThreePhaseEvent.addTrigger} and remove the
        associated trigger.
        RN(RRRRt
removeTriggerRR(Rthandle((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttest_removeTriggerWscCs |jt|jjtdS(s
        L{_ThreePhaseEvent.removeTrigger} should raise L{ValueError} when given
        an object not previously returned by L{_ThreePhaseEvent.addTrigger}.
        N(Rt
ValueErrorRR$R(R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttest_removeNonexistentTriggerbscCsK|jjd|j|j}|jj||jt|jj|dS(s
        L{_ThreePhaseEvent.removeTrigger} should raise L{ValueError} the second
        time it is called with an object returned by
        L{_ThreePhaseEvent.addTrigger}.
        RN(RRRRR$RR'(RR%((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttest_removeRemovedTriggerjscCs2|jt|jjd|j|jfifdS(s
        L{_ThreePhaseEvent.removeTrigger} should raise L{ValueError} if it is
        given a trigger handle which resembles a valid trigger handle aside
        from its phase being incorrect.
        RN(RRRR$RR(R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttest_removeAlmostValidTriggerusc	Csg}|jjd|jd|jjd|jd|jjd|jd	|jjd|jd
|jjd|jd|jjd|jd|j|g|jj|j|d
dddddgdS(s
        L{_ThreePhaseEvent.fireEvent} should call I{before}, I{during}, and
        I{after} phase triggers in that order.
        R"tfirstR RtsecondN(R+safter(R+sduring(R+sbefore(R,sbefore(R,sduring(R,safter(R+sbefore(R,sbefore(R+sduring(R,sduring(R+safter(R,safter(RRtappendRt	fireEvent(Rtevents((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttest_fireEvents
	csg}t|jjdfd|jjd|jd|jjd|jd|j|g|jj|j|gjd|j|ddgdS(s
        L{_ThreePhaseEvent.fireEvent} should wait for any L{Deferred} returned
        by a I{before} phase trigger before proceeding to I{during} events.
        RcsS(N(((tbeforeResult(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRsR R"N(R	RRR-RR.tcallbackR(RR/((R1s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttest_asynchronousBefores	

csg}dtfdYfd}|jjd||jjd|jd|jjd|jd|jj|j|ddg|j}|jt|ddS(s
        If a before-phase trigger raises a synchronous exception, it should be
        logged and the remaining triggers should be run.
        tDummyExceptioncBseZRS((t__name__t
__module__(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyR4scs
dS(N(((R4(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytraisingTriggersRR iN(t	ExceptionRRR-R.RtflushLoggedErrorstlen(RR/R7terrors((R4s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttest_beforeTriggerExceptions
csg}dtfdYfd}|jjd||jjd|jd|jjd|jd|jj|j|ddg|j}|jt|ddS(s
        If a during-phase trigger raises a synchronous exception, it should be
        logged and the remaining triggers should be run.
        R4cBseZRS((R5R6(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyR4scs
dS(N(((R4(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyR7sR R"iN(R8RRR-R.RR9R:(RR/R7R;((R4s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttest_duringTriggerExceptions
csg}fd}jjd|jdjjd|jjd|jdjtdtjjj|d	d
gdS(s
        If a before-phase trigger tries to remove another before-phase trigger
        which has already run, a warning should be emitted.
        csjjdS(N(RR$((RtbeforeHandle(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyR$sRR+R,sdRemoving already-fired system event triggers will raise an exception in a future version of Twisted.N(sfirstsbefore(ssecondsbefore(sfirstsbefore(ssecondsbefore(RRR-tassertWarnstDeprecationWarningt__file__R.R(RR/R$((RR>s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt+test_synchronousRemoveAlreadyExecutedBefores
cs}g}jjdfdjjd|jdjjd|jdjjj|dgdS(	s
        If a before-phase trigger removes another before-phase trigger which
        has not yet run, the removed trigger should not be run.
        RcsjjS(N(RR$((RR>(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRsR+R,N(sfirstsbefore(ssecondsbefore(ssecondsbefore(RRR-R.R(RR/((RR>s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt#test_synchronousRemovePendingBefores		
cs}g}jjdfdjjd|jdjjd|jdjjj|dgdS(s
        If a before-phase trigger removes a during-phase trigger, the
        during-phase trigger should not be run.
        RcsjjS(N(RR$((RtduringHandle(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRsR R"N(RRR-R.R(RR/((RRDs>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt#test_synchronousBeforeRemovesDurings	
csg}t|jjdfd|jjd|jd}|jjd|jd|jj|jj|jd|j|dgdS(s
        If a before-phase trigger returns a L{Deferred} and later removes a
        during-phase trigger before the L{Deferred} fires, the during-phase
        trigger should not be run.
        RcsS(N(((R1(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRsR R"N(	R	RRR-R.R$R2RR(RR/RD((R1s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt$test_asynchronousBeforeRemovesDurings	

csgfd}jjd|jjdfdjjd|jjjdgdS(s
        If a before-phase trigger removes a during-phase trigger which is
        identical to an already-executed before-phase trigger aside from their
        phases, no warning should be emitted and the during-phase trigger
        should not be run.
        csjddS(NR(R-((R/(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRsRcsjjS(N(RR$((Rt
duringTrigger(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyR#sR RN(RRR.R(RR((RRGR/s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt7test_synchronousBeforeRemovesConspicuouslySimilarDurings	
cs}g}jjdfdjjd|jdjjd|jdjjj|dgdS(	s
        If a during-phase trigger removes another during-phase trigger which
        has not yet run, the removed trigger should not be run.
        R csjjS(N(RR$((RRD(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyR0sR+R,N(sfirstsduring(ssecondsduring(ssecondsduring(RRR-R.R(RR/((RRDs>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt#test_synchronousRemovePendingDuring)s			
cCsg}|jjd|jd|jjd|jd|jjd|jd|jj|jj|j|dddgdS(sm
        A trigger should only be called on the first call to
        L{_ThreePhaseEvent.fireEvent}.
        RR R"N(RRR-R.R(RR/((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttest_triggersRunOnce9s

cskgfd}jjdjdjjd|jjjddgdS(s
        The temporary list L{_ThreePhaseEvent.finishedBefore} should be emptied
        and the state reset to C{'BASE'} before the first during-phase trigger
        executes.
        cs=jdjjjgjjjddS(NR tBASE(R-RRtfinishedBeforetstate((RR/(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRGNs
RR N(RRR-R.R(RRG((RR/s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt"test_finishedBeforeTriggersClearedGs
(R5R6t__doc__RRRR!R#R&R(R)R*R0R3R<R=RBRCRERFRHRIRJRN(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyR
s,			
																		tSystemEventTestCasecBseZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZdZdZRS(s
    Tests for the reactor's implementation of the C{fireSystemEvent},
    C{addSystemEventTrigger}, and C{removeSystemEventTrigger} methods of the
    L{IReactorCore} interface.

    @ivar triggers: A list of the handles to triggers which have been added to
        the reactor.
    cCs
g|_dS(sI
        Create an empty list in which to store trigger handles.
        N(ttriggers(R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRbscCsNxG|jrI|jj}ytj|Wqttfk
rEqXqWdS(sA
        Remove all remaining triggers from the reactor.
        N(RQtpopRtremoveSystemEventTriggerR'R(RR((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttearDowniscCs)tj|||}|jj||S(sS
        Add a trigger to the reactor and remember it in C{self.triggers}.
        (RtaddSystemEventTriggerRQR-(RRtphasetfunctt((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRuscCs!tj||jj|dS(sd
        Remove a trigger by its handle from the reactor and from
        C{self.triggers}.
        N(RRSRQtremove(RR((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyR$~s
csbd}gfd}|j||||jgtj||jdgdS(NttestcsjddS(N(R-R((R/(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRs(RRRtfireSystemEventR(RRVt	eventTypeR((R/s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt_addSystemEventTriggerTests
cCs|jddS(s
        L{IReactorCore.addSystemEventTrigger} should accept the C{'before'}
        phase and not call the given object until the right event is fired.
        RN(R](R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttest_beforePhasescCs|jddS(s
        L{IReactorCore.addSystemEventTrigger} should accept the C{'during'}
        phase and not call the given object until the right event is fired.
        R N(R](R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttest_duringPhasescCs|jddS(s
        L{IReactorCore.addSystemEventTrigger} should accept the C{'after'}
        phase and not call the given object until the right event is fired.
        R"N(R](R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttest_afterPhasescCs)d}|jt|jd|ddS(s
        L{IReactorCore.addSystemEventTrigger} should reject phases other than
        C{'before'}, C{'during'}, or C{'after'}.
        RZRcSsdS(N(R(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRsN(RRR(RR\((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttest_unknownPhasescsd}gfd}fd}|jd|||jd|||jgtj||jddgdS(s
        L{IReactorCore.addSystemEventTrigger} should call triggers added to the
        C{'before'} phase before it calls triggers added to the C{'during'}
        phase.
        RZcsjddS(NR(R-((R/(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt
beforeTriggerscsjddS(NR (R-((R/(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRGsRR N(RRRR[(RR\RbRG((R/s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttest_beforePreceedsDurings
csd}gfd}fd}|jd|||jd|||jgtj||jddgdS(s
        L{IReactorCore.addSystemEventTrigger} should call triggers added to the
        C{'during'} phase before it calls triggers added to the C{'after'}
        phase.
        RZcsjddS(NR (R-((R/(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRGscsjddS(NR"(R-((R/(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytafterTriggersR R"N(RRRR[(RR\RGRd((R/s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttest_duringPreceedsAfters
cstd}gfd}fd}|jd|||jd|||jgtj||jgjd|jdgdS(s
        If a trigger added to the C{'before'} phase of an event returns a
        L{Deferred}, the C{'during'} phase should be delayed until it is called
        back.
        RZcsS(N(((ttriggerDeferred(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRbscsjddS(NR (R-((R/(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRGsRR N(R	RRRR[R2R(RR\RbRG((RfR/s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttest_beforeReturnsDeferreds	

csttd}gfd}fd}fd}|jd|||jd|||jd|||jgtj||jgjd|jgjd|jdgdS(s
        If more than one trigger added to the C{'before'} phase of an event
        return L{Deferred}s, the C{'during'} phase should be delayed until they
        are all called back.
        RZcsS(N(((t
firstDeferred(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytfirstBeforeTriggerscsS(N(((tsecondDeferred(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytsecondBeforeTriggerscsjddS(NR (R-((R/(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRGsRR N(R	RRRR[R2R(RR\RiRkRG((RhRjR/s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt!test_multipleBeforeReturnDeferreds"		


csd}gttfd}fd}fd}fd}|jd|||jd|||jd|||jd|||jgtj||jdgjd|jddgdS(	sa
        If a trigger added to the C{'before'} phase of an event calls back a
        L{Deferred} returned by an earlier trigger in the C{'before'} phase of
        the same event, the remaining C{'before'} triggers for that event
        should be run and any further L{Deferred}s waited on before proceeding
        to the C{'during'} events.
        RZcsS(N(((Rh(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRiscsjddS(N(R2R((Rh(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRkscsjdS(NR(R-((RjR/(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytthirdBeforeTriggers
csjddS(NR (R-((R/(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRGsRR N(R	RRRR[R2R(RR\RiRkRmRG((RhRjR/s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt4test_subsequentBeforeTriggerFiresPriorBeforeDeferreds"		

csd}gfd}fd}|jd|||j|jd|||jgtj||jdgdS(s
        A trigger removed with L{IReactorCore.removeSystemEventTrigger} should
        not be called when the event fires.
        RZcsjddS(NR+(R-((R/(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRi3scsjddS(NR,(R-((R/(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRk5sRR+N(RR$RRR[(RR\RiRk((R/s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttest_removeSystemEventTrigger,s
cCs|jddd}|j||jttjd|jttj||jttj|dd|ddfdS(	sM
        Passing an object to L{IReactorCore.removeSystemEventTrigger} which was
        not returned by a previous call to
        L{IReactorCore.addSystemEventTrigger} or which has already been passed
        to C{removeSystemEventTrigger} should result in L{TypeError},
        L{KeyError}, or L{ValueError} being raised.
        R RZcSsdS(N(R(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRGsiRiN(sxxx(	RR$Rt	TypeErrorRRSRR'R(Rtb((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt(test_removeNonExistentSystemEventTrigger?s
csXgd}tfd}fd}d}tfd}fd}|jd|||jd|||jd|||jd|||jgtj||jdgtj||jd
dgjd|jdddgjd|jddddgdS(s
        L{IReactorCore.fireSystemEvent} should behave the same way for a
        particular system event regardless of whether Deferreds are being
        waited on for a different system event.
        sfirst-eventcsjdS(NRR+(sbeforesfirst(R-((RhR/(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytbeforeFirstEvent]s
csjddS(NR"R+(saftersfirst(R-((R/(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytafterFirstEvent`sssecond-eventcsjdS(NRR,(sbeforessecond(R-((RjR/(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytbeforeSecondEventes
csjddS(NR"R,(safterssecond(R-((R/(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytafterSecondEventhsRR"R+R,N(sbeforesfirst(sbeforesfirst(sbeforessecond(sbeforesfirst(sbeforessecond(saftersfirst(sbeforesfirst(sbeforessecond(saftersfirst(safterssecond(R	RRRR[R2R(Rt
firstEventRsRttsecondEventRuRv((RhRjR/s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt&test_interactionBetweenDifferentEventsSs0		




(R5R6RORRTRR$R]R^R_R`RaRcReRgRlRnRoRrRy(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRPYs$											
					 		tTimeTestCasecBseZdZdZdZdZdZdZdZdZ	dZ
d	Zd
Zde_
de_d
Zde_
de_dZdZRS(s9
    Tests for the IReactorTime part of the reactor.
    cCs(tj}|j||||dS(sN
        L{twisted.internet.reactor.seconds} should return something
        like a number.

        1. This test specifically does not assert any relation to the
           "system time" as returned by L{time.time} or
           L{twisted.python.runtime.seconds}, because at some point we
           may find a better option for scheduling calls than
           wallclock-time.
        2. This test *also* does not assert anything about the type of
           the result, because operations may not return ints or
           floats: For example, datetime-datetime == timedelta(0).
        N(RtsecondsR(Rtnow((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttest_secondsscCsUtj}dt_z/tjdd}|j|jdWd|t_XdS(s
        L{reactor.callLater} should use the reactor's seconds factory
        to produce the time at which the DelayedCall will be called.
        cSsdS(Nid((((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRsicSsdS(N(R(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRsiiN(RR{t	callLaterRtgetTime(Rtosecondstcall((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt-test_callLaterUsesReactorSecondsInDelayedCalls	cCsUtj}dt_z/tjdd}|j|jdWd|t_XdS(s
        L{reactor.callLater} should propagate its own seconds factory
        to the DelayedCall to use as its own seconds factory.
        cSsdS(Nid((((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRsicSsdS(N(R(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRsidN(RR{R~R(RRR((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt;test_callLaterUsesReactorSecondsAsDelayedCallSecondsFactorys	cCs6t}tjd|jd|j|jd|S(sc
        Test that a DelayedCall really calls the function it is
        supposed to call.
        iN(R	RR~R2RtaddCallbackR(Rtd((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttest_callLaters	cslgfd}tjd|}|jtfd}tjdtjd|S(sL
        Test that when a DelayedCall is cancelled it does not run.
        csjddS(N(R-R((tcalled(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytfunctionsics9yjgWnjnXjddS(N(RterrbackR2R((RRR(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytchecks
(RR~tcancelR	(RRRR((RRRs>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttest_cancelDelayedCalls
	cCs9tjdd}|j|jtj|jdS(s
        Test that cancelling a DelayedCall which has already been cancelled
        raises the appropriate exception.
        icSsdS(N(R(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRsN(RR~RRRtAlreadyCancelled(RR((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttest_cancelCancelledDelayedCalls
cs4tfd}tjd|S(s
        Test that cancelling a DelayedCall in the DelayedCall's function as
        that function is being invoked by the DelayedCall raises the
        appropriate exception.
        cs?yjtjjWnjnXjddS(N(RRt
AlreadyCalledRRR2R((RRR(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytlaters
i(R	RR~(RR((RRRs>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt'test_cancelCalledDelayedCallSynchronouss	csCtfdfd}tjd|S(s|
        Test that cancelling a DelayedCall after it has run its function
        raises the appropriate exception.
        cs?yjtjjWnjnXjddS(N(RRRRRR2R((RRR(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRs
cstjddS(Ni(RR~((R(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyR	si(R	RR~(RR((RRRRs>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt(test_cancelCalledDelayedCallAsynchronouss
	cCsRtjdd}z+|j|jtjddkWd|jXdS(Ni
cSsdS(N(R(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRsi(RR~t
failUnlessRttimeR(RR((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttestCallLaterTimes+csggfd}fd}fd}fd}x'tdD]}tjd||q[Wx>tdD]0}tjd||dtjd||qWtjd|tjd|t}tjd|jd|S(	Ncsj|dS(N(R-(R(tl(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytfscsj|dS(N(R-(R(tl2(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytf2scsjtddS(Ni(Rtrange((RR(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytdonescsjtddS(Ni
(RR((RR(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytdone2si
ig?g?(RRR~R	R2R(RRRRRtnR((RRRs>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttestCallLaterOrders 	sSee bug 1396s*Trial bug, todo doesn't work! See bug 1397csUd}tjtj|t_|t_fd}t|jj|S(NcSsttjS(N(tintR(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyR{4scst_t_|S(N(RR{R(R(truntime_originalt
base_original(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytcleanup<s		(RR{RR
RtaddBoth(RR{R((RRs>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttestCallLaterOrder20s					cstjdddddtjdtjttjdddidd	6d
ftgtdtjtfd}tj|}tjd|jdt|S(NicSsdS(N(R(Rty((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRHsRRi
icSsdS(N(R(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyROsuworldthelloy$@cstdS(N(tstr(tignored(tdc(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt
calledBackTs(
RR~RtresetRRR	RR2R(RRR((Rs>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttestDelayedCallStringificationEs




7



cCspd}tjddd	idd|}|j|jd|jd|j|jddS(
s
        Test that the C{seconds} argument to DelayedCall gets used instead of
        the default timing function, if it is not None.
        cSsdS(Ni
((((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyR{asicSsdS(N(R(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRcscSsdS(N(R(R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRcscSsdS(N(R(R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRdsii
N((RtDelayedCallRRR(RR{R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttestDelayedCallSecondsOverride\s	
(R5R6ROR}RRRRRRRRRttodotskipRRR(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRzs$						
										tCallFromThreadTestscBsYeZdZejeddkr3de_ndZdZ	dZ
dZRS(cs)tfd}tj|S(Ncs$tjdtjjddS(Ng?(RtsleepRtcallFromThreadR2R((R(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytwakens
(R	RtcallInThread(RR((Rs>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt
testWakeUpks	
s-Nothing to wake up for without thread supportcCs
t|_dS(N(tTruetstopped(R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt_stopCallFromThreadCallbackxscCs*tj|j|tjd|jdS(Ni(RRt_callFromThreadCallback2R~R(RR((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt_callFromThreadCallback{scCs9y|j|jWn|jnX|jddS(N(tassert_RRR2R(RR((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRs
cCs,t|_tj}tj|j||S(s
        Ensure that callFromThread from inside a callFromThread
        callback doesn't sit in an infinite loop and lets other
        things happen too.
        (tFalseRRR	RRR(RR((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttestCallFromThreadStopss	N(R5R6RRtIReactorThreadsRRRRRRR(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRjs	
				tDelayedTestCasecBsYeZdZdZdZdZdZdZdZdZ	dZ
RS(	cCs.d|_d|_i|_tj|_dS(Ni(tfinishedtcounterttimersRR	tdeferred(R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRs			cCs(x!|jjD]}|jqWdS(N(RtvaluesR(RRX((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRTscCs|jj}ttj}g}x*|D]"}||kr.|j|q.q.W|rfd|_n|j|dt|dS(Nis7Should have been missing no calls, instead was missing (	RRtlistRtgetDelayedCallsR-RtfailIftrepr(Rtl1RtmissingR((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytcheckTimerss
cCs|j|=|jdS(N(RR(Rttag((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyR2s
cCs$|j||jd|jdS(Ni(R2taddTimer(RR((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRs
cCs*d|_|j||jjddS(Ni(RR2RR(RR((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRs	
cCsCtj|d||j|j|j<|jd7_|jdS(Ng{Gz?i(RR~RRR(RtwhenR2((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRscsttdsdSjjdjjdjjdjj}jdjjdjjdjj|j	j|=jj
jfdj
S(	NRi#iiiiics
jS(N(R(R(R(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRs(thasattrRRRRR2RRRRR(Rtwhich((Rs>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttestGetDelayedCallss
	

csZtjdjjtjjtfd}jj|jS(sM
        L{IDelayedCall.active} returns False once the call has run.
        g{Gz?csjjt|S(N(RtactiveR(tsuccess(tdcallR(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytcheckDeferredCalls(RR~RR2RRRR(RR((RRs>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttest_actives
(R5R6RRTRR2RRRRR(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRs								s
import %(reactor)s
%(reactor)s.install()
from twisted.internet import reactor

class Foo:
    def __init__(self):
        reactor.callWhenRunning(self.start)
        self.timer = reactor.callLater(3, self.failed)
    def start(self):
        reactor.resolve('localhost').addBoth(self.done)
    def done(self, res):
        print 'done', res
        reactor.stop()
    def failed(self):
        print 'failed'
        self.timer = None
        reactor.stop()
f = Foo()
reactor.run()
tChildResolveProtocolcBs5eZdZdZdZdZdZRS(cCs
||_dS(N(tonCompletion(RR((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt__init__scCsg|_g|_dS(N(toutputR(R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytconnectionMades	cCs|jj|dS(N(RR-(Rtout((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytoutReceivedscCs|jj|dS(N(RR-(Rterr((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyterrReceivedscCs,|jj||j|jfd|_dS(N(RR2RRR(Rtreason((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytprocessEndeds(R5R6RRRRR(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRs
				tResolvecBseZdZRS(cstjjj}t|d}tj}|jti|d6|j	tj
j}tjj
tj|d<t}t|}tj|tjdd|f|fd}|j||S(NtwRt
PYTHONPATHtpythons-ucsZ|\}}}dj|}|dkrVjd|j|dj|fndS(Ntsdone 127.0.0.1
sThe child process failed to produce the desired results:
   Reason for termination was: %r
   Output stream was: %r
   Error stream was: %r
(tjointfailtgetErrorMessage(t.0RRR(R(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt
cbFinished)s(tostpathtabspathtmktemptopenRR6twritetresolve_helpertclosetenvirontcopytpathsepRtsysR	RtspawnProcesst
executableR(Rt
helperPatht
helperFiletreactorNametenvthelperDeferredthelperProtoR((Rs>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttestChildResolves	
	"
(R5R6R(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRss8cannot run test: reactor doesn't support IReactorProcesstCallFromThreadTestCasecBs\eZdZejeddkr-dZndZdZ	dZ
dZdZRS(s-
    Task scheduling from threads tests.
    s&Nothing to test without thread supportcCsd|_t|_dS(Ni(RR	R(R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRCs	cOstj||dS(s)
        Override in subclasses.
        N(RR(Rtargstkwargs((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytscheduleHscs:fd}x!tdD]}j|qWjS(s
        L{IReactorThreads.callFromThread} can be used to schedule a large
        number of calls in the reactor thread.
        cs5jd7_jdkr1jjtndS(Niid(RRR2R((R(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytaddAndMaybeFinishTsid(txrangeRR(RRti((Rs>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt'test_lotsOfThreadsAreScheduledCorrectlyOscsgfd}jj|jjdjjdjjdjtjjjdjS(sO
        Callbacks should be invoked in the order they were scheduled.
        csjdddgdS(Niii(R(t_(Rtorder(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyResiiiN(RRRR-RRR2R(RR((RRs>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt"test_threadsAreRunInScheduledOrder_scs6fd}j|jjdjS(sU
        Scheduled tasks should not be run until the reactor starts running.
        csd_jjtdS(Ni(RRR2R((R(s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytincAndFinishus	i(RRRR(RR
((Rs>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt+test_scheduledThreadsNotRunUntilReactorRunsqs
N(
R5R6RORRRRRRRR	RR(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyR<s					t
MyProtocolcBseZdZRS(s
    Sample protocol.
    (R5R6RO(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRst	MyFactorycBseZdZeZRS(s
    Sample factory.
    (R5R6RORR(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRstProtocolTestCasecBseZdZRS(cCsHt}|jd}|j|j||jt||jdS(N(Rt
buildProtocolRRtfactoryRt
isinstanceR(RRR((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttestFactorys	(R5R6R(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRst
DummyProducercBs2eZdZdZdZdZdZRS(s
    Very uninteresting producer implementation used by tests to ensure the
    right methods are called by the consumer with which it is registered.

    @type events: C{list} of C{str}
    @ivar events: The producer/consumer related events which have happened to
    this producer.  Strings in this list may be C{'resume'}, C{'stop'}, or
    C{'pause'}.  Elements are added as they occur.
    cCs
g|_dS(N(R/(R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRscCs|jjddS(Ntresume(R/R-(R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytresumeProducingscCs|jjddS(Ntstop(R/R-(R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt
stopProducingscCs|jjddS(Ntpause(R/R-(R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytpauseProducings(R5R6RORRRR(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRs
				tSillyDescriptorcBs2eZdZdZeZdZdZeZRS(s
    A descriptor whose data buffer gets filled very fast.

    Useful for testing FileDescriptor's IConsumer interface, since
    the data buffer fills as soon as at least four characters are
    written to it, and gets emptied in a single doWrite() cycle.
    icCs
t|S(s(
        Always write all data.
        (R:(Rtdata((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt
writeSomeDatascCsdS(s1
        Do nothing: bypass the reactor.
        N((R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pytstartWritings(	R5R6ROt
bufferSizeRt	connectedRR tstopWriting(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRs		tReentrantProducercBs eZdZdZdZRS(s
    Similar to L{DummyProducer}, but with a resumeProducing method which calls
    back into an L{IConsumer} method of the consumer against which it is
    registered.

    @ivar consumer: The consumer with which this producer has been or will
    be registered.

    @ivar methodName: The name of the method to call on the consumer inside
    C{resumeProducing}.

    @ivar methodArgs: The arguments to pass to the consumer method invoked in
    C{resumeProducing}.
    cGs2tt|j||_||_||_dS(N(tsuperR$Rtconsumert
methodNamet
methodArgs(RR&R'R(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRs		cCs3tt|jt|j|j|jdS(N(R%R$RtgetattrR&R'R((R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyRs(R5R6RORR(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyR$s	tTestProducercBsVeZdZdZdZdZdZdZdZdZ	dZ
RS(	s<
    Test abstract.FileDescriptor's consumer interface.
    cCsdtj}d|_t}|j|d|j|jdg|jt|jtddS(s
        Verify that registering a non-streaming producer invokes its
        resumeProducing() method and that you can only register one producer
        at a time.
        iiRN(	RtFileDescriptorR"RtregisterProducerRR/RtRuntimeError(Rtfdtdp((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttest_doubleProducers		cCsHtj}d|_t}|j|d|j|jdgdS(s
        Verify that registering a producer when the connection has already
        been closed invokes its stopProducing() method.
        iiRN(RR+tdisconnectedRR,RR/(RR.R/((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttest_unconnectedFileDescriptors
		cCslt}t}|j|dt|j|jdg|j2t||d|j|jgdS(Nt	streamingRt1234(RRR,RRR/R)(RR't
descriptortproducer((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt_dontPausePullConsumerTests		cCs
|jdS(s
        Verify that FileDescriptor does not call producer.pauseProducing() on a
        non-streaming pull producer in response to a L{IConsumer.write} call
        which results in a full write buffer. Issue #2286.
        R(R7(R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt!test_dontPausePullConsumerOnWritescCs
|jdS(s@
        Like L{test_dontPausePullConsumerOnWrite}, but for a call to
        C{writeSequence} rather than L{IConsumer.write}.

        C{writeSequence} is not part of L{IConsumer}, but
        L{abstract.FileDescriptor} has supported consumery behavior in response
        to calls to L{writeSequence} forever.
        t
writeSequence(R7(R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt)test_dontPausePullConsumerOnWriteSequences	cCst}t||d}|j|dtt||d|j|jdg|j2|j|j|jddg|j2|j|j|jddgdS(NtspamR3RR(RR$R,RR)RR/tdoWrite(RR'R5R6((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt_reentrantStreamingProducerTest*s	

cCs
|jdS(s
        Verify that FileDescriptor tracks producer's paused state correctly.
        Issue #811, fixed in revision r12857.
        R(R=(R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt)test_reentrantStreamingProducerUsingWriteGscCs
|jdS(s/
        Like L{test_reentrantStreamingProducerUsingWrite}, but for calls to
        C{writeSequence}.

        C{writeSequence} is B{not} part of L{IConsumer}, however
        C{abstract.FileDescriptor} has supported consumery behavior in response
        to calls to C{writeSequence} forever.
        R9(R=(R((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt1test_reentrantStreamingProducerUsingWriteSequenceOs	(R5R6ROR0R2R7R8R:R=R>R?(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyR*s								tPortStringificationcBs}eZejeddk	r*dZnejeddk	rNdZnej	eddk	r{e
r{e
dZnRS(cCsctjdtj}|jj}|jt|jt|dd||f|j	S(Niis%d not found in %s(
Rt	listenTCPRt
ServerFactorytgetHosttporttassertNotEqualRtfindt
stopListening(RtptportNo((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttestTCP^s
!cCsctjdtj}|jj}|jt|jt|dd||f|j	S(Niis%d not found in %s(
Rt	listenUDPRtDatagramProtocolRCRDRERRFRG(RRHRI((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttestUDPfs
!cCstjtd}tjdtj|j||}|jj	}|j
t|jt|dd||f|j
S(Ns
server.pemiis%d not found in %s(RtsibpathRARt	listenSSLRRBtDefaultOpenSSLContextFactoryRCRDRERRFRG(RRtpemRHRI((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyttestSSLns'!N(R5R6RtIReactorTCPRRRJtIReactorUDPRMtIReactorSSLRRR(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyR@\s(1RORRRt
twisted.trialRttwisted.internetRRRRRRRRtImportErrorRt	supportedttwisted.internet.deferR	R
ttwisted.pythonRRtTestCaseR
RPRzRRRtProcessProtocolRRtIReactorProcessRRtProtocolRtFactoryRRRRR+RR$R*R@(((s>/usr/lib/python2.7/dist-packages/twisted/test/test_internet.pyt<module>sF(

	>1*j$E	s