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


H7Nc@s\dZddlZddlZddlmZddlmZmZddlm	Z	ddl
mZmZddl
mZdefd	YZd
ejfdYZdejfd
YZdejfdYZdejfdYZdejfdYZdejfdYZdejfdYZdejfdYZdS(s
Test cases for defer module.
iN(tunittest(treactortdefer(tClock(tfailuretlog(t
unsignedIDtGenericErrorcBseZRS((t__name__t
__module__(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRstDeferredTestCasecBseZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!d Z"d!Z#d"Z$d#Z%d$Z&d%Z'd&Z(d'Z)d(Z*d)Z+d*Z,d+Z-d,Z.d-Z/d.Z0d/Z1d0Z2d1Z3d2Z4d3Z5d4Z6d5Z7RS(6cCs8d|_d|_d|_|jtjtjdS(N(tNonetcallbackResultsterrbackResultstcallback2Resultst
addCleanupRtsetDebuggingtgetDebugging(tself((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pytsetUps			cOs||f|_|dS(Ni(R(Rtargstkw((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt	_callbackscOs||f|_dS(N(R(RRR((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt
_callback2"scOs||f|_dS(N(R
(RRR((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt_errback%scCsYtj}|j|j|jd|j|jd|j|jdifdS(Nthello(R(	RtDeferredtaddCallbackRtcallbacktassertEqualR
RR(Rtdeferred((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttestCallbackWithoutArgs(s

cCs\tj}|j|jd|jd|j|jd|j|jdifdS(NtworldR(shellosworld(	RRRRRRR
RR(RR((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttestCallbackWithArgs/s

cCsftj}|j|jdd|jd|j|jd|j|jdidd6fdS(NR R(shello(	RRRRRRR
RR(RR((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttestCallbackWithKwArgs6s
cCstj}|j|j|j|j|jd|j|jd|j|j	dif|j|j
difdS(NR(shello(shello(RRRRRRRR
RRR(RR((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttestTwoCallbacks>s

cCs	tj}tj}tj}tj|||g}g}|d}d}|j|||jd|j||jtd|jd|j|d|ddt	|ddj
f|dgtjdftjdftjdfgdS(	NcSs|j|dS(N(textend(t
resultListtresult((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pytcbOscSsdS(N(R(terr((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pytcatchQst1t2t3iii(
RRtDeferredListtaddCallbacksRt
addErrbackterrbackRRtstrtvaluetSUCCESStFAILURE(Rtdefr1tdefr2tdefr3tdlR&R'R)((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttestDeferredListIs$	



"
cCs~g}|d}tjg}|j||j|ggg|(tjgdd}|j||j|gdS(NcSs|j|dS(N(tappend(R%R&((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyR'istfireOnOneCallbacki(RR-R.R(RR&R'R8((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttestEmptyDeferredListgs

c	Cs6tj}tj}tj}tj|||gdd}g}|j|jd}|j||jd|j|g|jtd|jt	|d|d}|j
t|jtj
d|jf|j}|j|jjt|j|jjjd|j|jddS(	NtfireOnOneErrbackicSsdS(N(R(R(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyR)sR*s	from def2isHissubclass(aFailure.type, defer.FirstError) failed: failure's type is %r(s	from def2(RRR-R/R:RRR0Rtlent
failUnlesst
issubclassttypet
FirstErrorR2t
subFailureRtindex(	RR5R6R7R8R&R)taFailuret
firstError((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttestDeferredListFireOnOneErrorus(	


	cCstj}tj|g}g}|j|jg}|j|j|jtd|jd|dj	j
d|jdt||jd|dddj	j
ddS(NtBangii(RRR-R/R:RR0RRR2RR>(Rtd1R8t	errorTrapR&((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt!testDeferredListDontConsumeErrorsscCstj}tj|gdt}g}|j|jg}|j|j|jtd|j	g||j	dt
||j	d|dddjjddS(Nt
consumeErrorsRHii(
RRR-tTrueR/R:RR0RRR>R2R(RRIR8RJR&((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttestDeferredListConsumeErrorsscCstj}tj}|jtdtj||gdt}g}|j|j|jdt	||jddS(NRHR=icSsdS(N(R(te((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt<lambda>s(
RRR0RR-RMR/R:RR>(RRItd2R8R&((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt7testDeferredListFireOnOneErrorWithAlreadyFiredDeferredsscCstj}tj}|jtd|jdtj||g}g}|j|j|jdt	||j
ddS(NRHiicSsdS(N(R(RO((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRPs(RRR0RRR-RR:RR>R/(RRIRQR8R&((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt)testDeferredListWithAlreadyFiredDeferredss
cCs<g}tjd}|j|j|j|dgdS(Ntsuccess(RtsucceedRR:R(Rtltd((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttestImmediateSuccessscCsLg}tjtd}|j|j|jt|djddS(Ntfaili(RRYRR/R:RR1R2(RRVRW((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttestImmediateFailurescCspg}tjtd}|j|j|j|j|g|j|jt|dj	ddS(NRYi(
RRYRtpauseR/R:RtunpauseR1R2(RRVRW((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttestPausedFailures

cCsg}tjjdj|j}|jd|jt|djt	g}tjjdj|j}|jd|jt|djt	dS(NcSsddS(Nii((t_((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRPsiicSstjtS(N(RtFailuretZeroDivisionError(R^((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRPs(
RRRR/R:Rtassert_t
isinstanceR2R`(RRVRW((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttestCallbackErrorss$

cCs4tj}|j|j|j|jdS(N(RRR[RRR\(RRW((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttestUnpauseBeforeCallbacks
cCstj}tj}|j|j|d|j|j|jd|jdksmtd|jd|jdkstd|j	|jdddkstd|jfdS(NcSs|S(N((trRQ((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRPsis Should not have been called yet.is&Still should not have been called yet.is/Result should have been from second deferred:%s(
RRR[RRRRRtAssertionErrorR\(RRWRQ((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttestReturnDeferreds



cst}tjj|jtj}|jfd|jdg}|j|j|j|gj	|j||gdS(s
        When a paused Deferred with a result is returned from a callback on
        another Deferred, the other Deferred is chained to the first and waits
        for it to be unpaused.
        csS(N((tignored(tpaused(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRPsN(
tobjectRRRR[RRR:RR\(RtexpectedtchainedR&((Ris;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt$test_chainedPausedDeferredWithResults	



cstj}tj|jfd|jd|jjdg}j|j|j|dgdS(s
        A paused Deferred encountered while pushing a result forward through a
        chain does not prevent earlier Deferreds from continuing to execute
        their callbacks.
        csS(N((Rh(tsecond(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRP-sN(RRRRRR[R:R(RtfirstR&((Rns;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_pausedDeferredChained%s


cCsg}tjtjdtjdgj|j|j|ddggg}tjdtjtg}tj|j|j|jt	|d|j
t|dtj
|djddS(NiiicSsdS(Ni((RO((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRPBs(Rt
gatherResultsRURR:RRYt
ValueErrorR/R>RaRbRR_(RRVR8((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_gatherResults6s1cCstjd}tjtd}tj||gdt}g}|j|jg}|j|j|jt	|t	|fd|j
|djtj|djj
}|j
|jtdS(s
        If a L{Deferred} in the list passed to L{gatherResults} fires with a
        failure and C{consumerErrors} is C{True}, the failure is converted to a
        C{None} result on that L{Deferred}.
        isoh noesRLiN(ii(RRURYtRuntimeErrorRqRMR/R:RR>tassertIsInstanceR2RBRC(RtdgoodtdbadRWtunconsumedErrorstgatheredErrorsRF((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt#test_gatherResultsWithConsumeErrorsEscCs_gg}}tjdd}|j|j|j|j|g|j|dg|S(s
        L{defer.maybeDeferred} should retrieve the result of a synchronous
        function and pass it to its resulting L{defer.Deferred}.
        cSs|dS(Ni((tx((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRPasi
i(Rt
maybeDeferredR.R:R(RtStERW((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_maybeDeferredSync[s
cCsgg}}yddWntk
r:}t|}nXtjdd}|j|j|j|j|g|jt|d|jt|dj||S(s
        L{defer.maybeDeferred} should catch exception raised by a synchronous
        function and errback its resulting L{defer.Deferred} with it.
        t10icSs|dS(Ni((R{((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRPrsii(	t	TypeErrorR1RR|R.R:RR>R2(RR}R~RORkRW((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_maybeDeferredSyncErrorhs
csDtjtjfd}jd|j|jdS(s
        L{defer.maybeDeferred} should let L{defer.Deferred} instance pass by
        so that original result is the same.
        csS(N(((RW(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRPstSuccess(RRR|RRR(RRQ((RWs;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_maybeDeferredAsynczs
csMtjtjfd}jtjt|j|tS(s
        L{defer.maybeDeferred} should let L{defer.Deferred} instance pass by
        so that L{failure.Failure} returned by the original instance is the
        same.
        csS(N(((RW(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRPs(RRR|R0RR_Rtt
assertFailure(RRQ((RWs;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_maybeDeferredAsyncErrorscsggtjfd}tjd}|j|jd|jjjj|jj|jg|jd
dddgd	S(
s
        When a L{Deferred} encounters a result which is another L{Deferred}
        which is waiting on a third L{Deferred}, the middle L{Deferred}'s
        callbacks are executed after the third L{Deferred} fires and before the
        first receives a result.
        csmjd|ftjd}fd}fd}|j|j||jj|S(Nsstart-of-cbtinnercsjdS(Nt
firstCallbackR(s
firstCallbacksinner(R:(R&(Rtresults(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRs
csjd|f|dS(NtsecondCallbacki(R:(R&(R(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRs(R:RRURR/(R&RWRR(RtfailuresR(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyR'stoutertorangesstart-of-cbRRRtorangeorangeN(sstart-of-cbsouter(s
firstCallbacksinner(ssecondCallbackR(RRRURRR:R/R(RR'R((RRRs;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_innerCallbacksPreserveds"

csggtjfd}tjd}|j||jj|jdd	gjd|jg|jd
dddgfgdS(s
        The continue callback of a L{Deferred} waiting for another L{Deferred}
        is not necessarily the first one. This is somewhat a whitebox test
        checking that we search for that callback among the whole list of
        callbacks.
        cs{jd|ftj}fd}fd}|j||j||jj|jd|S(NR'cs#jd|ftjgS(NR(R:RRq(Rh(taR(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRscsjd|fdS(NR(R:(R&(R(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRs(R:RRRR/RR(R&RWRR(RRR(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyR's


RR'RtwithersRN(scbsouter(s
firstCallbackN(scbsouter(s
firstCallbackN(	RRRURR/R:RRR(RR'R((RRRs;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_continueCallbackNotFirsts

csggtjfd}tj}|j||jfd|jj|jd|jd
dgjd|jg|jdd
ddgfdgd	S(s
        A callback added to a L{Deferred} after a previous callback attached
        another L{Deferred} as a result is run after the callbacks of the other
        L{Deferred} are run.
        cs{jd|ftj}fd}fd}|j||j||jj|jd|S(NR'cs#jd|ftjgS(NR(R:RRq(Rh(RR(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRscsjd|fdS(NR(R:(R&(R(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRs(R:RRRR/RR(R&RWRR(RRR(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyR's


cs
jdS(Ntfinal(R:(R{(R(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRPsRR'RRRRN(scbsouter(s
firstCallbackN(scbsouter(s
firstCallbackN(RRRR/R:RRR(RR'R((RRRs;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_callbackOrderPreserveds"


cstjgfdfd}fd}j|j|jd|jdddgdS(s
        A callback added to a L{Deferred} by a callback on that L{Deferred}
        should be added to the end of the callback chain.
        csjddS(Ni(R:(R&(tcalled(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt	callback3scsjddS(Ni(R:(R&(R(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt	callback2scsjdjdS(Ni(R:R(R&(RRR(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt	callback1s
iiiN(RRRRRR(RRR((RRRs;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_reentrantRunCallbacks	s


csmtjgfdfd}j|jdjddgdS(s
        A callback added to a L{Deferred} by a callback on that L{Deferred}
        should not be executed until the running callback returns.
        csjddS(Ni(R:(R&(R(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyR$scs1jdjjdgdS(Ni(R:RR(R&(RRRR(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyR&s

iiN(RRRRRR(RR((RRRRs;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_nonReentrantCallbackss

csdtjfdfd}j|jdjtfd}j|S(s
        After an exception is raised by a callback which was added to a
        L{Deferred} by a callback on that L{Deferred}, the L{Deferred} should
        call the first errback with a L{Failure} wrapping that exception.
        scallback raised exceptioncstdS(N(t	Exception(R&(texceptionMessage(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyR7scsjdS(N(R(R&(RR(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyR9scsj|jfdS(N(RR(t	exception(RR(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pytcbFailed>sN(RRRRRRR(RRR((RRRRs;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt%test_reentrantRunCallbacksWithFailure/s


cst}tj|tj}|jfd|jdg}j|j|j|dd|j|j|j|d|dS(s

        If a first L{Deferred} with a result is returned from a callback on a
        second L{Deferred}, the result of the second L{Deferred} becomes the
        result of the first L{Deferred} and the result of the first L{Deferred}
        becomes C{None}.
        csS(N((tign(Ro(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRPNsiiN(	RjRRURRRRR:tassertIdentical(RR&RnR((Ros;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_synchronousImplicitChainDs	
cstjtj}|jfd|jdg}j|jg}|j|j|j|g|j|gt}j||j|dg|j||gdS(s9
        If a first L{Deferred} without a result is returned from a callback on
        a second L{Deferred}, the result of the second L{Deferred} becomes the
        result of the first L{Deferred} as soon as the first L{Deferred} has
        one and the result of the first L{Deferred} becomes C{None}.
        csS(N((R(Ro(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRPasN(RRRRRR:RRj(RRntfirstResulttsecondResultR&((Ros;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_asynchronousImplicitChainXs
	
cCstjtd}tj}|j|d|j|t|jdg}|j|j|j	|dd|S(s
        If a first L{Deferred} with a L{Failure} result is returned from a
        callback on a second L{Deferred}, the first L{Deferred}'s result is
        converted to L{None} and no unhandled error is logged when it is
        garbage collected.
        sFirst Deferred's FailurecSs|S(N((RRo((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRP|siN(
RRYRtRRRRRR:R(RRoRnR((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt"test_synchronousImplicitErrorChainss
cstjtj}|jfd|jd|j|tg}j|jg}|j|j|j|g|j|gj	td|j|dg|jt
|ddS(sP
        Let C{a} and C{b} be two L{Deferred}s.

        If C{a} has no result and is returned from a callback on C{b} then when
        C{a} fails, C{b}'s result becomes the L{Failure} that was C{a}'s result,
        the result of C{a} becomes C{None} so that no unhandled error is logged
        when it is garbage collected.
        csS(N((R(Ro(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRPssFirst Deferred's FailureiN(RRRRRRRtR:RR0R>(RRnRR((Ros;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt#test_asynchronousImplicitErrorChains	
cstjtjjfdtj}|jfdg}|j|jt}jd|jd|j|gj||j||gdS(s
        L{Deferred} chaining is transitive.

        In other words, let A, B, and C be Deferreds.  If C is returned from a
        callback on B and B is returned from a callback on A then when C fires,
        A fires.
        csS(N((R(Ro(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRPscsS(N((R(Rn(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRPsN(RRRR:RjRRR(RtthirdtthirdResultR&((RnRos;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt'test_doubleAsynchronousImplicitChainings	


csggtjfd}tjd}|j||jj|jddgjdjj|jj|jgd|jd
ddd	gd
S(s
        L{Deferred}s can have callbacks that themselves return L{Deferred}s.
        When these "inner" L{Deferred}s fire (even asynchronously), the
        callback chain continues.
        csmjd|ftjd}fd}fd}|j|j||jj|S(Nsstart-of-cbRcsjdS(NRR(s
firstCallbacksinner(R:(R&(RR(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRs
csjd|f|dS(NRi(R:(R&(R(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRs(R:RRURR/(R&RWRR(RRR(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyR'sRsstart-of-cbRRRs&Got errbacks but wasn't expecting any.RRN(sstart-of-cbsouter(s
firstCallbacksinner(sstart-of-cbsouter(s
firstCallbacksinner(ssecondCallbacksorange(RRRURR:RRR/(RR'R((RRRs;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt'test_nestedAsynchronousChainedDeferredss(


csggtjfd}tjd}|j||jj|jd
dgjd|jjjj|jgd|jdd
ddgfddggd	S(sK
        L{Deferred}s can have callbacks that themselves return L{Deferred}s.
        These L{Deferred}s can have other callbacks added before they are
        returned, which subtly changes the callback chain. When these "inner"
        L{Deferred}s fire (even asynchronously), the outer callback chain
        continues.
        csqjd|ftjd}fd}fd}|j||j||jj|S(Nsstart-of-cbRcs#jd|fjdS(NRcSs|gS(N((R{((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRPs(R:R(Rh(RR(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRscsjd|f|dS(NRi(R:(R&(R(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRs(R:RRURR/(R&RWRR(RRR(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyR's

Rsstart-of-cbRRRs&Got errbacks but wasn't expecting any.RN(sstart-of-cbsouter(s
firstCallbacksinner(sstart-of-cbsouter(s
firstCallbacksinner(RRRURR:RRR/(RR'R((RRRs;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt9test_nestedAsynchronousChainedDeferredsWithExtraCallbackss(


cCs<tj}tj}|j||j|j|dS(sT
        When we chain a L{Deferred}, that chaining is recorded explicitly.
        N(RRt
chainDeferredRt
_chainedTo(RRtb((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt&test_chainDeferredRecordsExplicitChain>s
cCsItj}tj}|j||jd|j|jddS(sR
        Any recorded chaining is cleared once the chaining is resolved, since
        it no longer exists.

        In other words, if one L{Deferred} is recorded as depending on the
        result of another, and I{that} L{Deferred} has fired, then the
        dependency is resolved and we no longer benefit from recording it.
        N(RRRRRRR(RRR((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt%test_explicitChainClearedWhenResolvedHs
	

csRtj}tj|jfd|jd|j|jdS(s
        We can chain L{Deferred}s implicitly by adding callbacks that return
        L{Deferred}s. When this chaining happens, we record it explicitly as
        soon as we can find out about it.
        csS(N((Rh(R(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRP`sN(RRRRRRR(RR((Rs;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt&test_chainDeferredRecordsImplicitChainXs

cCs?tj}tt|}|jt|d|fdS(s
        The C{repr()} of a L{Deferred} contains the class name and a
        representation of the internal Python ID.
        s<Deferred at %s>N(RRthexRRtrepr(RRWtaddress((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt	test_represcCsCtj}|jd|jt|dtt|dS(sb
        If a L{Deferred} has been fired, then its C{repr()} contains its
        result.
        Rs)<Deferred at %s current result: 'orange'>N(RRRRRRR(RRW((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_reprWithResultps

cCsatj}tj}|j||jt|dtt|tt|fdS(s
        If a L{Deferred} C{a} has been fired, but is waiting on another
        L{Deferred} C{b} that appears in its callback chain, then C{repr(a)}
        says that it is waiting on C{b}.
        s*<Deferred at %s waiting on Deferred at %s>N(RRRRRRR(RRR((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_reprWithChaining|s
cs/fd}j|d|ddS(sw
        The depth of the call stack does not grow as more L{Deferred} instances
        are chained together.
        csgfd}tj}gt|D]}tj^q.}|}tj|j}|j|d|j|x/|r|j}|j|d|}qW|jfd|jdx|D]}|jdqWjgjddS(NcsjttjdS(N(R:R>t	tracebackt
extract_stack(Rh(tstack(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pytrecordStackDepthscSs|S(N((RR((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRPscSs|S(N((RR((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRPscsS(N((R(tlast(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRPsi(RRtrangetpopRRRR(thowManyRttopRhtinnerDeferredstoriginalInnersRtnewInner(R(RRs;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pytchainDeferredss(%
	



iiN(R(RR((Rs;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_boundedStackDepths#cstj}tjtj|jfdjfdjd|jdjdg}j|j|j|dgdS(s
        Given three Deferreds, one chained to the next chained to the next,
        callbacks on the middle Deferred which are added after the chain is
        created are called once the last Deferred fires.

        This is more of a regression-style test.  It doesn't exercise any
        particular code path through the current implementation of Deferred, but
        it does exercise a broken codepath through one of the variations of the
        implementation proposed as a resolution to ticket #411.
        csS(N((Rh(Rn(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRPscsS(N((Rh(R(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRPsN(RRRRRR:R(RRotL((RRns;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt:test_resultOfDeferredResultOfDeferredOfFiredDeferredCalleds


cCstjttj}g}td}y
|Wn|jnX|j|j|d}|j|j	||j
dd\}}|jg||jg|dS(s
        C{Deferred.errback()} creates a failure from the current Python
        exception.  When Deferred.debug is not set no globals or locals are
        captured in that failure.
        RHiiN(RRtFalseRRR0R/R:RR2tframes(RRWRVtexcRYtlocalztglobalz((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_errbackWithNoArgsNoDebugs


cCstjttj}g}td}y
|Wn|jnX|j|j|d}|j|j	||j
dd\}}|jg||jg|dS(s
        C{Deferred.errback()} creates a failure from the current Python
        exception.  When Deferred.debug is set globals and locals are captured
        in that failure.
        RHiiN(RRRMRRR0R/R:RR2RtassertNotEquals(RRWRVRRYRR((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_errbackWithNoArgss


cCstj}|jdtjtd}|j|g}|j|j|d}|j	dd\}}|j
g||j
g|dS(s
        An error raised by a callback creates a Failure.  The Failure captures
        locals and globals if and only if C{Deferred.debug} is set.
        cSstddS(NRH(R(Rh((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt
raiseErrorsiiN(RRRRRRRR/R:RR(RRWRRVRYRR((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt&test_errorInCallbackDoesNotCaptureVarss

	

cCstj}|jdtjtd}|j|g}|j|j|d}|j	dd\}}|j
g||j
g|dS(s
        An error raised by a callback creates a Failure.  The Failure captures
        locals and globals if and only if C{Deferred.debug} is set.
        cSstddS(NRH(R(Rh((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRsiiN(RRRRRRMRR/R:RR(RRWRRVRYRR((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt-test_errorInCallbackCapturesVarsWhenDebuggings

	

(8RR	RRRRRR!R"R#R9R<RGRKRNRRRSRXRZR]RcRdRgRmRpRsRzRRRRRRRRRRRRRRRRRRRRRRRRRRRRR(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyR
sl											(																
				%	)	*								 	;	A	
		
				+				tFirstErrorTestscBs)eZdZdZdZdZRS(s"
    Tests for L{FirstError}.
    cCsetd}y
|Wntj}nXtj|d}|jt|dt|fdS(s
        The repr of a L{FirstError} instance includes the repr of the value of
        the sub-failure and the index which corresponds to the L{FirstError}.
        s	some textisFirstError[#3, %s]N(RrRR_RRBRR(RRtfterror((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyR$s
	cCsetd}y
|Wntj}nXtj|d}|jt|dt|fdS(s
        The str of a L{FirstError} instance includes the str of the
        sub-failure and the index which corresponds to the L{FirstError}.
        s	some textisFirstError[#5, %s]N(RrRR_RRBRR1(RRRR((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_str5s
	cCsyddWntj}nXtj|d}tj|d}ytdWntj}nXtj|d}|j||k|j||k|j||k|j||k|j|dkdS(s
        L{FirstError} instances compare equal to each other if and only if
        their failure and index compare equal.  L{FirstError} instances do not
        compare equal to instances of other types.
        iii
tbari	i
N(RR_RRBRrt
assertTruetassertFalse(RtfirstFailuretonet
anotherOnet
secondFailuretanother((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_comparisonFs (RR	t__doc__RRR(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyR s		tAlreadyCalledTestCasecBseZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZdZdZdZdZRS(cCs tj|_tjtdS(N(RRt_deferredWasDebuggingRRM(R((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRescCstj|jdS(N(RRR(R((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttearDowniscOsdS(N((RRR((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRlscOsdS(N((RRR((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRnscCs|jddS(NR(R(RRW((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt_call_1qscCs|jddS(Nttwice(R(RRW((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt_call_2sscCs|jtjtdS(N(R0RR_Rt(RRW((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt_err_1uscCs|jtjtdS(N(R0RR_Rt(RRW((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt_err_2wscCsLtj}|j|j|j|j||jtj|j|dS(N(	RRR.RRRtfailUnlessRaisestAlreadyCalledErrorR(RRW((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttestAlreadyCalled_CCzs
cCsLtj}|j|j|j|j||jtj|j|dS(N(	RRR.RRRRRR(RRW((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttestAlreadyCalled_CEs
cCsLtj}|j|j|j|j||jtj|j|dS(N(	RRR.RRRRRR(RRW((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttestAlreadyCalled_EEs
cCsLtj}|j|j|j|j||jtj|j|dS(N(	RRR.RRRRRR(RRW((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttestAlreadyCalled_ECs
cCsad}xA|D]9}|jd|r
|jd|r
|d7}q
q
W|j||kdS(Nis %s:s %si(t
startswithtendswithR?(RtlinetypetfunctlinesRktcounttline((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt_counts
cCs|jdjd}|jd||d|jdd|d|jdd|d|jdd|d|jdd|d|jd	||d|jd	||ddS(
Nis
tCiRRRRtI(RtsplitR(RROtcallertinvoker1tinvoker2R((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt_checkscCstj}|j|j|j|j|y|j|Wn,tjk
rn}|j|dddnX|j	ddS(NttestAlreadyCalledDebug_CCRRs2second callback failed to raise AlreadyCalledError(
RRR.RRRRRRRY(RRWRO((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRs
cCstj}|j|j|j|j|y|j|Wn,tjk
rn}|j|dddnX|j	ddS(NttestAlreadyCalledDebug_CERRs1second errback failed to raise AlreadyCalledError(
RRR.RRRRRRRY(RRWRO((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRs
cCstj}|j|j|j|j|y|j|Wn,tjk
rn}|j|dddnX|j	ddS(NttestAlreadyCalledDebug_ECRRs2second callback failed to raise AlreadyCalledError(
RRR.RRRRRRRY(RRWRO((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRs
cCstj}|j|j|j|j|y|j|Wn,tjk
rn}|j|dddnX|j	ddS(NttestAlreadyCalledDebug_EERRs1second errback failed to raise AlreadyCalledError(
RRR.RRRRRRRY(RRWRO((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRs
cCstjttj}|j|j|j|j|y|j|Wn&tj	k
ru}|j
|jnX|jddS(Ns2second callback failed to raise AlreadyCalledError(
RRRRR.RRRRRtfailIfRRY(RRWRO((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttestNoDebuggings

cCstjttj}|jdtjt|jdtjttj}|jdtjt|jddS(NcSsdS(N(R(R((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRPscSsdS(N(R(R((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRPs(RRRRtaddBothRMRR(RRW((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttestSwitchDebuggings





(RR	RRRRRRRRRRRRRRRRRRRR(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRds(																			
tDeferredCancellerTestcBseZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZdZdZdZRS(cCs(d|_d|_d|_d|_dS(Ni(RRR
RtcancellerCallCount(R((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRs			cCs|j|jdkdS(Nii(ii(RR(R((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRscCs
||_|S(N(R(Rtdata((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRs	cCs
||_dS(N(R(RR	((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRscCs
||_dS(N(R
(RR	((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyR	scCs\tj}|j|j|j|j|j|jjtj	|j|j
ddS(s
        A L{defer.Deferred} without a canceller must errback with a
        L{defer.CancelledError} and not callback.
        N(RRR.RRtcancelRR
RAtCancelledErrorRR(RRW((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_noCanceller
s

cCsrtj}|j|j|j|j|jd|jtj	|jd|jtj	|j
tdS(s
        A L{defer.Deferred} without a canceller, when cancelled must allow
        a single extra call to callback, and raise
        L{defer.AlreadyCalledError} if callbacked or errbacked thereafter.
        N(RRR.RRR
RRtassertRaisesRR0R(RRW((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt!test_raisesAfterCancelAndCallbacks

cCsutj}|j|j|j|j|jt|jtj	|j
d|jtj	|jtdS(s
        A L{defer.Deferred} without a canceller, when cancelled must allow
        a single extra call to errback, and raise
        L{defer.AlreadyCalledError} if callbacked or errbacked thereafter.
        N(RRR.RRR
R0RR
RRR(RRW((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt test_raisesAfterCancelAndErrback+s
cCsctj}|j|j|j|j|j}|jd|j|j	||jdS(s
        A L{Deferred} without a canceller, when cancelled and then
        callbacked, ignores multiple cancels thereafter.
        N(
RRR.RRR
R
RRR(RRWtcurrentFailure((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt5test_noCancellerMultipleCancelsAfterCancelAndCallback=s
	

cCstj}|j|j|j|j|j|jjtj	|j}|j
t|j|jjtj	|j|j||jdS(s
        A L{defer.Deferred} without a canceller, when cancelled and then
        errbacked, ignores multiple cancels thereafter.
        N(
RRR.RRR
RR
RARR0RR(RRWR((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt4test_noCancellerMultipleCancelsAfterCancelAndErrbackMs
	
cCsotj}|j|j|j|j|j|jjtj	|j}|j|j
||jdS(s
        Calling cancel multiple times on a deferred with no canceller
        results in a L{defer.CancelledError}. Subsequent calls to cancel
        do not cause an error.
        N(RRR.RRR
RR
RARR(RRWR((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_noCancellerMultipleCancel_s
	
csfd}tjd|}|jjj|jjjjtj	j}|jj
|jjjddS(s,
        Verify that calling cancel multiple times on a deferred with a
        canceller that does not errback results in a
        L{defer.CancelledError} and that subsequent calls to cancel do not
        cause an error and that after all that, the canceller was only
        called once.
        csjd7_dS(Ni(R(RW(R(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyR
vst	cancelleriN(RRR.RRR
RR
RARRR(RR
RWR((Rs;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_cancellerMultipleCancelns
	
csfd}tjd|}|jjj|jjjdjjj	tj
jtj|j
djtj|jtdS(s
        Verify that a L{defer.Deferred} calls its specified canceller when
        it is cancelled, and that further call/errbacks raise
        L{defer.AlreadyCalledError}.
        csjd7_dS(Ni(R(RW(R(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyR
sRiN(RRR.RRR
RRR
RARR
RRRR0R(RR
RW((Rs;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_simpleCancellers
csHfd}tjd|jjjjdS(sQ
        Verify that a canceller is given the correct deferred argument.
        csj|dS(N(R(RI(RRW(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyR
sRN(RRR.RRR
(RR
((RRWs;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_cancellerArgscsfd}tjd|}|jjj|jd|jjjdjj	djjddS(so
        Test that cancelling a deferred after it has been callbacked does
        not cause an error.
        cs#jd7_|jtdS(Ni(RR0R(RW(R(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyR
sRsbiff!iN(RRR.RRRR
RRR
RR(RR
RW((Rs;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_cancelAfterCallbacks

csfd}tjd|}|jjj|jt|jjj	djj
jtjjddS(s
        Test that cancelling a L{Deferred} after it has been errbacked does
        not result in a L{defer.CancelledError}.
        cs#jd7_|jtdS(Ni(RR0R(RW(R(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyR
sRiN(RRR.RRR0RR
RRR
RARR(RR
RW((Rs;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_cancelAfterErrbacks
csnfd}tjd|}|jjj|jjjdjjj	t
dS(s?
        Test a canceller which errbacks its deferred.
        cs#jd7_|jtdS(Ni(RR0R(RW(R(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyR
sRiN(RRR.RRR
RRR
RAR(RR
RW((Rs;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_cancellerThatErrbackss
cs~fd}tjd|}|jjj|jjjdjjdjj	ddS(s<
        Test a canceller which calls its deferred.
        cs jd7_|jddS(Nishello!(RR(RW(R(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyR
sRishello!N(RRR.RRR
RRRR
R(RR
RW((Rs;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_cancellerThatCallbackss
csfd}fd}tjd|tjd|}|jd|jfd|j|jjjj	j
dj	jjtj
dS(s
        Verify that a Deferred, a, which is waiting on another Deferred, b,
        returned from one of its callbacks, will propagate
        L{defer.CancelledError} when a is cancelled.
        csjd7_dS(Ni(R(RW(R(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pytinnerCancelscsjtdS(N(RaR(RW(R(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyR
sRcsS(N((R	(R(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRPsiN(RRRRRR
R.RRRRR
RAR(RRR
R((RRs;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_cancelNestedDeferreds

(RR	RRRRRRRRRRRRRRRRRRR(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRs&																		tLogTestCasecBs_eZdZdZdZdZdZdZdZdZ	dZ
d	ZRS(
s+
    Test logging of unhandled errors.
    cCs g|_tj|jjdS(s<
        Add a custom observer to observer logging.
        N(tcRtaddObserverR:(R((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRs	cCstj|jjdS(s&
        Remove the observer.
        N(RtremoveObserverRR:(R((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRscCs$g|jD]}|dr
|^q
S(NtisError(R(RRO((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt
_loggedErrors
scCsH|j}|jt|d|ddjt|jtdS(sV
        Check the output of the log observer to see if the error is present.
        iiRN(R#RR>ttrapR`tflushLoggedErrors(Rtc2((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRscCs7tjjdjdtj|jdS(s
        Verify that when a L{Deferred} with no references to it is fired,
        and its final result (the one not handled by any callback) is an
        exception, that exception will be logged immediately.
        cSsddS(Nii((R{((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRP siN(RRRRtgctcollectR(R((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt
test_errorLogs
cCs(d}|tj|jdS(sD
        Same as L{test_errorLog}, but with an inner frame.
        cSs-tj}|jd|jddS(NcSsddS(Nii((R{((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRP*si(RRRR(RW((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt_subErrorLogWithInnerFrameRef(sN(R'R(R(RR*((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_errorLogWithInnerFrameRef$s	
cCs(d}|tj|jdS(sQ
        Same as L{test_errorLogWithInnerFrameRef}, plus create a cycle.
        cSs9tj}|j|d||_|jddS(NcSsddS(Nii((R{RW((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRP7si(RRRt_dR(RW((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt_subErrorLogWithInnerFrameCycle5s	N(R'R(R(RR-((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt test_errorLogWithInnerFrameCycle1s	
cCstj}|jd|jdg}g}|j|j|j|j|g|jt|d|dj	t
~~~tj|j|j
gdS(s
        If one Deferred with an error result is returned from a callback on
        another Deferred, when the first Deferred is garbage collected it does
        not log its error.
        cSstjtdS(Ntzoop(RRYRt(R((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRPGsiiN(RRRRRR.R:RR>R$RR'R(R#(RRWRterrors((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_chainedErrorCleanup@s
	
csetjtd}tj|jfdd}tj|j|j	gdS(s
        If a Deferred with a failure result has an errback which chains it to
        another Deferred, the initial failure is cleared by the errback so it is
        not logged.
        soh nocsS(N((Rh(tgood(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRPgsN(
RRYRRR/RR'R(RR#(Rtbad((R2s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_errorClearedByChaining]s

(RR	RRRR#RR)R+R.R1R4(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRs						
	
		tDeferredTestCaseIIcBs,eZdZdZdZdZRS(cCs
d|_dS(Ni(tcallbackRan(R((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRqscCs#tjg}|j|jdS(sTesting empty DeferredList.N(RR-Rtcb_empty(RR8((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttestDeferredListEmptytscCsd|_|jg|dS(Ni(R6R(Rtres((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyR7ys	cCs|j|jddS(NsCallback was never run.(R?R6(R((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyR}s(RR	RR8R7R(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyR5ps			tOtherPrimitivescBsteZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
RS(cCs|jd7_dS(Ni(tcounter(RR&((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt_incrscCs
d|_dS(Ni(R;(R((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRscsGtj}|jjjj|jjjd|jjjj|jjjd|j	j|jjjd|j	j
|jjjdjt|j
t}t}tjfd}|j
|dd|}j|jjj||jfd|jjjj|jjjdj|jj|j|jjjd|jjfd}|jjjjtj|j	j
|jdS(	Niics
||_S(N(R(RR(tcontrolDeferred(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pythelpers	RRcstd|S(NR&(tsetattr(R{(R(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRPsicstd|S(NR&(R?(R{(R(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRPs(RtDeferredLocktacquireRR<R?tlockedRR;treleaseRR
RtrunRjRRRR&RR
RAR(RtlocktfirstUniquetsecondUniqueR>tresultDeferredRW((RR=s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttestLocksD

		


csBfd}tj}|j}|j||jdS(s
        When canceling a L{Deferred} from a L{DeferredLock} that already
        has the lock, the cancel should have no effect.
        csjddS(NsUnexpected errback call!(RY(R^(R(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt_failOnErrbacksN(RR@RAR/R
(RRJRERW((Rs;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_cancelLockAfterAcquireds

cCsCtj}|j|j}|j|tj|jdS(s
        When canceling a L{Deferred} from a L{DeferredLock} that does not
        yet have the lock (i.e., the L{Deferred} has not fired), the cancel
        should cause a L{defer.CancelledError} failure.
        N(RR@RARRR
(RRERW((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_cancelLockBeforeAcquireds

cs	d}tj|}tjfd}g}t}|j|d|d|}|j|j|j|j|j|g|j|j	|j
d|j|jd|j|j
dd|_
xDtdd|D]/}|jj|j|j|j
|qWgfd}fd}	|jj||	}
|
j|jtg|jj|j|j|j
||j|j|j
|dx<tdd|D]'}|j|j|j
|dqWdS(	Ni
cs
||_S(N(targ(RRM(R=(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyR>s	RRMiicsjtdS(N(R:R(Re(RT(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRYscsjtdS(N(R:RM(Re(RT(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRUs(RtDeferredSemaphoreRRjRDRR:R<RRMRRRR;RRAR.R
RMRC(RtNtsemR>RtuniqueObjectRHtiRYRURW((RTR=s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt
testSemaphores>	
	


cCs0|jttjd|jttjddS(sz
        If the token count passed to L{DeferredSemaphore} is less than one
        then L{ValueError} is raised.
        iiN(R
RrRRN(R((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_semaphoreInvalidTokensscsEfd}tjd}|j}|j||jdS(s
        When canceling a L{Deferred} from a L{DeferredSemaphore} that
        already has the semaphore, the cancel should have no effect.
        csjddS(NsUnexpected errback call!(RY(R^(R(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRJsiN(RRNRAR/R
(RRJRPRW((Rs;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt!test_cancelSemaphoreAfterAcquireds

cCsFtjd}|j|j}|j|tj|j|S(s
        When canceling a L{Deferred} from a L{DeferredSemaphore} that does
        not yet have the semaphore (i.e., the L{Deferred} has not fired),
        the cancel should cause a L{defer.CancelledError} failure.
        i(RRNRARRR
(RRPRW((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt"test_cancelSemaphoreBeforeAcquireds

cCs d\}}tj||}g}x*t|D]}|jj|jq1W|jtj|jx;t|D]-}|j||j	|t|dqtWx;t|D]-}|j|||j	|t|qW|jtj
|jdg}xKt|D]=}|jj|j|j	|t|||dqWtj}g}x*t|D]}|jj|jqoWx!t|D]}|j|qW|j	|t|tjdd}|jtj
|jdtjdd}|jtj|jdS(Niitsizeitbacklog(ii(Rt
DeferredQueueRtgetRR:R
tQueueUnderflowtputRt
QueueOverflowR(RROtMtqueuetgottenRR((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt	testQueue's8
%csOfd}tj}|j}|j||jd|jdS(s
        When canceling a L{Deferred} from a L{DeferredQueue} that already has
        a result, the cancel should have no effect.
        csjddS(NsUnexpected errback call!(RY(R^(R(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRJRsN(RRYRZR/R\RR
(RRJR_RW((Rs;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt#test_cancelQueueAfterSynchronousGetMs

csTtjj}j|tj|jfd}|j|S(s
        When canceling a L{Deferred} from a L{DeferredQueue} that does not
        have a result (i.e., the L{Deferred} has not fired), the cancel
        causes a L{defer.CancelledError} failure. If the queue has a result
        later on, it doesn't try to fire the deferred.
        cs&jdjjjdS(N(R\RRZRR(tignore(R_R(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyR'gs
(RRYRZRRR
R(RRWR'((R_Rs;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_cancelQueueAfterGet\s
(RR	R<RRIRKRLRSRTRURVRaRbRd(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyR:s			3	
	
	.					&	tDeferredFilesystemLockTestCasecBsMeZdZdZdZdZdZdZdZdZ	RS(s8
    Test the behavior of L{DeferredFilesystemLock}
    cCs1t|_tj|jd|j|_dS(Nt	scheduler(RtclockRtDeferredFilesystemLocktmktempRE(R((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyRtscCs|jjdd}|S(sI
        Test that the lock can be acquired when no lock is held
        ttimeouti(REtdeferUntilLocked(RRW((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_waitUntilLockedWithNoLockzscCsY|j|jj|jjdd}|j|tj|jjdgd|S(ss
        Test that the lock can not be acquired when the lock is held
        for longer than the timeout.
        Rjg@ii
(R?RERkRRtTimeoutErrorRgtpump(RRW((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt%test_waitUntilLockedWithTimeoutLockeds
cs{fd}jjjjjdjjjjdd}|j|jjdgd|S(s|
        Test that a lock can be acquired while a lock is held
        but the lock is unlocked before our timeout.
        cs!|jtjjddS(NsShould not have timed out(R$RRmRY(R(R(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt	onTimeoutsiRji
(R?RERgt	callLatertunlockRkR/Rn(RRpRW((Rs;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt'test_waitUntilLockedWithTimeoutUnlockeds
cCs,tj|j}|j|jtdS(sE
        Test that the default scheduler is set up properly.
        N(RRhRiRt
_schedulerR(RRE((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_defaultSchedulerscCsk|jj|jjd|jj|jj}|jj}|j|tj|jjd|S(s|
        Test that an appropriate exception is raised when attempting
        to use deferUntilLocked concurrently.
        i(	RERgRqRrRkRRtAlreadyTryingToLockErrortadvance(RRWRQ((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_concurrentUsages
csefd}jjjjdjjjj}|j|jjd|S(sO
        Test that a DeferredFilesystemLock can be used multiple times
        cs jjjj}|S(N(RERrRk(RRW(R(s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pytlockAquireds
i(RERgRqRrRkRRw(RRyRW((Rs;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyttest_multipleUsagess

(
RR	RRRlRoRsRuRxRz(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyReps								(RR'Rt
twisted.trialRttwisted.internetRRttwisted.internet.taskRttwisted.pythonRRttwisted.python.utilRRRtTestCaseR
RRRRR5R:Re(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_defer.pyt<module>s(Dv