+
    Dfj+                      R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	t
^ RIt^ RIt^ RIHtHtHtHt ^ RIHtHtHtHtHtHtHtHtHtHtHtHtH t H!t!H"t"H#t# ^ RI$H%t%H&t&H't' ^ RI(H)t) ^ RI*H+t+ ^ RIH,t, ^ R	I-H.t.H/t/ ^ R
I0H1t1H2t2H3t3H4t4H5t5H6t6H7t7H8t8H9t9H:t:H;t;H<t< ^ RI=H>t> ^ RI?H@t@ ^ RIAHBtB ^ RICHDtD ^ RIEH	t	 R R ltF ! R R]G4      tHR R ltI]!! R]GR7      tJ ! R R4      tK ! R R]	P                  4      tM ! R R]	P                  ]K4      tO ! R R4      tPR  R! ltQ ! R" R#]	P                  4      tR ! R$ R%]	P                  4      tS ! R& R']	P                  4      tT ! R( R)]	P                  4      tU ! R* R+]	P                  4      tV ! R, R-]	P                  4      tW ! R. R/]	P                  ]K4      tX ! R0 R1]	P                  4      tYR2 R3 ltZ ! R4 R5]	P                  4      t[ ! R6 R7]	P                  4      t\ ! R8 R9]	P                  ]K4      t]R: R; lt^ ! R< R=]	P                  4      t_ ! R> R?]	P                  4      t` ! R@ RA]	P                  4      taR# )Bz+
Test cases for L{twisted.internet.defer}.
)annotationsN)AbstractEventLoopCancelledErrorFuturenew_event_loop)AnyCallable	CoroutineDict	GeneratorListLiteralMappingNoReturnOptionalSetTupleTypeTypeVarUnioncast)assert_thatemptyequal_to)given)integers)assert_type)deferreactor)_TDeferredDeferredFilesystemLockDeferredListDeferredLockDeferredQueueDeferredSemaphoreFailureGroup_DeferredListResultListT_DeferredListSingleResultTensureDeferredrace)Clock)log)_PYPYFailure)unittestc                    V ^8  d   QhRRRR/# )   fz0Callable[..., Coroutine[Deferred[Any], Any, _T]]returnzCallable[..., Deferred[_T]] )formats   "9/usr/lib/python3/dist-packages/twisted/test/test_defer.py__annotate__r8   G   s      7     c                L   a  \         P                  ! S 4      R  V 3R ll4       pV# )c               $    V ^8  d   QhRRRRRR/# )r2   argsobjectkwargsr4   zDeferred[_T]r5   )r6   s   "r7   r8   &ensuringDeferred.<locals>.__annotate__K   s!     , ,v , ,L ,r9   c                 @   < S! V / VB p\         P                  ! V4      # N)r    fromCoroutine)r<   r>   coror3   s   *, r7   wrapper!ensuringDeferred.<locals>.wrapperJ   s#    $!&!%%d++r9   )	functoolswraps)r3   rD   s   f r7   ensuringDeferredrH   G   s'     __Q, , Nr9   c                      ] tR t^RtRtR# )GenericErrorr5   N__name__
__module____qualname____firstlineno____static_attributes__r5   r9   r7   rJ   rJ   R   s    r9   rJ   c                    V ^8  d   QhRRRR/# )r2   deferredDeferred[str]r4   Noner5   )r6   s   "r7   r8   r8   V   s     ) )M )d )r9   c                (    V P                  R4       R# )z
A fake L{Deferred} canceller which callbacks the L{Deferred}
with C{str} "Callback Result" when cancelling it.

@param deferred: The cancelled L{Deferred}.
Callback ResultNcallbackrR   s   &r7   fakeCallbackCancellerrZ   V   s     '(r9   _ExceptionT)boundc                  &    ] tR t^ctRtR R ltRtR# )ImmediateFailureMixinz#
Add additional assertion methods.
c               $    V ^8  d   QhRRRRRR/# )r2   rR   Deferred[Any]	exceptionzType[_ExceptionT]r4   r[   r5   )r6   s   "r7   r8   "ImmediateFailureMixin.__annotate__h   s$     4 4%42C4	4r9   c                6   \        \        P                  V 4      p. pVP                  VP                  4       VP                  \        V4      ^4       VP                  V^ ,          P                  V4      4       \        \        V^ ,          P                  4      # )z
Assert that the given Deferred current result is a Failure with the
given exception.

@return: The exception instance in the Deferred.
)r   r0   TestCase
addErrbackappendassertEquallen
assertTruecheckr[   value)selfrR   ra   testCasefailuress   &&&  r7   assertImmediateFailure,ImmediateFailureMixin.assertImmediateFailureh   su     ))40"$HOO,S]A.HQK--i89K!!2!233r9   r5   N)rL   rM   rN   rO   __doc__ro   rP   r5   r9   r7   r^   r^   c   s    4 4r9   r^   c                  >    ] tR t^ytRtR R ltR R ltR R ltRtR	# )
	UtilTestsz
Tests for utility functions.
c                   V ^8  d   QhRR/# r2   r4   rT   r5   )r6   s   "r7   r8   UtilTests.__annotate__~   s     % %4 %r9   c                    \        \        4       4      p\        P                  ! V4      pV P	                  \        4       V P                  W4       R# )z,
L{defer.logError} returns the given error.
N)r/   RuntimeErrorr   logErrorflushLoggedErrorsassertIs)rl   errorresults   &  r7   test_logErrorReturnsError#UtilTests.test_logErrorReturnsError~   s8     '&|,e$r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   rv      s     * * *r9   c                    \        \        4       4      p\        P                  ! V4       V P	                  \        4      pV P                  W!.4       R# )z)
L{defer.logError} logs the given error.
N)r/   rx   r   ry   rz   rg   )rl   r|   errorss   &  r7   test_logErrorLogsError UtilTests.test_logErrorLogsError   s<     'u''5)r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   rv      s     M Md Mr9   c                  a . oR V3R llp\         P                  ! V4       \        \        4       4      p\        P
                  ! V4       V P                  \        4       V P                  S^ ,          P                  R4      4       R# )zB
The text logged by L{defer.logError} has no repr of the failure.
c                    V ^8  d   QhRRRR/# )r2   	eventDictzDict[str, Any]r4   rT   r5   )r6   s   "r7   r8   <UtilTests.test_logErrorLogsErrorNoRepr.<locals>.__annotate__   s     	  	 N 	 t 	 r9   c                b   < \         P                  ! V 4      pVf   Q hSP                  V4       R # rA   )r,   textFromEventDictrf   )r   textoutputs   & r7   emit4UtilTests.test_logErrorLogsErrorNoRepr.<locals>.emit   s+    ((3D###MM$r9   Unhandled Error
Traceback N)	r,   addObserverr/   rx   r   ry   rz   ri   
startswith)rl   r   r|   r   s   &  @r7   test_logErrorLogsErrorNoRepr&UtilTests.test_logErrorLogsErrorNoRepr   sd     	  	 
 	'u|,q	,,-JKLr9   r5   N)	rL   rM   rN   rO   rq   r~   r   r   rP   r5   r9   r7   rs   rs   y   s    %*M Mr9   rs   c                     ] tR t^tR R ltR R ltR R ltR R ltR	 R
 ltR R lt	R R lt
R R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R  ltR! R" ltR# R$ ltR% R& ltR' R( ltR) R* ltR+ R, ltR- R. ltR/ R0 ltR1 R2 ltR3 R4 ltR5 R6 ltR7 R8 ltR9 R: lt R; R< lt!R= R> lt"R? R@ lt#RA RB lt$RC RD lt%RE RF lt&RG RH lt'RI RJ lt(RK RL lt)RM RN lt*RO RP lt+RQ RR lt,RS RT lt-RU RV lt.RW RX lt/RY RZ lt0R[ R\ lt1R] R^ lt2R_ R` lt3Ra Rb lt4Rc Rd lt5Re Rf lt6Rg Rh lt7Ri Rj lt8Rk Rl lt9Rm Rn lt:Ro Rp lt;Rq Rr lt<Rs Rt lt=Ru Rv lt>Rw Rx lt?Ry Rz lt@R{ R| ltAR} R~ ltBR R ltCR R ltDR R ltER R ltFR R ltGR R ltHR R ltIR R ltJR R ltKR R ltLR R ltMR R ltNR R ltOR R ltPR R ltQR R ltRR R ltSR R ltTR R ltU]VP                  ! ]XR4      R R l4       tY]VP                  ! ]XR4      R R l4       tZ]VP                  ! ]XR4      R R l4       t[R R lt\Rt]R# )DeferredTestsc                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   DeferredTests.__annotate__   s     B Bt Br9   c                	    R V n         R V n        R V n        V P                  \        P
                  \        P                  ! 4       4       R # rA   )callbackResultscallback2ResultserrbackResults
addCleanupr   setDebugginggetDebuggingrl   s   &r7   setUpDeferredTests.setUp   sH      	
  	
  	
 	**E,>,>,@Ar9   c               $    V ^8  d   QhRRRRRR/# )r2   r<   r=   r>   r4   r   r5   )r6   s   "r7   r8   r      s!      v  C r9   c                	$    W3V n         V^ ,          # )    r   rl   r<   r>   s   &*,r7   	_callbackDeferredTests._callback   s    #|Awr9   c               $    V ^8  d   QhRRRRRR/# r2   r<   r=   r>   r4   rT   r5   )r6   s   "r7   r8   r      s!     - - -& -T -r9   c                	    W3V n         R # rA   r   r   s   &*,r7   
_callback2DeferredTests._callback2   s     $r9   c               $    V ^8  d   QhRRRRRR/# )r2   r<   r/   r>   r=   r4   rT   r5   )r6   s   "r7   r8   r      s!     + +g + +D +r9   c                	    W3V n         R # rA   r   r   s   &*,r7   _errbackDeferredTests._errback   s    "lr9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r      s     A A Ar9   c                	    \        4       pVP                  V P                  4       VP                  R 4       V P	                  V P
                  4       V P                  V P                  R/ 34       R# helloNr   r    addCallbackr   rX   assertIsNoner   rg   r   rl   rR   s   & r7   testCallbackWithoutArgs%DeferredTests.testCallbackWithoutArgs   sX    "**T^^,'"$--.--
B/?@r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r      s     I Id Ir9   c                	    \        4       pVP                  V P                  R 4       VP                  R4       V P	                  V P
                  4       V P                  V P                  R/ 34       R# )worldr   N)r   r   r   r   s   & r7   testCallbackWithArgs"DeferredTests.testCallbackWithArgs   s[    "**T^^W5'"$--.--0BB/GHr9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r      s     Q Q Qr9   c                	    \        4       pVP                  V P                  R R7       VP                  R4       V P	                  V P
                  4       V P                  V P                  RR R /34       R# )r   )r   r   Nr   r   r   s   & r7   testCallbackWithKwArgs$DeferredTests.testCallbackWithKwArgs   sb    "**T^^7;'"$--.--
Wg<N/OPr9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r      s     B B$ Br9   c                	V   \        4       pVP                  V P                  4       VP                  V P                  4       VP	                  R 4       V P                  V P                  4       V P                  V P                  R/ 34       V P                  V P                  R/ 34       R# r   )
r    r   r   r   rX   r   r   rg   r   r   r   s   & r7   testTwoCallbacksDeferredTests.testTwoCallbacks   s    "**T^^,T__-'"$--.--
B/?@..R0@Ar9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r      s     

 

4 

r9   c                	   \        4       pVP                   V P                  4       pV P                  ^\	        V4      4       V P                  \        V^ ,          R,          4       V P                  RV^ ,          R,          4       R# )   categoryzCtwisted.internet.defer.Deferred.callbacks was deprecated in TwistedmessageN)r    	callbacksflushWarningsrg   rh   r{   DeprecationWarningassertIn)rl   rR   warningss   &  r7   !test_callbacksAttributeDeprecated/DeferredTests.test_callbacksAttributeDeprecated   sg    "**%%'CM*((1+j*ABQQK	"	
r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r      s     5 5d 5r9   c                R   \        R4      p\        4       pVP                  V P                  \	        \
        R\        3,          R4      4       VP                  V4       VP                  V P                  4       V P                  V P                  4       V P                  f   Q hV P                  \        V P                  ^ ,          4      ^4       V P                  V P                  ^ ,          ^ ,          P                  V4       V P                  V P                  ^,          / 4       R# )zA
If given None for an errback, addCallbacks uses a pass-through.
oopsie.N)rJ   r    addCallbacksr   r   r   r=   errbackre   r   r   r   r   rg   rh   rk   rl   r|   rR   s   &  r7   test_addCallbacksNoneErrback*DeferredTests.test_addCallbacksNoneErrback   s     X&#+:dnnd8CK3H$.OPDMM*$../""...T0034a8,,Q/288%@,,Q/4r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r      s     A A4 Ar9   c           
     r   \        4       pVP                  V P                  V P                  \	        \
        \        ,          R4      \	        \        \        \        3,          R4      R/ 4       VP                  R4       V P                  V P                  4       V P                  V P                  R/ 34       R# )zB
If given None as a callback args and kwargs, () and {} are used.
Nr   r5   r   )r    r   r   r   r   r   r=   r   strrX   r   r   rg   r   r   s   & r7   !test_addCallbacksNoneCallbackArgs/DeferredTests.test_addCallbacksNoneCallbackArgs   s     #+*NNMMv%f%t,	
 	'"$--.--
B/?@r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r   	  s     5 5$ 5r9   c                   \        R4      p\        4       pVP                  V P                  V P                  R/ \        \        \        ,          R4      \        \        \        \        3,          R4      4       VP                  V4       VP                  V P                  4       V P                  V P                  4       V P                  f   Q hV P                  \!        V P                  ^ ,          4      ^4       V P                  V P                  ^ ,          ^ ,          P"                  V4       V P                  V P                  ^,          / 4       R# )zA
If given None as a errback args and kwargs, () and {} are used.
r   Nr5   )rJ   r    r   r   r   r   r   r=   r   r   r   re   r   r   r   rg   rh   rk   r   s   &  r7    test_addCallbacksNoneErrbackArgs.DeferredTests.test_addCallbacksNoneErrbackArgs	  s    X&#+:NNMMv%f%t,	
 	DMM*$../""...T0034a8,,Q/288%@,,Q/4r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     "
 "
$ "
r9   c                	   \         \        \        \        \        \
        3,          3,          ,          p\        4       p\        4       p\        4       p\        W#V.4      p. pV3R  R llpR R lpVP                  Ww4       VP                  R4       VP                  V4       VP                  \        R4      4       VP                  R4       V P                  V^ ,          V^,          ^ ,          \	        \        \
        V^,          ^,          4      P                  4      3V^,          .\         P"                  R3\         P$                  R3\         P"                  R3.4       R# )c               $    V ^8  d   QhRRRRRR/# )r2   
resultList
ResultListr}   r4   rT   r5   )r6   s   "r7   r8   4DeferredTests.testDeferredList.<locals>.__annotate__(  s!     	& 	&: 	&z 	&t 	&r9   c                (    VP                  V 4       R # rA   )extendr   r}   s   &&r7   cb*DeferredTests.testDeferredList.<locals>.cb(  s    MM*%r9   c                    V ^8  d   QhRRRR/# r2   errr/   r4   rT   r5   )r6   s   "r7   r8   r   +       	 	w 	4 	r9   c                    R # rA   r5   r   s   &r7   catch-DeferredTests.testDeferredList.<locals>.catch+      r9   123N)r   r   boolr   r   r/   r    r"   r   rX   re   r   rJ   rg   r   rk   r   SUCCESSFAILURE)	rl   r   defr1defr2defr3dlr}   r   r   s	   &        r7   testDeferredListDeferredTests.testDeferredList  s   %eCL&9 9:;
'z'z'z5/0<B 	&	 	s 	l3'(sq	1s41#>#D#DEFq		 mmS!EMM3#7%--9MN	
r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r   C  s     % %t %r9   c                	    . pV3R  R llp\        . 4      pVP                  V4       V P                  V. .4       . VR&   \        . RR7      pVP                  V4       V P                  V. 4       R# )c               $    V ^8  d   QhRRRRRR/# )r2   r   z_DeferredListResultListT[None]r}   z$List[_DeferredListResultListT[None]]r4   rT   r5   )r6   s   "r7   r8   9DeferredTests.testEmptyDeferredList.<locals>.__annotate__F  s&     	& 	&6	&8	& 	&r9   c                (    VP                  V 4       R # rA   rf   r   s   &&r7   r   /DeferredTests.testEmptyDeferredList.<locals>.cbF  s     MM*%r9   NNNTfireOnOneCallbackN)r"   r   rg   )rl   r}   r   dl1dl2s   &    r7   testEmptyDeferredList#DeferredTests.testEmptyDeferredListC  sw    79 <B	& 9ER8H"&q	:F$;
 	$r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r   W  s     '. '. '.r9   c                	   \        4       p\        4       p\        4       p\        WV.R R7      p. pVP                  VP                  4       R R lpVP                  V4       VP	                  R4       V P                  V. 4       VP                  \        R4      4       V P                  \        V4      ^4       V^ ,          pV P                  \        VP                  \        P                  4      RVP                  : 24       VP                  pV P                  VP                  P                  \        4       V P                  VP                  P                  P                   R4       V P                  VP"                  ^4       R# )	TfireOnOneErrbackc                    V ^8  d   QhRRRR/# r   r5   )r6   s   "r7   r8   BDeferredTests.testDeferredListFireOnOneError.<locals>.__annotate__a  r   r9   c                    R # rA   r5   r   s   &r7   r   ;DeferredTests.testDeferredListFireOnOneError.<locals>.catcha  r   r9   r   	from def2zFissubclass(aFailure.type, defer.FirstError) failed: failure's type is N)r   )r    r"   re   rf   rX   rg   r   rJ   rh   ri   
issubclasstyper   
FirstErrorrk   
subFailurer<   index)	rl   r  r  r  r  r}   r   aFailure
firstErrors	   &        r7   testDeferredListFireOnOneError,DeferredTests.testDeferredListFireOnOneErrorW  s1   'z'z'z5/$G "
fmm$	 	 	s$ 	l;/0Va( !9 	x}}e&6&67&.mm6	
 ^^
 	..33\B..4499>J))1-r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     ? ?4 ?r9   c                	   \        4       p\        V.4      p. pVP                  VP                  4       . pVP	                  VP                  4       VP                  \        R 4      4       V P                  R V^ ,          P                  P                  ^ ,          4       V P                  ^\        V4      4       V^ ,          ^ ,          pVf   Q hV P                  R V^,          P                  P                  ^ ,          4       R# )BangN)r    r"   re   rf   r   r   rJ   rg   rk   r<   rh   rl   d1r  	errorTrapresultListsfirstResults   &     r7   !testDeferredListDontConsumeErrors/DeferredTests.testDeferredListDontConsumeErrors  s    %Z2$#%	
i&&'<>
{))*


<'(1!3!3!8!8!;<C,-!!nQ'&&&Q!5!5!:!:1!=>r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     ? ?t ?r9   c                	   \        4       p\        V.R R7      p. pVP                  VP                  4       . pVP	                  VP                  4       VP                  \        R4      4       V P                  . V4       V P                  ^\        V4      4       V^ ,          ^ ,          pVf   Q hV P                  RV^,          P                  P                  ^ ,          4       R# )TconsumeErrorsr,  N)r    r"   re   rf   r   r   rJ   rg   rh   rk   r<   r-  s   &     r7   testDeferredListConsumeErrors+DeferredTests.testDeferredListConsumeErrors  s    %Z2$d3#%	
i&&'<>
{))*


<'(Y'C,-!!nQ'&&&Q!5!5!:!:1!=>r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     & & &r9   c                	   \        4       p\        4       pVP                  \        R 4      4       \        W.RR7      p. pVP	                  VP
                  4       V P                  ^\        V4      4       VP	                  R 4       R# )r,  Tr  c                    R # rA   r5   es   &r7   <lambda>WDeferredTests.testDeferredListFireOnOneErrorWithAlreadyFiredDeferreds.<locals>.<lambda>      r9   N)r    r   rJ   r"   re   rf   rg   rh   rl   r.  d2r  r}   s   &    r7   7testDeferredListFireOnOneErrorWithAlreadyFiredDeferredsEDeferredTests.testDeferredListFireOnOneErrorWithAlreadyFiredDeferreds  sf    %Z%Z


<'( 2(T: "
fmm$CK(
n%r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     & &4 &r9   c                	0   \        4       p\        4       pVP                  \        R 4      4       VP                  ^4       \	        W.4      p. pVP                  VP                  4       V P                  ^\        V4      4       VP                  R 4       R# )r,  c                    R # rA   r5   r=  s   &r7   r?  IDeferredTests.testDeferredListWithAlreadyFiredDeferreds.<locals>.<lambda>  rA  r9   N)
r    r   rJ   rX   r"   r   rf   rg   rh   re   rB  s   &    r7   )testDeferredListWithAlreadyFiredDeferreds7DeferredTests.testDeferredListWithAlreadyFiredDeferreds  so    $J$J


<'(
A 2(#/1
v}}%CK(
n%r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     
@ 
@ 
@r9   c                    \        4       p\        4       p\        W.4      pVP                  4        V P                  V\        P
                  4       V P                  V\        P
                  4       R# )zS
When cancelling an unfired L{DeferredList}, cancel every
L{Deferred} in the list.
Nr    r"   cancelfailureResultOfr   r   rl   deferredOnedeferredTwodeferredLists   &   r7   test_cancelDeferredList%DeferredTests.test_cancelDeferredList  sW    
 '/j&.j#[$>?[%*>*>?[%*>*>?r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     B B Br9   c                   \        \        4      p\        4       p\        W.4      pVP                  4        V P	                  V\
        P                  4       V P                  V4      pV P                  V^ ,          ^ ,          4       V P                  V^ ,          ^,          R4       V P                  V^,          ^ ,          4       V P                  V^,          ^,          P                  \
        P                  4      4       R# )z
When cancelling an unfired L{DeferredList} without the
C{fireOnOneCallback} and C{fireOnOneErrback} flags set, the
L{DeferredList} will be callback with a C{list} of
(success, result) C{tuple}s.
rV   N)r    rZ   r"   rO  rP  r   r   successResultOfri   rg   assertFalserj   rl   rR  rS  rT  r}   s   &    r7   test_cancelDeferredListCallback-DeferredTests.test_cancelDeferredListCallback  s     &..C%D%-Z#[$>?[%*>*>?%%l3q	!%1'891&q	!**5+?+?@Ar9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     
@ 
@d 
@r9   c                    \        4       p\        4       p\        W.RR7      pVP                  4        V P                  V\        P
                  4       V P                  V\        P
                  4       R# )zz
When cancelling an unfired L{DeferredList} with the flag
C{fireOnOneCallback} set, cancel every L{Deferred} in the list.
Tr  NrN  rQ  s   &   r7   ,test_cancelDeferredListWithFireOnOneCallback:DeferredTests.test_cancelDeferredListWithFireOnOneCallback  sZ    
 '/j&.j#[$>RVW[%*>*>?[%*>*>?r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     9 9QU 9r9   c                    \        \        4      p\        4       p\        W.RR7      pVP                  4        V P	                  V\
        P                  4       V P                  V4      pV P                  VR4       R# )z
When cancelling an unfired L{DeferredList} with the flag
C{fireOnOneCallback} set, if one of the L{Deferred} callbacks
in its canceller, the L{DeferredList} will callback with the
result and the index of the L{Deferred} in a C{tuple}.
Tr  N)rV   r   )	r    rZ   r"   rO  rP  r   r   rY  rg   r[  s   &    r7   ?test_cancelDeferredListWithFireOnOneCallbackAndDeferredCallbackMDeferredTests.test_cancelDeferredListWithFireOnOneCallbackAndDeferredCallback  si     &..C%D%-Z#[$>RVW[%*>*>?%%l3!78r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     K KT Kr9   c                   \        4       p\        4       p\        W.RR7      pVP                  4        V P                  V\        P
                  4       V P                  V\        P
                  4       V P                  V\        P                  4      pVP                  pV P                  VP                  P                  \        P
                  4      4       R# )zy
When cancelling an unfired L{DeferredList} with the flag
C{fireOnOneErrback} set, cancel every L{Deferred} in the list.
Tr  N)r    r"   rO  rP  r   r   r#  rk   ri   r$  rj   )rl   rR  rS  rT  deferredListFailurer'  s   &     r7   +test_cancelDeferredListWithFireOnOneErrback9DeferredTests.test_cancelDeferredListWithFireOnOneErrback  s    
 '/j&.j#[$>QUV[%*>*>?[%*>*>?"22<AQAQR(..

--33E4H4HIJr9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r   	  s     : :QU :r9   c                   \        \        4      p\        \        4      p\        W.RR7      pVP                  4        V P	                  V4      pV P                  V^ ,          ^ ,          4       V P                  V^ ,          ^,          R4       V P                  V^,          ^ ,          4       V P                  V^,          ^,          R4       R# )z
When cancelling an unfired L{DeferredList} with the flag
C{fireOnOneErrback} set, if all the L{Deferred} callbacks
in its canceller, the L{DeferredList} will callback with a
C{list} of (success, result) C{tuple}s.
Tr  rV   N)r    rZ   r"   rO  rY  ri   rg   r[  s   &    r7   ?test_cancelDeferredListWithFireOnOneErrbackAllDeferredsCallbackMDeferredTests.test_cancelDeferredListWithFireOnOneErrbackAllDeferredsCallback	  s     &..C%D%-.C%D#[$>QUV%%l3q	!%1'89q	!%1'89r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     + +d +r9   c                B   \        4       p\        4       pW.p\        V4      p\        4       pVP                  V4       VP                  4        V P	                  V\
        P                  4       V P	                  V\
        P                  4       V P                  V4       R# )zO
Cancelling a L{DeferredList} will cancel the original
L{Deferred}s passed in.
N)r    r"   rf   rO  rP  r   r   assertNoResult)rl   rR  rS  argumentListrT  deferredThrees   &     r7   ,test_cancelDeferredListWithOriginalDeferreds:DeferredTests.test_cancelDeferredListWithOriginalDeferreds  s    
 '/j&.j#1#L1(0
M*[%*>*>?[%*>*>?M*r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r   *  s     ) )d )r9   c                   R R lp\        V4      p\        4       p\        W#.4      pVP                  4        V P                  V\        P
                  4       V P                  \        4      pV P                  \        V4      ^4       R# )z
Cancelling a L{DeferredList} will cancel every L{Deferred}
in the list even exceptions raised from the C{cancel} method of the
L{Deferred}s.
c                    V ^8  d   QhRRRR/# )r2   rR   Deferred[object]r4   rT   r5   )r6   s   "r7   r8   HDeferredTests.test_cancelDeferredListWithException.<locals>.__annotate__1  s     	' 	'/? 	'D 	'r9   c                    \        R4      h)z`
A L{Deferred} canceller that raises an exception.

@param deferred: The cancelled L{Deferred}.
test)rx   rY   s   &r7   cancellerRaisesExceptionTDeferredTests.test_cancelDeferredListWithException.<locals>.cancellerRaisesException1  s     v&&r9   N)
r    r"   rO  rP  r   r   rz   rx   rg   rh   )rl   r}  rR  rS  rT  r   s   &     r7   $test_cancelDeferredListWithException2DeferredTests.test_cancelDeferredListWithException*  sn    	' '//G&H&.j#[$>?[%*>*>?''5Va(r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r   A  s     ) )4 )r9   c                    \        4       p\        4       p\        W.RR7      pVP                  R4       VP                  4        V P	                  V4       R# )z
When a L{DeferredList} has fired because one L{Deferred} in
the list fired with a non-failure result, the cancellation will do
nothing instead of cancelling the rest of the L{Deferred}s.
Tr  N)r    r"   rX   rO  rq  rQ  s   &   r7   )test_cancelFiredOnOneCallbackDeferredList7DeferredTests.test_cancelFiredOnOneCallbackDeferredListA  sJ     '/j&.j#[$>RVWT"K(r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r   N  s     = =$ =r9   c                ,   \        4       p\        4       p\        W.RR7      pVP                  \        R4      4       VP	                  4        V P                  V4       V P                  V\        4       V P                  V\        P                  4       R# )z
When a L{DeferredList} has fired because one L{Deferred} in
the list fired with a failure result, the cancellation will do
nothing instead of cancelling the rest of the L{Deferred}s.
Tr  r|  N)	r    r"   r   rJ   rO  rq  rP  r   r#  rQ  s   &   r7   (test_cancelFiredOnOneErrbackDeferredList6DeferredTests.test_cancelFiredOnOneErrbackDeferredListN  su     '/j&.j#[$>QUVL01K([,7\5+;+;<r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r   ]  s     ) )d )r9   c                	    . p\         P                  ! R 4      pVP                  VP                  4       V P	                  VR .4       R# )successN)r   succeedr   rf   rg   rl   lds   &  r7   testImmediateSuccess"DeferredTests.testImmediateSuccess]  s7     ==3	ahhYK(r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r   c  s     2 2$ 2r9   c                    \        4       pVP                  R4       \        P                  ! R4      pV P	                  VP
                  VP
                  4       R# )zI
C{defer.succeed(x)} is the same as as C{d = Deferred(); d.callback(x)}.
r  N)r    rX   r   r  rg   __dict__)rl   r  rC  s   &  r7    test_succeedMatchesManualSuccess.DeferredTests.test_succeedMatchesManualSuccessc  s=     $:	

9!MM)4R[[1r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r   l  s     2 2d 2r9   c                	    . p\         P                  ! \        R 4      4      pVP                  VP                  4       V P                  \        V^ ,          P                  4      R 4       R# failN)r   r  rJ   re   rf   rg   r   rk   r  s   &  r7   testImmediateFailure"DeferredTests.testImmediateFailurel  sF    !JJ|F';<	QXXQqTZZ&1r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r   r  s     2 24 2r9   c                	:   . p\         P                  ! \        R 4      4      pVP                  4        VP	                  VP
                  4       V P                  V. 4       VP                  4        V P                  \        V^ ,          P                  4      R 4       R# r  )
r   r  rJ   pausere   rf   rg   unpauser   rk   r  s   &  r7   testPausedFailureDeferredTests.testPausedFailurer  sh    JJ|F+,			QXXB			QqTZZ&1r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r   {  s     
= 
=D 
=r9   c                	   . p\        4       pVP                  R  4      P                  VP                  4       VP	                  ^4       V P                  V^ ,          P                  \        4       . p\         \        ,          ! 4       pVP                  R 4      P                  VP                  4       VP	                  ^4       V P                  V^ ,          P                  \        4       R# )c                    ^^ ,          # r   r5   _s   &r7   r?  2DeferredTests.testCallbackErrors.<locals>.<lambda>~  s    Qr9   c                (    \        \        4       4      # rA   )r/   ZeroDivisionErrorr  s   &r7   r?  r    s    ):)<!=r9   N)	r    r   re   rf   rX   assertIsInstancerk   r  int)rl   r  r  rC  s   &   r7   testCallbackErrors DeferredTests.testCallbackErrors{  s    #:	&'22188<	

1adjj*;<c]_
=>II!((S
Aadjj*;<r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s      4 r9   c                	    \        4       pVP                  4        VP                  V P                  4       VP	                  4        R # rA   )r    r  r   r   r  rl   r  s   & r7   testUnpauseBeforeCallback'DeferredTests.testUnpauseBeforeCallback  s+    $J			dnn%			r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     
 
d 
r9   c                n  a \        4       p\        4       oSP                  4        VP                  V3R l4       VP                  V P                  4       VP	                  ^4       V P                  V P                  R4       SP	                  ^4       V P                  V P                  R4       SP                  4        V P                  V P                  R4       V P                  f   Q R4       hV P                  V P                  ^ ,          ^ ,          ^RP                  V P                  4      4       R# )z
Callbacks passed to L{Deferred.addCallback} can return Deferreds and
the next callback will not be run until that Deferred fires.
c                   < S# rA   r5   )rrC  s   &r7   r?  <DeferredTests.test_callbackReturnsDeferred.<locals>.<lambda>  s    r9   z Should not have been called yet.z&Still should not have been called yet.zShould have been called nowNz%make that legible to the type checkerz/Result should have been from second deferred:{})r    r  r   r   rX   r   r   r  assertIsNotNoneassertEqualsr6   rl   r.  rC  s   & @r7   test_callbackReturnsDeferred*DeferredTests.test_callbackReturnsDeferred  s    
 %J$J


|$
t~~&
A$..0RS
A  "J	
 	

T113PQ##/X1XX/  #A&=DD$$	
r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     
 
$ 
r9   c                  aa \        4       pRo\        4       oR VV3R llpVP                  ^4       V P                  V P	                  VP                  V4      4      ^4       \         \        ,          ! 4       pRoVP                  ^4       V P                  V P                  VP                  V4      P                  V4      \        4      P                  S4       R# )z6
Callbacks passed to addCallback may return Failures.
Fc                    V ^8  d   QhRRRR/# )r2   r}   r  r4   zUnion[int, Failure]r5   )r6   s   "r7   r8   DDeferredTests.test_callbackMaybeReturnsFailure.<locals>.__annotate__  s     	" 	"c 	"&9 	"r9   c                <   < S'       d   \        S4      # V ^,           # r  r.   )r}   rte
shouldFails   &r7   	maybeFailADeferredTests.test_callbackMaybeReturnsFailure.<locals>.maybeFail  s    s|#z!r9   TN)
r    rx   rX   rg   rY  r   r  r{   rP  rk   )rl   r  r  r  r  s   &  @@r7    test_callbackMaybeReturnsFailure.DeferredTests.test_callbackMaybeReturnsFailure  s     $:
n	" 	" 	


1--ammI.FGKSMO
	

1  i(44Y? e	
r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     3 3T 3r9   c                Z  aa \        4       p\        4       o. oR V3R llpR V3R llpVP                  V4      P                  V4       VP                  \	        4       4       V P                  V4       V P                  S. 4       SP                  R4       V P                  SR.4       R# )zW
Errbacks passed to L{Deferred.addErrback} can return Deferreds just as
callbacks can.
c                    V ^8  d   QhRRRR/# )r2   r}   r/   r4   rS   r5   )r6   s   "r7   r8   ?DeferredTests.test_errbackReturnsDeferred.<locals>.__annotate__  s     	 	 	] 	r9   c                   < S# rA   r5   )r}   rC  s   &r7   asyncErrback?DeferredTests.test_errbackReturnsDeferred.<locals>.asyncErrback  s    Ir9   c                    V ^8  d   QhRRRR/# )r2   r}   zUnion[str, int]r4   rT   r5   )r6   s   "r7   r8   r    s     	( 	( 	(T 	(r9   c                *   < SP                  V 4       R # rA   r  )r}   resultValuess   &r7   syncCallback?DeferredTests.test_errbackReturnsDeferred.<locals>.syncCallback  s    'r9   r}   N)r    re   r   r   
ValueErrorrq  rg   rX   )rl   r  r  r  rC  r  s   &   @@r7   test_errbackReturnsDeferred)DeferredTests.test_errbackReturnsDeferred  s    
 $:$J	 		( 	( 	
\"..|<			*,Ar*
Hz2r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     - -d -r9   c                t  a \        4       p\        4       oSP                  V4       SP                  4        \        4       pVP	                  V3R l4       VP                  R4       . pVP	                  VP
                  4       V P                  V. 4       SP                  4        V P                  W1.4       R# )z
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.
c                   < S# rA   r5   )ignoredpauseds   &r7   r?  DDeferredTests.test_chainedPausedDeferredWithResult.<locals>.<lambda>  s    Fr9   N)r=   r    rX   r  r   rf   rg   r  )rl   expectedchainedr}   r  s   &   @r7   $test_chainedPausedDeferredWithResult2DeferredTests.test_chainedPausedDeferredWithResult  s     8#+:!"**23!FMM*$,r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     ) )D )r9   c                  a \        4       p\        4       oVP                  V3R l4       VP                  R4       VP                  4        SP                  R4       . pSP                  VP                  4       V P                  VR.4       R# )z
A paused Deferred encountered while pushing a result forward through a
chain does not prevent earlier Deferreds from continuing to execute
their callbacks.
c                   < S# rA   r5   r  seconds   &r7   r?  :DeferredTests.test_pausedDeferredChained.<locals>.<lambda>      &r9   N)r    r   rX   r  rf   rg   )rl   firstr}   r  s   &  @r7   test_pausedDeferredChained(DeferredTests.test_pausedDeferredChained  sl     !)
!)01t6==)$(r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r      s     & &D &r9   c                	R   . p\         P                  ! \         P                  ! ^4      \         P                  ! ^4      .4      P                  VP                  4       V P                  V^^..4       . p\         P                  ! ^4      \         P                  ! \        4       4      .p\         P                  ! V4      P                  VP                  4       V P                  \        V4      ^4       V P                  V^ ,          \        4       V^,          P                  R 4       R# )r   c                    ^# r  r5   r=  s   &r7   r?  2DeferredTests.test_gatherResults.<locals>.<lambda>  s    1r9   N)r   gatherResultsr  r   rf   rg   r  r  re   rh   r  r/   )rl   resultsr   r  s   &   r7   test_gatherResults DeferredTests.test_gatherResults   s    #%U]]1-u}}Q/?@AMMNN	
 	Aq6(+ "mmA

:< 89B**6==9Va(fQi1
1%r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     > >T >r9   c                >   \         P                  ! ^4      p\         P                  ! \        R4      4      p\         P                  ! W.RR7      p. pVP                  VP                  4       . pVP                  VP                  4       V P                  \        V4      \        V4      3R4       V P                  V^ ,          P                  \         P                  4       V^ ,          P                  P                  pV P                  VP                  \        4       R# )z
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
L{None} result on that L{Deferred}.
zoh noesTr6  Nr   r   )r   r  r  rx   r  re   rf   rg   rh   r  rk   r#  r$  )rl   dgooddbadr  unconsumedErrorsgatheredErrorsr'  s   &      r7   #test_gatherResultsWithConsumeErrors1DeferredTests.test_gatherResultsWithConsumeErrors  s     a zz,y12TB*,(//0(*	^**+#./^1DEvNnQ/55u7G7GH#A&,,77
j..=r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r   $  s     K K$ Kr9   c                   \        4       p\        4       p\        P                  ! W.4      pVP                  4        V P	                  V\        P
                  4       V P	                  V\        P
                  4       V P	                  V\        P                  4      pVP                  pV P                  VP                  P                  \        P
                  4      4       R# )zf
When cancelling the L{defer.gatherResults} call, all the
L{Deferred}s in the list will be cancelled.
N)r    r   r  rO  rP  r   r#  rk   ri   r$  rj   )rl   rR  rS  r}   gatherResultsFailurer'  s   &     r7   test_cancelGatherResults&DeferredTests.test_cancelGatherResults$  s    
 '/j&.j$$k%?@[%*>*>?[%*>*>?#33FE<L<LM)//

--33E4H4HIJr9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r   3  s     ? ?$ ?r9   c                   \        \        4      p\        \        4      p\        P                  ! W.4      pVP	                  4        V P                  V4      pV P                  V^ ,          R4       V P                  V^,          R4       R# )z
When cancelling the L{defer.gatherResults} call, if all the
L{Deferred}s callback in their canceller, the L{Deferred}
returned by L{defer.gatherResults} will be callbacked with the C{list}
of the results.
rV   N)r    rZ   r   r  rO  rY  rg   )rl   rR  rS  r}   callbackResults   &    r7   0test_cancelGatherResultsWithAllDeferredsCallback>DeferredTests.test_cancelGatherResultsWithAllDeferredsCallback3  sr     &..C%D%-.C%D$$k%?@--f5*,=>*,=>r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r   B  s     1 1 1r9   c                0  a \        4       o. p. p\        P                  ! V3R l4      pVP                  VP                  VP                  4       V P                  V. 4       V P                  \        V4      ^4       V P                  V^ ,          S4       R# )zw
L{defer.maybeDeferred} should retrieve the result of a synchronous
function and pass it to its resulting L{Deferred}.
c                    < S # rA   r5   r}   s   r7   r?  6DeferredTests.test_maybeDeferredSync.<locals>.<lambda>J  s    r9   N)r=   r   maybeDeferredr   rf   rg   rh   assertIdentical)rl   r  r   r  r}   s   &   @r7   test_maybeDeferredSync$DeferredTests.test_maybeDeferredSyncB  st    
  " "/	w~~v}}5$Wq)WQZ0r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r   P  s     ( ( (r9   c                   R R lp. p. p\         P                  ! V^
4      p\        V\        \        ,          4       VP                  VP                  VP                  4       V P                  V. 4       V P                  V^.4       R# )zF
L{defer.maybeDeferred} should pass arguments to the called function.
c                    V ^8  d   QhRRRR/# )r2   xr  r4   r5   )r6   s   "r7   r8   BDeferredTests.test_maybeDeferredSyncWithArgs.<locals>.__annotate__U  s     	 	 	 	r9   c                    V ^,           # )   r5   r  s   &r7   plusFive>DeferredTests.test_maybeDeferredSyncWithArgs.<locals>.plusFiveU  s    q5Lr9   N)r   r  r   r    r  r   rf   rg   )rl   r  r  r   r  s   &    r7   test_maybeDeferredSyncWithArgs,DeferredTests.test_maybeDeferredSyncWithArgsP  sk    
	   ""-Ax}%	w~~v}}5$2$'r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r   `  s     > > >r9   c                p  a \        R4      oR V3R llp. p. p\        P                  ! V4      P                  VP                  VP                  4       V P                  V. 4       V P                  \        V4      ^4       V P                  \        V^ ,          P                  4      \        S4      4       R# )z
L{defer.maybeDeferred} should catch an exception raised by a synchronous
function and errback its resulting L{Deferred} with it.
zthat value is unacceptablec                   V ^8  d   QhRR/# )r2   r4   r   r5   )r6   s   "r7   r8   CDeferredTests.test_maybeDeferredSyncException.<locals>.__annotate__g  s     	 	 	r9   c                    < S hrA   r5   r  s   r7   raisesExceptionFDeferredTests.test_maybeDeferredSyncException.<locals>.raisesExceptiong  s    Nr9   N)	r  r   r  r   rf   rg   rh   r   rk   )rl   r#  r  r   r  s   &   @r7   test_maybeDeferredSyncException-DeferredTests.test_maybeDeferredSyncException`  s    
 :;	 	   "O,99'..&--X"%Va(VAY__-s8}=r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r   q  s     2 2t 2r9   c                f  a  R^,            . p. p\        P                  ! V3R l4      pVP	                  VP
                  VP
                  4       V P                  V. 4       V P                  \        V4      ^4       V P                  V^ ,          S4       R#   \          d    \        4       o Li ; i)z_
L{defer.maybeDeferred} should handle a L{Failure} returned by a
function and errback with it.
10c                    < S # rA   r5   r"  s   r7   r?  =DeferredTests.test_maybeDeferredSyncFailure.<locals>.<lambda>}  s    r9   N)		TypeErrorr/   r   r  r   rf   rg   rh   r  )rl   r  r   r  r  s   &   @r7   test_maybeDeferredSyncFailure+DeferredTests.test_maybeDeferredSyncFailureq  s    
	!1H   " 01	w~~v}}5"%Va(VAY1  	!yH	!s   	B B0/B0c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     
. 
. 
.r9   c                   a \        4       o\        P                  ! V3R l4      pSP                  R4       . pVP	                  VP
                  4       V P                  VR.4       R# )ze
L{defer.maybeDeferred} should let L{Deferred} instance pass by
so that original result is the same.
c                    < S # rA   r5   r.  s   r7   r?  7DeferredTests.test_maybeDeferredAsync.<locals>.<lambda>  s    r9   SuccessN)r    r   r  rX   r   rf   rg   )rl   rC  r}   r.  s   &  @r7   test_maybeDeferredAsync%DeferredTests.test_maybeDeferredAsync  sO    
 %J  ,
I
v}}%)-r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     	6 	6d 	6r9   c                   a \        4       o\        P                  ! V3R l4      pSP                  \	        \        4       4      4       V P                  V\
        4       R# )z
L{defer.maybeDeferred} should let L{Deferred} instance pass by
so that L{Failure} returned by the original instance is the
same.
c                    < S # rA   r5   r2  s   r7   r?  <DeferredTests.test_maybeDeferredAsyncError.<locals>.<lambda>  s    r9   N)r    r   r  r   r/   rx   ro   )rl   rC  r.  s   & @r7   test_maybeDeferredAsyncError*DeferredTests.test_maybeDeferredAsyncError  s?     &Z"00<


7<>*+##B5r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     E ED Er9   c                    R R lp\         P                  ! V4      p\        V\        \        ,          4       V P                  V P                  V4      ^4       R# )
When called with a coroutine function L{defer.maybeDeferred} returns a
L{defer.Deferred} which has the same result as the coroutine returned
by the function.
c                   V ^8  d   QhRR/# r2   r4   r  r5   )r6   s   "r7   r8   FDeferredTests.test_maybeDeferredCoroutineSuccess.<locals>.__annotate__       	 	 	r9   c                    "   ^# 5i   r5   r5   r9   r7   r3   ;DeferredTests.test_maybeDeferredCoroutineSuccess.<locals>.f          N)r   r  r   r    r  rg   rY  )rl   r3   coroutineDeferreds   &  r7   "test_maybeDeferredCoroutineSuccess0DeferredTests.test_maybeDeferredCoroutineSuccess  sE    	 "//2%x}5--.?@!Dr9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     D DD Dr9   c                   a R R loR V3R llpR R lp\         P                  ! V4      p\        V\        \        ,          4       VP                  V4      pV P                  V P                  V4      ^4       R# )r?  c                   V ^8  d   QhRR/# rA  r5   )r6   s   "r7   r8   NDeferredTests.test_maybeDeferredCoroutineSuccessIndirect.<locals>.__annotate__  rC  r9   c                    "   ^# 5irE  r5   r5   r9   r7   r3   CDeferredTests.test_maybeDeferredCoroutineSuccessIndirect.<locals>.f  rH  rI  c                   V ^8  d   QhRR/# )r2   r4   z"Coroutine[Deferred[int], Any, Any]r5   )r6   s   "r7   r8   rP    s     	 	5 	r9   c                    < S ! 4       # rA   r5   r3   s   r7   gCDeferredTests.test_maybeDeferredCoroutineSuccessIndirect.<locals>.g  
    3Jr9   c                    V ^8  d   QhRRRR/# )r2   r}   r  r4   r5   )r6   s   "r7   r8   rP    s     	 	# 	# 	r9   c                    V ^,           # r  r5   r  s   &r7   typedCallbackODeferredTests.test_maybeDeferredCoroutineSuccessIndirect.<locals>.typedCallback  s    A:r9   N)r   r  r   r    r   r   rg   rY  )rl   rV  r[  rJ  modifiedDeferredr3   s   &    @r7   *test_maybeDeferredCoroutineSuccessIndirect8DeferredTests.test_maybeDeferredCoroutineSuccessIndirect  sf    	
	 	
	 "//2%x}5,88G--.>?Cr9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     
 
D 
r9   c                   aa  ! R R\         4      oR V3R lloR V3R llp\        V P                  \        P                  ! V4      4      P
                  \        S4      4       R# )z
When called with a coroutine function L{defer.maybeDeferred} returns a
L{defer.Deferred} which has a L{Failure} result wrapping the exception
raised by the coroutine function.
c                      ] tR tRtRtR# )GDeferredTests.test_maybeDeferredCoroutineFailure.<locals>.SomeExceptioni  r5   NrK   r5   r9   r7   SomeExceptionrc        r9   rd  c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   FDeferredTests.test_maybeDeferredCoroutineFailure.<locals>.__annotate__  s     	" 	" 	"r9   c                    <"   S ! 4       h5irA   r5   )rd  s   r7   r3   ;DeferredTests.test_maybeDeferredCoroutineFailure.<locals>.f  s     /!s   c                   V ^8  d   QhRR/# )r2   r4   zCoroutine[None, None, None]r5   )r6   s   "r7   r8   rg    s     	 	. 	r9   c                    < S ! 4       # rA   r5   rU  s   r7   rV  ;DeferredTests.test_maybeDeferredCoroutineFailure.<locals>.g  rX  r9   N)	Exceptionr   rP  r   r  r"  r   )rl   rV  rd  r3   s   & @@r7   "test_maybeDeferredCoroutineFailure0DeferredTests.test_maybeDeferredCoroutineFailure  sT    	I 		" 	"
	 	 	  !4!4Q!78==]#	
r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     *
 *
d *
r9   c                  aaa . o. o\        4       oR VVV3R llp\        P                  ! R4      pVP                  V4       SP	                  R4       VP                  SP
                  4       SP                  SP
                  4       VP                  SP
                  4       V P                  . S4       V P                  S. RO4       R# )z
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.
c                    V ^8  d   QhRRRR/# r2   r}   r   r4   rS   r5   )r6   s   "r7   r8   @DeferredTests.test_innerCallbacksPreserved.<locals>.__annotate__  s     	 	s 	} 	r9   c                   < SP                  R V 34       \        P                  ! R4      pR VV3R llpR V3R llpVP                  V4      P                  V4       VP	                  SP                   4       V# )start-of-cbinnerc                    V ^8  d   QhRRRR/# rs  r5   )r6   s   "r7   r8   LDeferredTests.test_innerCallbacksPreserved.<locals>.cb.<locals>.__annotate__  s      c m r9   c                *   < SP                  R4       S# firstCallbackr|  rw  r  r}   rw  r  s   &r7   r|  MDeferredTests.test_innerCallbacksPreserved.<locals>.cb.<locals>.firstCallback  s    9:r9   c                    V ^8  d   QhRRRR/# r2   r}   r   r4   r5   )r6   s   "r7   r8   ry         " "s "s "r9   c                <   < SP                  R V 34       V ^,          # secondCallbackr  r}   r  s   &r7   r  NDeferredTests.test_innerCallbacksPreserved.<locals>.cb.<locals>.secondCallback       0&9:z!r9   rf   r   r  r   re   r}   r  r|  r  rn   rw  r  s   &   r7   r   6DeferredTests.test_innerCallbacksPreserved.<locals>.cb  sd    NNM623g&A " " MM-(44^DLL)Hr9   outerorangeNrv  r  r}  )r  r  orangeorange)r    r   r  r   rX   rf   re   rg   rl   r   r  rn   rw  r  s   &  @@@r7   test_innerCallbacksPreserved*DeferredTests.test_innerCallbacksPreserved  s     68"$'z	 	  g&"x '..)))X&	
r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     %
 %
t %
r9   c                X  aaa . o. o\        4       oR VVV3R llp\        P                  ! R4      P                  V4      P	                  SP
                  4       V P                  RR.S4       SP                  R4       V P                  . S4       V P                  SRRRR.3.4       R# )	z
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.
c                    V ^8  d   QhRRRR/# r2   r}   r   r4   Deferred[None]r5   )r6   s   "r7   r8   ADeferredTests.test_continueCallbackNotFirst.<locals>.__annotate__       	 	s 	~ 	r9   c                   < SP                  R V 34       \        4       pR VV3R llpR V3R llpVP                  V4      P                  V4      P                  SP                   4      pVP	                  R4       V# )r   c                    V ^8  d   QhRRRR/# r2   r}   rT   r4   Deferred[List[str]]r5   )r6   s   "r7   r8   MDeferredTests.test_continueCallbackNotFirst.<locals>.cb.<locals>.__annotate__       0 0d 0/B 0r9   c                X   < SP                  R V 34       \        P                  ! S.4      # r|  rf   r   r  r}   ar  s   &r7   r|  NDeferredTests.test_continueCallbackNotFirst.<locals>.cb.<locals>.firstCallback  '    89**A3//r9   c                    V ^8  d   QhRRRR/# r2   r}   	List[str]r4   rT   r5   )r6   s   "r7   r8   r         ; ;y ;T ;r9   c                .   < SP                  R V 34       R# r  Nr  r  s   &r7   r  ODeferredTests.test_continueCallbackNotFirst.<locals>.cb.<locals>.secondCallback       0&9:r9   Nrf   r    r   re   rX   r}   r  r|  r  returnerr  rn   r  s   &    r7   r   7DeferredTests.test_continueCallbackNotFirst.<locals>.cb  l    NND&>* (
A0 0; ; m,^,HOO, 
 JJtOr9   r  Nwithersr  r   r  r|  N)r    r   r  r   re   rf   rg   rX   )rl   r   r  rn   r  s   & @@@r7   test_continueCallbackNotFirst+DeferredTests.test_continueCallbackNotFirst  s     BD"$#:	 	& 	g**2.99(//J/+BCWM	

9X&58H9+7VW	
r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r   +  s     -
 -
T -
r9   c                  aaa . o. o\        4       oR VVV3R llp\        4       pVP                  V4       VP                  V3R l4       VP                  SP                  4       VP	                  R4       V P                  RR	.S4       SP	                  R4       V P                  . S4       V P                  SRR	RR.3R
.4       R# )z
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.
c                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   ?DeferredTests.test_callbackOrderPreserved.<locals>.__annotate__5  r  r9   c                   < SP                  R V 34       \        4       pR VV3R llpR V3R llpVP                  V4      P                  V4      P                  SP                   4      pVP	                  R4       V# )r   c                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   KDeferredTests.test_callbackOrderPreserved.<locals>.cb.<locals>.__annotate__9  r  r9   c                X   < SP                  R V 34       \        P                  ! S.4      # r  r  r  s   &r7   r|  LDeferredTests.test_callbackOrderPreserved.<locals>.cb.<locals>.firstCallback9  r  r9   c                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   r  =  r  r9   c                .   < SP                  R V 34       R# r  r  r  s   &r7   r  MDeferredTests.test_callbackOrderPreserved.<locals>.cb.<locals>.secondCallback=  r  r9   Nr  r  s   &    r7   r   5DeferredTests.test_callbackOrderPreserved.<locals>.cb5  r  r9   c                &   < SP                  R4      # )finalr  Nr  )r  r  s   &r7   r?  ;DeferredTests.test_callbackOrderPreserved.<locals>.<lambda>J  s    GNN?$Cr9   r  Nr  r  r  r  r  )r    r   re   rf   rX   rg   )rl   r   r  r  rn   r  s   &  @@@r7   test_callbackOrderPreserved)DeferredTests.test_callbackOrderPreserved+  s     BD"$#:	 	&  (z"CD)w/+BCWM	

9X&'!I;/		
r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r   Z  s     , ,D ,r9   c                   aaa \        4       o. oR V3R lloR V3R llpR VVV3R llpSP                  V4       SP                  V4       SP                  R4       V P                  S. RO4       R# )	zw
A callback added to a L{Deferred} by a callback on that L{Deferred}
should be added to the end of the callback chain.
c                    V ^8  d   QhRRRR/# r2   r}   rT   r4   r5   )r6   s   "r7   r8   >DeferredTests.test_reentrantRunCallbacks.<locals>.__annotate__b       	 	d 	t 	r9   c                *   < SP                  ^4       R# )   Nr  r}   calleds   &r7   	callback3;DeferredTests.test_reentrantRunCallbacks.<locals>.callback3b      MM!r9   c                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   r  e  r  r9   c                *   < SP                  ^4       R# r2   Nr  r  s   &r7   	callback2;DeferredTests.test_reentrantRunCallbacks.<locals>.callback2e  r  r9   c                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   r  h  s     	, 	,d 	,t 	,r9   c                L   < SP                  ^4       SP                  S4       R# r   Nrf   r   )r}   r  r  rR   s   &r7   	callback1;DeferredTests.test_reentrantRunCallbacks.<locals>.callback1h  s    MM!  +r9   N)r   r2   r  r    r   rX   rg   )rl   r  r  r  r  rR   s   &  @@@r7   test_reentrantRunCallbacks(DeferredTests.test_reentrantRunCallbacksZ  sk    
 $,:	 		 		, 	, 	Y'Y'$+r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r   q  s     ) )D )r9   c                   a aaa \        4       o. oR V3R lloR VVVV 3R llpSP                  V4       SP                  R4       S P                  S^^.4       R# )z
A callback added to a L{Deferred} by a callback on that L{Deferred}
should not be executed until the running callback returns.
c                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   >DeferredTests.test_nonReentrantCallbacks.<locals>.__annotate__y  r  r9   c                *   < SP                  ^4       R# r  r  r  s   &r7   r  ;DeferredTests.test_nonReentrantCallbacks.<locals>.callback2y  r  r9   c                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   r  |  s     	* 	*d 	*t 	*r9   c                r   < SP                  ^4       SP                  S4       SP                  S^.4       R# r  )rf   r   rg   )r}   r  r  rR   rl   s   &r7   r  ;DeferredTests.test_nonReentrantCallbacks.<locals>.callback1|  s/    MM!  +VaS)r9   Nr  )rl   r  r  r  rR   s   f @@@r7   test_nonReentrantCallbacks(DeferredTests.test_nonReentrantCallbacksq  sW    
 $,:	 		* 	*
 	Y'$!Q(r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     > >t >r9   c                   aaa Ro\        4       oR V3R lloR VV3R llpSP                  V4       SP                  R4       V P                  S\        4      pV P                  VP                  S34       R# )z
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.
zcallback raised exceptionc                    V ^8  d   QhRRRR/# r2   r}   r=   r4   rT   r5   )r6   s   "r7   r8   IDeferredTests.test_reentrantRunCallbacksWithFailure.<locals>.__annotate__  s     	. 	.f 	. 	.r9   c                   < \        S4      hrA   )rm  )r}   exceptionMessages   &r7   r  FDeferredTests.test_reentrantRunCallbacksWithFailure.<locals>.callback2  s    ,--r9   c                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   r    s     	, 	,f 	, 	,r9   c                *   < SP                  S4       R # rA   )r   )r}   r  rR   s   &r7   r  FDeferredTests.test_reentrantRunCallbacksWithFailure.<locals>.callback1  s      +r9   N)r    r   rX   ro   rm  rg   r<   )rl   r  ra   r  rR   r  s   &  @@@r7   %test_reentrantRunCallbacksWithFailure3DeferredTests.test_reentrantRunCallbacksWithFailure  sn     7#+:	. 	.	, 	, 	Y'$//)D	*:)<=r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     * *t *r9   c                z  a \        4       p\        P                  ! V4      o\        4       pVP	                  V3R l4       VP                  R4       . pSP	                  VP                  4       V P                  V^ ,          4       VP	                  VP                  4       V P                  V^,          V4       R# )z
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 L{None}.
c                   < S# rA   r5   ignr  s   &r7   r?  =DeferredTests.test_synchronousImplicitChain.<locals>.<lambda>      ur9   N)	r=   r   r  r    r   rX   rf   r   r{   )rl   r}   r  r  r  s   &   @r7   test_synchronousImplicitChain+DeferredTests.test_synchronousImplicitChain  s     f%!),-*,'..)'!*%7>>*gaj&)r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     1 1 1r9   c                  a \        4       o\        4       pVP                  V3R l4       VP                  R4       . pSP                  VP                  4       . pVP                  VP                  4       V P	                  V. 4       V P	                  V. 4       \        4       pSP                  V4       V P	                  VR.4       V P	                  W4.4       R# )a  
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 L{None}.
c                   < S# rA   r5   r  s   &r7   r?  >DeferredTests.test_asynchronousImplicitChain.<locals>.<lambda>  r  r9   N)r    r   rX   rf   rg   r=   )rl   r  r1  secondResultr}   r  s   &    @r7   test_asynchronousImplicitChain,DeferredTests.test_asynchronousImplicitChain  s     #+*#+:,-$&+,,-%'<../b)r*vtf-x0r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     : :D :r9   c                D   \         P                  ! \        R4      4      pV3R R llp\        4       pVP	                  V4       VP                  R4       . pVP	                  VP                  4       V P                  V^ ,          4       V P                  V\        4       R# )z
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.
First Deferred's Failurec               $    V ^8  d   QhRRRRRR/# )r2   r  rT   r  r  r4   r5   )r6   s   "r7   r8   FDeferredTests.test_synchronousImplicitErrorChain.<locals>.__annotate__  s!     	 	$ 	~ 	. 	r9   c                    V# rA   r5   )r  r  s   &&r7   r   <DeferredTests.test_synchronousImplicitErrorChain.<locals>.cb  s    Lr9   N)	r   r  rx   r    r   rX   rf   r   ro   )rl   r  r   r  r1  s   &    r7   "test_synchronousImplicitErrorChain0DeferredTests.test_synchronousImplicitErrorChain  s~     

<(BCD05 	 "*2"$+,,-+a.)##FL9r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     / /T /r9   c                X  a \        4       o\        4       pVP                  V3R l4       VP                  R4       . pVP                  VP                  4       . pSP                  VP                  4       . pVP                  VP                  4       V P                  V. 4       V P                  V. 4       SP                  \        R4      4       V P                  V^ ,          P                  \        4      4       V P                  VR.4       V P                  \        V4      ^4       R# )a   
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 L{None} so that no unhandled error is logged
when it is garbage collected.
c                   < S# rA   r5   r  s   &r7   r?  CDeferredTests.test_asynchronousImplicitErrorChain.<locals>.<lambda>  r  r9   Nr  )r    r   rX   re   rf   rg   r   rx   ri   rj   rh   )rl   r  secondErrorr1  r  r  s   &    @r7   #test_asynchronousImplicitErrorChain1DeferredTests.test_asynchronousImplicitErrorChain  s     !)
!),-%'+,,-"$+,,-#%<../b)r*l#=>?A,,\:;tf-\*A.r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     0 0 0r9   c                  aa \        4       o\        4       oSP                  V3R l4       \        4       pVP                  V3R l4       . pVP                  VP                  4       \        4       pSP	                  R4       VP	                  R4       V P                  V. 4       SP	                  V4       V P                  W#.4       R# )z
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.
c                   < S# rA   r5   r  s   &r7   r?  GDeferredTests.test_doubleAsynchronousImplicitChaining.<locals>.<lambda>  r  r9   c                   < S# rA   r5   )r  r  s   &r7   r?  r#    s    fr9   N)r    r   rf   r=   rX   rg   )rl   thirdthirdResultr}   r  r  s   &   @@r7   'test_doubleAsynchronousImplicitChaining5DeferredTests.test_doubleAsynchronousImplicitChaining  s     #+*#+:,-"**,-$&+,,-t 	b) 	vh/r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     ;
 ;
 ;
r9   c                  aaa . o. o\        4       oR VVV3R llp\        P                  ! R4      P                  V4      P                  SP                  4      pV P                  SRR.4       SP                  R4       SP                  SP                  4       VP                  SP                  4       V P                  . SR4       V P                  S. R	O4       R# )
z
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.
c                    V ^8  d   QhRRRR/# rs  r5   )r6   s   "r7   r8   KDeferredTests.test_nestedAsynchronousChainedDeferreds.<locals>.__annotate__"  s     	 	s 	} 	r9   c                   < SP                  R V 34       \        P                  ! R4      pR VV3R llpR V3R llpVP                  V4      P                  V4       VP	                  SP                   4       V# )rv  rw  c                    V ^8  d   QhRRRR/# rs  r5   )r6   s   "r7   r8   WDeferredTests.test_nestedAsynchronousChainedDeferreds.<locals>.cb.<locals>.__annotate__&  s      c m r9   c                *   < SP                  R4       S# r{  r  r~  s   &r7   r|  XDeferredTests.test_nestedAsynchronousChainedDeferreds.<locals>.cb.<locals>.firstCallback&  s    9: r9   c                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   r/  ,  r  r9   c                <   < SP                  R V 34       V ^,          # r  r  r  s   &r7   r  YDeferredTests.test_nestedAsynchronousChainedDeferreds.<locals>.cb.<locals>.secondCallback,  r  r9   r  r  s   &   r7   r   ADeferredTests.test_nestedAsynchronousChainedDeferreds.<locals>.cb"  sd    NNM623g&A " " MM-(44^DLL)Hr9   r  r  &Got errbacks but wasn't expecting any.Nr  r}  r  r    r   r  r   rf   rg   rX   re   r  s   &  @@@r7   'test_nestedAsynchronousChainedDeferreds5DeferredTests.test_nestedAsynchronousChainedDeferreds  s     68"$  (z	 	, MM'"..r2>>w~~N 	
 	.0JK	
 	x  	))X'OP	
r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r   S  s     F
 F
4 F
r9   c                  aaa . o. o\        4       oR VVV3R llp\        P                  ! R4      pVP                  V4       VP                  SP                  4       V P                  SRR	.4       SP                  R4       VP                  SP                  4       SP                  SP                  4       V P                  . SR4       V P                  SRR	RR.3RR..4       R# )
a  
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.
c                    V ^8  d   QhRRRR/# )r2   r}   r   r4   zDeferred[Optional[List[str]]]r5   )r6   s   "r7   r8   ]DeferredTests.test_nestedAsynchronousChainedDeferredsWithExtraCallbacks.<locals>.__annotate__b  s     	 	s 	< 	r9   c                   < SP                  R V 34       \        P                  ! R4      pR VV3R llpR V3R llpVP                  V4      P                  V4      P	                  SP                   4      # )rv  rw  c                    V ^8  d   QhRRRR/# )r2   r}   r   r4   r  r5   )r6   s   "r7   r8   iDeferredTests.test_nestedAsynchronousChainedDeferredsWithExtraCallbacks.<locals>.cb.<locals>.__annotate__f  s     
4 
4c 
4.A 
4r9   c                X   < SP                  R V 34       R R lpSP                  V4      # )r|  c                    V ^8  d   QhRRRR/# )r2   r}   r   r4   r  r5   )r6   s   "r7   r8   ڀDeferredTests.test_nestedAsynchronousChainedDeferredsWithExtraCallbacks.<locals>.cb.<locals>.firstCallback.<locals>.__annotate__m  s     $ $c $i $r9   c                    V .# rA   r5   r  s   &r7   	transform}DeferredTests.test_nestedAsynchronousChainedDeferredsWithExtraCallbacks.<locals>.cb.<locals>.firstCallback.<locals>.transformm  s	    "8Or9   r  )r}   rE  rw  r  s   & r7   r|  jDeferredTests.test_nestedAsynchronousChainedDeferredsWithExtraCallbacks.<locals>.cb.<locals>.firstCallbackf  s,    89$ ((33r9   c                    V ^8  d   QhRRRR/# )r2   r}   r  r4   r5   )r6   s   "r7   r8   r@  r  s     " "y "Y "r9   c                <   < SP                  R V 34       V ^,          # r  r  r  s   &r7   r  kDeferredTests.test_nestedAsynchronousChainedDeferredsWithExtraCallbacks.<locals>.cb.<locals>.secondCallbackr  r  r9   r  r  s   &   r7   r   SDeferredTests.test_nestedAsynchronousChainedDeferredsWithExtraCallbacks.<locals>.cbb  sa    NNM623g&A
4 
4" "
 m,^,HOO,r9   r  r  r6  r  Nr  r}  r7  r  s   &  @@@r7   9test_nestedAsynchronousChainedDeferredsWithExtraCallbacksGDeferredTests.test_nestedAsynchronousChainedDeferredsWithExtraCallbacksS  s      "$  (z	 	: g&"'..) 	.0JK	
 	y! 	))X'OP(*!I;/I&		
r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     ' ' 'r9   c                    \        4       p\        4       pVP                  V4       V P                  VP                  V4       R# )zD
When we chain a L{Deferred}, that chaining is recorded explicitly.
N)r    chainDeferredr{   
_chainedTorl   r  bs   &  r7   &test_chainDeferredRecordsExplicitChain4DeferredTests.test_chainDeferredRecordsExplicitChain  s0     %J$J	allA&r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     ( (t (r9   c                    \        4       p\        4       pVP                  V4       VP                  R4       V P                  VP                  4       R# )a"  
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)r    rP  rX   r   rQ  rR  s   &  r7   %test_explicitChainClearedWhenResolved3DeferredTests.test_explicitChainClearedWhenResolved  s<     %J$J		

4!,,'r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     
' 
' 
'r9   c                   a \        4       p\        4       oVP                  V3R l4       VP                  R4       V P                  VP                  S4       R# )z
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.
c                   < S# rA   r5   )r  rS  s   &r7   r?  FDeferredTests.test_chainDeferredRecordsImplicitChain.<locals>.<lambda>  s    ar9   N)r    r   rX   r{   rQ  rR  s   & @r7   &test_chainDeferredRecordsImplicitChain4DeferredTests.test_chainDeferredRecordsImplicitChain  s>     %J$J	'(	

4allA&r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     
 
4 
r9   c                  a \        4       oR V3R llpSP                  V4       SP                  R4       V P                  V.4      pV P	                  \        V4      ^4       V^ ,          pV P	                  VR,          \        4       RpV P                  \        P                  ! WCR,          4      RP                  WCR,          4      4       R# )	zl
When a Deferred is returned from a callback directly attached to that
same Deferred, a warning is emitted.
c                    V ^8  d   QhRRRR/# rs  r5   )r6   s   "r7   r8   =DeferredTests.test_circularChainWarning.<locals>.__annotate__       	 	S 	] 	r9   c                   < S# rA   r5   r}   r  s   &r7   circularCallbackADeferredTests.test_circularChainWarning.<locals>.circularCallback      Hr9   foor   z1Callback returned the Deferred it was attached tor   z
Expected match: {!r}
Got: {!r}N)r    r   rX   r   rg   rh   r   ri   researchr6   )rl   rg  circular_warningswarningpatternr  s   &    @r7   test_circularChainWarning'DeferredTests.test_circularChainWarning  s    
 $:	 	 	
&'	

5 ..0@/AB./3#A&,.@AEIIgy12/66w	@RS	
r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     ) )T )r9   c                J  a V P                  \        \        R\        P                  4       \        P                  ! R\
        R7       \        4       oR V3R llpSP                  V4       SP                  R4       V P                  S4      pVP                  \
        4       R# )z
If the deprecation warning for circular deferred callbacks is
configured to be an error, the exception will become the failure
result of the Deferred.
filtersr|   )r   c                    V ^8  d   QhRRRR/# rs  r5   )r6   s   "r7   r8   ?DeferredTests.test_circularChainException.<locals>.__annotate__  rd  r9   c                   < S# rA   r5   rf  s   &r7   rg  CDeferredTests.test_circularChainException.<locals>.circularCallback  ri  r9   rj  N)r   setattrr   rt  filterwarningsr   r    r   rX   rP  trap)rl   rg  failurer  s   &  @r7   test_circularChainException)DeferredTests.test_circularChainException  s     			
 	2DE#:	 	 	
&'	

5&&q)'(r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     B B4 Br9   c                p    \        4       p\        V4      pV P                  \        V4      RVR R24       R# )zh
The C{repr()} of a L{Deferred} contains the class name and a
representation of the internal Python ID.
<Deferred at 0xr  >N)r    idrg   repr)rl   r  addresss   &  r7   	test_reprDeferredTests.test_repr  s3    
 %JQ%aOGA;a"@Ar9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     Y YT Yr9   c                    \        4       pVP                  R4       V P                  \        V4      R\	        V4      R R24       R# )zJ
If a L{Deferred} has been fired, then its C{repr()} contains its
result.
r  r  r  z current result: 'orange'>N)r    rX   rg   r  r  r  s   & r7   test_reprWithResult!DeferredTests.test_reprWithResult  s;    
 $:	

8aOBqE!9<V"WXr9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     
 
t 
r9   c           	         \        4       p\        4       pVP                  V4       V P                  \        V4      R\	        V4      R R\	        V4      R R24       R# )z
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}.
r  r  z waiting on Deferred at 0xr  N)r    rP  rg   r  r  rR  s   &  r7   test_reprWithChaining#DeferredTests.test_reprWithChaining  sR     %J$J	GbeAY&@Aq	K	
r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     9? 9? 9?r9   c                V   a  R V 3R llpS P                  V! ^4      V! ^4      4       R# )z_
The depth of the call stack does not grow as more L{Deferred} instances
are chained together.
c                    V ^8  d   QhRRRR/# )r2   howManyr  r4   r5   )r6   s   "r7   r8   :DeferredTests.test_boundedStackDepth.<locals>.__annotate__  s     /	 /	C /	C /	r9   c                `  <a
a . oR  V3R llp\        4       p\        V 4       Uu. uF  p\        4       NK  	  ppVR,          p\        4       o
VP                  4       pV3R R llpVP                  V4       VP                  V4       V'       d/   VP                  4       pV3R R llp	VP                  V	4       TpK6  VP                  V
3R l4       VP	                  R4       V F  pVP	                  R4       K  	  SP                  S. 4       S
P	                  R4       S^ ,          # u upi )	c                    V ^8  d   QhRRRR/# r2   r  r=   r4   rT   r5   )r6   s   "r7   r8   RDeferredTests.test_boundedStackDepth.<locals>.chainDeferreds.<locals>.__annotate__  s     = =& =T =r9   c                b   < SP                  \        \        P                  ! 4       4      4       R # rA   )rf   rh   	tracebackextract_stack)r  stacks   &r7   recordStackDepthVDeferredTests.test_boundedStackDepth.<locals>.chainDeferreds.<locals>.recordStackDepth  s    S!8!8!:;<r9   r  c               $    V ^8  d   QhRRRRRR/# r2   r  r=   rw  r  r4   r5   )r6   s   "r7   r8   r  "  s$      (6r9   c                    V# rA   r5   r  rw  s   &&r7   cbInnerMDeferredTests.test_boundedStackDepth.<locals>.chainDeferreds.<locals>.cbInner"  s	     r9   c               $    V ^8  d   QhRRRRRR/# r  r5   )r6   s   "r7   r8   r  -  s$     ! !#!,:!#!r9   c                    V# rA   r5   r  s   &&r7   
cbNewInnerPDeferredTests.test_boundedStackDepth.<locals>.chainDeferreds.<locals>.cbNewInner-  s	     !Lr9   c                   < S# rA   r5   )r  lasts   &r7   r?  NDeferredTests.test_boundedStackDepth.<locals>.chainDeferreds.<locals>.<lambda>5  s    $r9   N)r    rangepopr   rX   rg   )r  r  topr  innerDeferredsoriginalInnersrw  r  newInnerr  r  r  rl   s   &         @@r7   chainDeferreds<DeferredTests.test_boundedStackDepth.<locals>.chainDeferreds  s   E= = #+*C*/.4*8w
.  4 ,A.N#+:D"&&(E :?
 OOG$OO,- )--/ >F!
 !!*- ./LL't$ (
 UB' MM$8OQ4s   D+N)rg   )rl   r  s   f r7   test_boundedStackDepth$DeferredTests.test_boundedStackDepth  s*    /	 /	f 	*N1,=>r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r   H  s     * *D *r9   c                `  aa \        4       p\        4       o\        4       oVP                  V3R l4       SP                  V3R l4       SP                  R4       VP                  R4       SP                  R4       . pSP                  VP                  4       V P	                  VR.4       R# )a  
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.
c                   < S# rA   r5   r  s   &r7   r?  ZDeferredTests.test_resultOfDeferredResultOfDeferredOfFiredDeferredCalled.<locals>.<lambda>V  r  r9   c                   < S# rA   r5   )r  r%  s   &r7   r?  r  W  s    5r9   N)r    r   rX   rf   rg   )rl   r  r  r  r%  s   &  @@r7   :test_resultOfDeferredResultOfDeferredOfFiredDeferredCalledHDeferredTests.test_resultOfDeferredResultOfDeferredOfFiredDeferredCalledH  s     !)
!) (
0101tt 7>>*4&)r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r   _  s     & &t &r9   c                   \         P                  ! R4       \        4       p. p\        R4      p Vh  \         d    TP                  4         Mi ; iTP                  TP                  4       T^ ,          pT P                  TP                  T4       TP                  ^ ,          RR w  rVT P                  RT4       T P                  RT4       R# )z
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.
Fr,  Nr5   )r   r   r    rJ   BaseExceptionr   re   rf   rg   rk   framesrl   r  r  excr  localzglobalzs   &      r7   test_errbackWithNoArgsNoDebug+DeferredTests.test_errbackWithNoArgsNoDebug_  s     	5!$J6"	I 	IIK		QXXtS)++a.-V$W%   1 AAc                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r   t  s     ) ) )r9   c                   \         P                  ! R4       \        4       p. p\        R4      p Vh  \         d    TP                  4         Mi ; iTP                  TP                  4       T^ ,          pT P                  TP                  T4       TP                  ^ ,          RR w  rVT P                  . T4       T P                  . T4       R# )z
C{Deferred.errback()} creates a failure from the current Python
exception.  When Deferred.debug is set globals and locals are captured
in that failure.
Tr,  Nr  )r   r   r    rJ   r  r   re   rf   rg   rk   r  assertNotEqualr  s   &      r7   test_errbackWithNoArgs$DeferredTests.test_errbackWithNoArgst  s     	4 $J6"	I 	IIK		QXXtS)++a.-B'B(r  c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     & & &r9   c                Z   \        4       pVP                  R4       \        P                  ! R4       R R lpVP	                  V4       . pVP                  VP                  4       V^ ,          pVP                  ^ ,          RR w  rVV P                  RV4       V P                  RV4       R# )
An error raised by a callback creates a Failure.  The Failure captures
locals and globals if and only if C{Deferred.debug} is set.
NFc                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   JDeferredTests.test_errorInCallbackDoesNotCaptureVars.<locals>.__annotate__       	' 	' 	'4 	'r9   c                    \        R 4      hr,  rJ   r  s   &r7   
raiseErrorHDeferredTests.test_errorInCallbackDoesNotCaptureVars.<locals>.raiseError      v&&r9   r  r5   )	r    rX   r   r   r   re   rf   r  rg   rl   r  r  r  r  r  r  s   &      r7   &test_errorInCallbackDoesNotCaptureVars4DeferredTests.test_errorInCallbackDoesNotCaptureVars  s    
 %J	

45!	' 	
j!	QXXt++a.-V$W%r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     ) )t )r9   c                Z   \        4       pVP                  R4       \        P                  ! R4       R R lpVP	                  V4       . pVP                  VP                  4       V^ ,          pVP                  ^ ,          RR w  rVV P                  . V4       V P                  . V4       R# )r  NTc                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   QDeferredTests.test_errorInCallbackCapturesVarsWhenDebugging.<locals>.__annotate__  r  r9   c                    \        R 4      hr  r  r  s   &r7   r  ODeferredTests.test_errorInCallbackCapturesVarsWhenDebugging.<locals>.raiseError  r  r9   r  )	r    rX   r   r   r   re   rf   r  r  r  s   &      r7   -test_errorInCallbackCapturesVarsWhenDebugging;DeferredTests.test_errorInCallbackCapturesVarsWhenDebugging  s    
 %J	

44 	' 	
j!	QXXt++a.-B'B(r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     
5 
5D 
5r9   c                    R R lp\         P                  ! V! 4       4      p\        V\         \        ,          4       V P	                  ^V P                  V4      4       R# )z=
It can discover the return type of a first level coroutine.
c                   V ^8  d   QhRR/# rA  r5   )r6   s   "r7   r8   6DeferredTests.test_fromCoroutine.<locals>.__annotate__  s     	 	# 	r9   c                    "   ^# 5ir  r5   r5   r9   r7   
returnsInt4DeferredTests.test_fromCoroutine.<locals>.returnsInt  rH  rI  N)r    rB   r   r  rg   rY  )rl   r  r  s   &  r7   test_fromCoroutine DeferredTests.test_fromCoroutine  sD    
	 "":<0Ax}%D0034r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r          W WT Wr9   c                    R ^RV P                   R\        .pV F2  pV P                  \        P                  \        P
                  V4       K4  	  R# )q
L{Deferred.fromCoroutine} requires a coroutine object or a generator,
and will reject things that are not that.
c                    V # rA   r5   r  s   &r7   r?  CDeferredTests.test_fromCoroutineRequiresCoroutine.<locals>.<lambda>      ar9   TN#test_fromCoroutineRequiresCoroutiner   assertRaisesNotACoroutineErrorr    rB   rl   thingsThatAreNotCoroutinesthings   &  r7   r  1DeferredTests.test_fromCoroutineRequiresCoroutine  O     44&
" 0Ee668N8NPUV 0r9   GC works differently on PyPy.c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     * *D *r9   c                   \        4       p\        P                  ! V4      p\        V4      pW1n        \        P                  ! V4      pVP                  R4       ??V P                  V! 4       4       V P                  V! 4       4       R# )zd
A circular reference between a `Deferred` and its canceller
is broken when the deferred is called.
N)DummyCancellerweakrefrefr    rR   rX   r   )rl   	cancellerweakCancellerrR   weakDeferreds   &    r7   *test_canceller_circular_reference_callback8DeferredTests.test_canceller_circular_reference_callback  sr     #$	I. #+9"5%{{8,$  	-/*,.)r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     * *4 *r9   c                \   \        4       p\        P                  ! V4      p\        V4      pW1n        \        P                  ! V4      p\        \        R4      4      pVP                  V4       V P                  V4       ??V P                  V! 4       4       V P                  V! 4       4       R# )z`
A circular reference between a `Deferred` and its canceller
is broken when the deferred fails.
The test demands failures.N)
r  r  r  r    rR   r/   rm  r   rP  r   )rl   r  r  rR   r  r|  s   &     r7   )test_canceller_circular_reference_errback7DeferredTests.test_canceller_circular_reference_errback  s     #$	I. #+9"5%{{8,)$@AB! 	X& 	-/*,.)r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r     s     + +T +r9   c                    \        4       p\        P                  ! V4      p\        V4      pW1n        VP                  R 4       VP                  R4       ??V P                  V! 4       4       R# )z
A circular reference between a `Deferred` and its canceller is broken
when the deferred is called, even if another deferred gets added to its
chain.
c                    \        4       # rA   )r    r  s   &r7   r?  KDeferredTests.test_canceller_circular_reference_non_final.<locals>.<lambda>"  s    xzr9   N)r  r  r  r    rR   r   rX   r   )rl   r  r  rR   s   &   r7   +test_canceller_circular_reference_non_final9DeferredTests.test_canceller_circular_reference_non_final  sa     #$	I. #+9"5%12$ 	-/*r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r   ,  s     9 9$ 9r9   c                   V P                  \        P                  R,          \        \        .4        ! R R\        \
        ,          4      pV P                  \        P                  R,          V4       \        P                  P                  R4       \        P                   F"  pV P                  \        V\        4      4       K$  	  R# )zA
C{_DEFERRED_SUBCLASSES} includes all subclasses of L{Deferred}.
:Nr2   Nc                      ] tR tRtRtR# )2DeferredTests.test_DEFERRED_SUBCLASSES.<locals>.D2i2  r5   NrK   r5   r9   r7   D2r  2  re  r9   r  N)	rg   r   _DEFERRED_SUBCLASSESr    r"   r  r  ri   r!  )rl   r  klasss   &  r7   test_DEFERRED_SUBCLASSES&DeferredTests.test_DEFERRED_SUBCLASSES,  s     	33B7(L9QR	# 	 	33B7<""&&r* //EOOJuh78 0r9   )r   r   r   N)^rL   rM   rN   rO   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r(  r2  r8  rD  rJ  rU  r\  r`  rd  ri  rm  rt  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r%  r-  r5  r;  rK  r^  rn  r  r  r  r  r  r  r  r  r  r  r'  r8  rL  rT  rX  r^  rp  r}  r  r  r  r  r  r  r  r  r  r  r  pyunitskipIfr-   r  r  r  r  rP   r5   r9   r7   r   r      s   B-+AIQB

5A"5,"
H%('.R?"?"&&"
@B$
@9K:"+ ).)=)222
=
6
<3,-() & >(K?1( >"2$
.	6ED2
.*
X%
N-
^,.)(>(*&14:(/:0>;
zF
P'(
'
.).BY
9?v*.&*)*&()(
5W. ]]59:* ;*8 ]]59:* ;*> ]]59:+ ;+49 9r9   r   c                  6    ] tR tRt$ RtRtR]R&   R R ltRtR# )	r  i>  zv
A callable that does nothing.
It is intended to be used just to get an object reference
to support GC related tests.
NzOptional[Deferred[Any]]rR   c                    V ^8  d   QhRRRR/# )r2   rR   r`   r4   rT   r5   )r6   s   "r7   r8   DummyCanceller.__annotate__G  s       4 r9   c                    R# )zF
This is not expected to be called as part of the current test suite.
Nr5   r   s   &&r7   __call__DummyCanceller.__call__G  s    r9   r5   )	rL   rM   rN   rO   rq   rR   __annotations__r%  rP   r5   r9   r7   r  r  >  s     )-H%, r9   r  c                    V ^8  d   QhRRRR/# )r2   numDeferredsr  r4   z(tuple[list[int], list[Deferred[object]]]r5   )r6   s   "r7   r8   r8   M  s      # *R r9   c                   a ^ .V ,          o. p\        V 4       F*  pV3R V3R lllpVP                  \        VR7      4       K,  	  SV3# )z
Create a list of Deferreds and a corresponding list of integers
tracking how many times each Deferred has been cancelled.  Without
additional steps the Deferreds will never fire.
c               $    V ^8  d   QhRRRRRR/# )r2   r  ry  nr  r4   rT   r5   )r6   s   "r7   r8   %_setupRaceState.<locals>.__annotate__X  s"     	# 	#& 	#3 	#t 	#r9   c                2   < SV;;,          ^,          uu&   R# r  r5   )r  r,  cancelledStates   &&r7   rO  _setupRaceState.<locals>.cancelX  s    1"r9   r  )r  rf   r    )r)  dsr,  rO  r/  s   &   @r7   _setupRaceStater3  M  sR     S<'N!#B< 12 	# 	# 			(V,- ! 2r9   c                  ,   ] tR tRtRt]! ]! ^ ^R7      ]! ^ ^R7      R7      R R l4       t]! ]! ^ ^R7      ]! ^ ^R7      R7      R R l4       t]! ]! ^ ^R7      ]! ^ ^R7      R7      R	 R
 l4       t	R R lt
]! ]! ^^R7      R7      R R l4       tRtR# )	RaceTestsi`  z
Tests for L{race}.
)	min_value	max_value)beforeWinnerafterWinnerc               $    V ^8  d   QhRRRRRR/# r2   r8  r  r9  r4   rT   r5   )r6   s   "r7   r8   RaceTests.__annotate__i  s!     
 
 
3 
4 
r9   c                J   \        V^,           V,           4      w  r4\        V4      p\        4       pWA,          P                  V4       \	        V P                  V4      \        W34      4       ^.V,          ^ .,           ^.V,          ,           p\	        V\        V4      4       R# )a  
When one of the L{Deferred}s passed to L{race} fires successfully,
the L{Deferred} return by L{race} fires with the index of that
L{Deferred} and its result and cancels the rest of the L{Deferred}s.

@param beforeWinner: A randomly selected number of Deferreds to
    appear before the "winning" Deferred in the list passed in.

@param beforeWinner: A randomly selected number of Deferreds to
    appear after the "winning" Deferred in the list passed in.
N)r3  r*   r=   rX   r   rY  r   )rl   r8  r9  r/  r2  
raceResultr  expectedCancelledStates   &&&     r7   test_successRaceTests.test_successe  s      -\A-=-KL"X
8
!!(+ 	  ,l-.	

 #$|!3qc!9QC+<M!M+,	
r9   c               $    V ^8  d   QhRRRRRR/# r;  r5   )r6   s   "r7   r8   r<    s!     
 
 
3 
4 
r9   c           	        \        V^,           V,           4      w  r4\        \        R4      4      p\        V4      pV F  pVP	                  V4       K  	  V P                  V\        4      p\        VP                  P                  \        V.\        V4      ,          4      4       \        V\        ^ .\        V4      ,          4      4       R# )a  
When all of the L{Deferred}s passed to L{race} fire with failures,
the L{Deferred} return by L{race} fires with L{FailureGroup} wrapping
all of their failures.

@param beforeWinner: A randomly selected number of Deferreds to
    appear before the "winning" Deferred in the list passed in.

@param beforeWinner: A randomly selected number of Deferreds to
    appear after the "winning" Deferred in the list passed in.
r  N)r3  r/   rm  r*   r   rP  r&   r   rk   rn   r   rh   )	rl   r8  r9  r/  r2  r|  r>  r  actualFailures	   &&&      r7   test_failureRaceTests.test_failure  s      -\A-=-KL)$@AB"X
AIIg  ,,ZF((gYR()	
 	aS3r7]#	
r9   c               $    V ^8  d   QhRRRRRR/# r;  r5   )r6   s   "r7   r8   r<    s!     7 73 7S 7T 7r9   c                V   \        V^,           V,           4       Uu. uF  p\        4       NK  	  pp\        V4      pWA,          P                  R4       WA^,           ,          P                  R4       V P	                  V4       \        V P                  4       \        4       4       R# u upi )z
If one of the Deferreds fires after it was cancelled its result
goes nowhere.  In particular, it does not cause any errors to be
logged.
N)r  r    r*   rX   rY  r   rz   r   )rl   r8  r9  r,  r2  r>  s   &&&   r7   test_resultAfterCancel RaceTests.test_resultAfterCancel  s     !&lQ&6&D E$
 E1HJ E 	 $
 "X

!!$'
!%%d+Z(D**,eg6$
s   B&c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r<    s     O Ot Or9   c                    \        4       pV\        R R7      .p\        4       p\        V4      pVP                  V4       \	        V P                  V4      \        ^ V34      4       R# )zf
If one of the input Deferreds has a cancel function that fires it
with success, nothing bad happens.
c                4    V P                  \        4       4      # rA   )rX   r=   r  s   &r7   r?  1RaceTests.test_resultFromCancel.<locals>.<lambda>  s    FH)=r9   r1  N)r    r=   r*   rX   r   rY  r   )rl   winnerr2  r  r>  s   &    r7   test_resultFromCancelRaceTests.test_resultFromCancel  sZ    
 $,:=>&
 8"X
!D((4h8}6MNr9   )r)  c                    V ^8  d   QhRRRR/# )r2   r)  r  r4   rT   r5   )r6   s   "r7   r8   r<    s     7 7 7 7r9   c                    \        V4      w  r#\        V4      pVP                  4        \        V\	        ^.V,          4      4       V P                  V\        4       R# )z]
If the result of L{race} is cancelled then all of the L{Deferred}s
passed in are cancelled.
N)r3  r*   rO  r   r   rP  r&   )rl   r)  r/  r2  r>  s   &&   r7   test_cancelRaceTests.test_cancel  sL     -\:"X
NHaS<-?$@AZ6r9   r5   N)rL   rM   rN   rO   rq   r   r   r@  rE  rI  rQ  rU  rP   r5   r9   r7   r5  r5  `  s     Q7qA6
	
> Q7qA6
	
: Q7qA67	7&O  Q777r9   r5  c                  >    ] tR tRtRtR R ltR R ltR R ltR	tR
# )FirstErrorTestsi  z
Tests for L{FirstError}.
c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   FirstErrorTests.__annotate__  s     F F4 Fr9   c                    \        R4      p Vh  \         d    \        4       p Mi ; i\        P                  ! T^4      pT P                  \        T4      R\        T4       R24       R# )z
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}.
	some textzFirstError[#3, ]N)r  r  r/   r   r#  rg   r  rl   r  r3   r|   s   &   r7   r  FirstErrorTests.test_repr  sc    
 %	I 		A	   A&eS	{!&DE    ''c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   rZ    s     B B$ Br9   c                    \        R4      p Vh  \         d    \        4       p Mi ; i\        P                  ! T^4      pT P                  \        T4      R\        T4       R24       R# )z
The str of a L{FirstError} instance includes the str of the
sub-failure and the index which corresponds to the L{FirstError}.
r\  zFirstError[#5, r]  N)r  r  r/   r   r#  rg   r   r^  s   &   r7   test_strFirstErrorTests.test_str  sc    
 %	I 		A	   A&Us1vha%@Ar`  c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   rZ    s     $ $ $r9   c                    ^^ ,           \        P                  ! X^4      p\        P                  ! V^4      p \	        R4      h  \          d    \        4       p LQi ; i  \          d    \        4       p Mi ; i\        P                  ! T^	4      pT P                  Y#8H  4       T P                  Y%8H  4       T P                  Y%8g  4       T P                  Y#8g  4       T P                  T^
8H  4       R# )z
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.
barN)r  r/   r   r#  r  ri   rZ  )rl   firstFailureone
anotherOnesecondFailureanothers   &     r7   test_comparisonFirstErrorTests.test_comparison  s    	%F |R0%%lB7
	&U##  	%"9L	%  	&#IM	& ""=!4)*('*+#s"   	A A  AA A87A8r5   N)	rL   rM   rN   rO   rq   r  rc  rm  rP   r5   r9   r7   rX  rX    s    FB$ $r9   rX  c                     ] tR tRtR R ltR R ltR R ltR R	 ltR
 R ltR R lt	R R lt
R R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR  R! ltR" R# ltR$ R% ltR& R' ltR( R) ltR*tR+# ),AlreadyCalledTestsi  c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   AlreadyCalledTests.__annotate__   s     ! !t !r9   c                	f    \         P                  ! 4       V n        \         P                  ! R 4       R# TN)r   r   _deferredWasDebuggingr   r   s   &r7   r   AlreadyCalledTests.setUp   s!    %*%7%7%9"4 r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   rr  $  s     7 7$ 7r9   c                	F    \         P                  ! V P                  4       R # rA   )r   r   ru  r   s   &r7   tearDownAlreadyCalledTests.tearDown$  s    4556r9   c               $    V ^8  d   QhRRRRRR/# r   r5   )r6   s   "r7   r8   rr  '  s!      v  D r9   c                	    R # rA   r5   r   s   &*,r7   r   AlreadyCalledTests._callback'      r9   c               $    V ^8  d   QhRRRRRR/# r   r5   )r6   s   "r7   r8   rr  *  s!      f  4 r9   c                	    R # rA   r5   r   s   &*,r7   r   AlreadyCalledTests._errback*  r~  r9   c                    V ^8  d   QhRRRR/# r2   r  rS   r4   rT   r5   )r6   s   "r7   r8   rr  -         4 r9   c                	(    VP                  R 4       R# )r   NrW   r  s   &&r7   _call_1AlreadyCalledTests._call_1-      	

7r9   c                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   rr  0  r  r9   c                	(    VP                  R 4       R# )twiceNrW   r  s   &&r7   _call_2AlreadyCalledTests._call_20  r  r9   c                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   rr  3       + + +$ +r9   c                	J    VP                  \        \        4       4      4       R # rA   r   r/   rx   r  s   &&r7   _err_1AlreadyCalledTests._err_13      			',.)*r9   c                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   rr  6  r  r9   c                	J    VP                  \        \        4       4      4       R # rA   r  r  s   &&r7   _err_2AlreadyCalledTests._err_26  r  r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   rr  9       E Ed Er9   c                	    \        4       pVP                  V P                  V P                  4       V P	                  V4       V P                  \        P                  V P                  V4       R # rA   )	r    r   r   r   r  r  r   AlreadyCalledErrorr  r  s   & r7   testAlreadyCalled_CC'AlreadyCalledTests.testAlreadyCalled_CC9  sF    #:	t~~t}}5Q%22DLL!Dr9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   rr  ?       D Dd Dr9   c                	    \        4       pVP                  V P                  V P                  4       V P	                  V4       V P                  \        P                  V P                  V4       R # rA   )	r    r   r   r   r  r  r   r  r  r  s   & r7   testAlreadyCalled_CE'AlreadyCalledTests.testAlreadyCalled_CE?  sF    #:	t~~t}}5Q%22DKKCr9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   rr  E  r  r9   c                	    \        4       pVP                  V P                  V P                  4       V P	                  V4       V P                  \        P                  V P                  V4       R # rA   )	r    r   r   r   r  r  r   r  r  r  s   & r7   testAlreadyCalled_EE'AlreadyCalledTests.testAlreadyCalled_EEE  sF    #:	t~~t}}5A%22DKKCr9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   rr  K  r  r9   c                	    \        4       pVP                  V P                  V P                  4       V P	                  V4       V P                  \        P                  V P                  V4       R # rA   )	r    r   r   r   r  r  r   r  r  r  s   & r7   testAlreadyCalled_EC'AlreadyCalledTests.testAlreadyCalled_ECK  sF    #:	t~~t}}5A%22DLL!Dr9   c          
     ,    V ^8  d   QhRRRRRRRRRR	/# )
r2   linetyper   funclinesr  r  r  r4   rT   r5   )r6   s   "r7   r8   rr  Q  s0     + +s +# +i +3 +SW +r9   c                	    ^ pV FL  pVP                  RV,          4      '       g   K#  VP                  RV,          4      '       g   KC  V^,          pKN  	  V P                  WT8H  4       R# )r   z %s:z %sN)r   endswithri   )rl   r  r  r  r  countlines   &&&&&  r7   _countAlreadyCalledTests._countQ  sQ    Dv011dmmEDL6Q6Q
  	)*r9   c          
     ,    V ^8  d   QhRRRRRRRRRR/# )	r2   r>  rm  callerr   invoker1invoker2r4   rT   r5   )r6   s   "r7   r8   rr  X  s0     - -	 -3 -# - -QU -r9   c                	\   VP                   ^ ,          P                  R4      pV P                  RW%^4       V P                  RRV^ 4       V P                  RRV^ 4       V P                  RRV^ 4       V P                  RRV^ 4       V P                  RW5^4       V P                  RWE^ 4       R# )	r   
Cr  r  r  r  IN)r<   splitr  )rl   r>  r  r  r  r  s   &&&&& r7   _checkAlreadyCalledTests._checkX  s    q	% 	C*CE1-CE1-C5!,C5!,C!,C!,r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   rr  f       	L 	L4 	Lr9   c                	<   \        4       pVP                  V P                  V P                  4       V P	                  V4        V P                  V4       V P                  R 4       R#   \        P                   d    pT P                  TRRR4        Rp?R# Rp?ii ; i)2second callback failed to raise AlreadyCalledErrortestAlreadyCalledDebug_CCr  r  N)
r    r   r   r   r  r  r  r   r  r  rl   r  r>  s   &  r7   r  ,AlreadyCalledTests.testAlreadyCalledDebug_CCf  sz    #:	t~~t}}5Q	LLLO IIJK '' 	NKK6	9MM	N   A' 'B<BBc                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   rr  q       	K 	K4 	Kr9   c                	<   \        4       pVP                  V P                  V P                  4       V P	                  V4        V P                  V4       V P                  R 4       R#   \        P                   d    pT P                  TRRR4        Rp?R# Rp?ii ; i)1second errback failed to raise AlreadyCalledErrortestAlreadyCalledDebug_CEr  r  N)
r    r   r   r   r  r  r  r   r  r  r  s   &  r7   r  ,AlreadyCalledTests.testAlreadyCalledDebug_CEq  sz    #:	t~~t}}5Q	KKKN IIIJ '' 	MKK6	8LL	Mr  c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   rr  |  r  r9   c                	<   \        4       pVP                  V P                  V P                  4       V P	                  V4        V P                  V4       V P                  R 4       R#   \        P                   d    pT P                  TRRR4        Rp?R# Rp?ii ; i)r  testAlreadyCalledDebug_ECr  r  N)
r    r   r   r   r  r  r  r   r  r  r  s   &  r7   r  ,AlreadyCalledTests.testAlreadyCalledDebug_EC|  sz    #:	t~~t}}5A	LLLO IIJK '' 	MKK6)LL	Mr  c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   rr    r  r9   c                	<   \        4       pVP                  V P                  V P                  4       V P	                  V4        V P                  V4       V P                  R 4       R#   \        P                   d    pT P                  TRRR4        Rp?R# Rp?ii ; i)r  testAlreadyCalledDebug_EEr  r  N)
r    r   r   r   r  r  r  r   r  r  r  s   &  r7   r  ,AlreadyCalledTests.testAlreadyCalledDebug_EE  sz    #:	t~~t}}5A	KKKN IIIJ '' 	LKK6(KK	Lr  c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   rr    s     
L 
L 
Lr9   c                	v   \         P                  ! R 4       \        4       pVP                  V P                  V P
                  4       V P                  V4        V P                  V4       V P                  R4       R#   \         P                   d'   pT P                  TP                  4        Rp?R# Rp?ii ; i)Fr  N)r   r   r    r   r   r   r  r  r  r  rZ  r<   r  s   &  r7   testNoDebugging"AlreadyCalledTests.testNoDebugging  s    5!#:	t~~t}}5Q	LLLO IIJK '' 	%QVV$$	%s   A= =B8B33B8c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   rr    s     $ $T $r9   c                	j   \         P                  ! R 4       \        4       pVP                  R 4       \         P                  ! R4       VP	                  R4       \         P                  ! R 4       \        4       pVP	                  R4       \         P                  ! R4       VP                  R 4       R# )Fc                    R # rA   r5   r  s   &r7   r?  8AlreadyCalledTests.testSwitchDebugging.<locals>.<lambda>      dr9   TNc                    R # rA   r5   r  s   &r7   r?  r    r  r9   )r   r   r    addBothrX   r  s   & r7   testSwitchDebugging&AlreadyCalledTests.testSwitchDebugging  s|     	5!$J			"#4 	

45!J	

44 			"#r9   )ru  N)rL   rM   rN   rO   r   ry  r   r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rP   r5   r9   r7   rp  rp    st    !7++EDDE+-	L	K	L	K
L$ $r9   rp  c                      ] tR tRtR R ltR R ltR R ltR R	 ltR
 R ltR R lt	R R lt
R R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR  R! ltR" R# ltR$ R% ltR& R' ltR(tR)# )*DeferredCancellerTestsi  c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   #DeferredCancellerTests.__annotate__  s     $ $t $r9   c                	>    R V n         R V n        R V n        ^ V n        R # rA   )r   r   r   cancellerCallCountr   s   &r7   r   DeferredCancellerTests.setUp  s"    .215/3"#r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r    s     7 7$ 7r9   c                	>    V P                  V P                  R4       R# )r   Nr  )r   r  r   s   &r7   ry  DeferredCancellerTests.tearDown  s    d--v6r9   c                    V ^8  d   QhRRRR/# )r2   datar   r4   r5   )r6   s   "r7   r8   r    s      c c r9   c                	    Wn         V# rA   r   rl   r  s   &&r7   r    DeferredCancellerTests._callback  s    #r9   c                    V ^8  d   QhRRRR/# )r2   r  r   r4   rT   r5   )r6   s   "r7   r8   r    s     % %s %t %r9   c                	    Wn         R # rA   r   r  s   &&r7   r   !DeferredCancellerTests._callback2  s     $r9   c                    V ^8  d   QhRRRR/# )r2   r|   r/   r4   rT   r5   )r6   s   "r7   r8   r    s     $ $g $$ $r9   c                	    Wn         R # rA   r   )rl   r|   s   &&r7   r   DeferredCancellerTests._errback  s    #r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r    s     
0 
0$ 
0r9   c                D   \        4       pVP                  V P                  V P                  4       VP	                  4        V P
                  f   Q hV P                  V P
                  P                  \        P                  4       V P                  V P                  4       R# )za
A L{Deferred} without a canceller must errback with a
L{defer.CancelledError} and not callback.
N)r    r   r   r   rO  r   rg   r"  r   r   r   r   r  s   & r7   test_noCanceller'DeferredCancellerTests.test_noCanceller  sr    
 %J	t~~t}}5	
""...,,1153G3GH$../r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r    s     L L4 Lr9   c                d   \        4       pVP                  V P                  V P                  4       VP	                  4        VP                  R4       V P                  \        P                  VP
                  R4       V P                  \        P                  VP                  \        4       4       R# )z
A L{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)r    r   r   r   rO  rX   r  r   r  r   rm  r  s   & r7   !test_raisesAfterCancelAndCallback8DeferredCancellerTests.test_raisesAfterCancelAndCallback  st     %J	t~~t}}5	
 	


4 	%22AJJE%22AIIy{Kr9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r    s     L L$ Lr9   c                t   \        4       pVP                  V P                  V P                  4       VP	                  4        VP                  \        4       4       V P                  \        P                  VP                  R4       V P                  \        P                  VP
                  \        4       4       R# )z
A L{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)r    r   r   r   rO  r   rm  r  r   r  rX   r  s   & r7    test_raisesAfterCancelAndErrback7DeferredCancellerTests.test_raisesAfterCancelAndErrback  sv     %J	t~~t}}5	
 	
		)+ 	%22AJJE%22AIIy{Kr9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r    s     ; ;t ;r9   c                   \        4       pVP                  V P                  V P                  4       VP	                  4        V P
                  pVP                  R4       VP	                  4        V P                  W P
                  4       R# )zm
A L{Deferred} without a canceller, when cancelled and then
callbacked, ignores multiple cancels thereafter.
N)r    r   r   r   rO  r   rX   r{   rl   r  currentFailures   &  r7   5test_noCancellerMultipleCancelsAfterCancelAndCallbackLDeferredCancellerTests.test_noCancellerMultipleCancelsAfterCancelAndCallback  s\    
 %J	t~~t}}5	
,,	

4	
n&9&9:r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r   	  s     ; ;d ;r9   c                   \        4       pVP                  V P                  V P                  4       VP	                  4        V P
                  f   Q hV P                  V P
                  P                  \        P                  4       V P
                  pVP                  \        4       4       V P                  V P
                  P                  \        P                  4       VP	                  4        V P                  W P
                  4       R# )zl
A L{Deferred} without a canceller, when cancelled and then
errbacked, ignores multiple cancels thereafter.
N)r    r   r   r   rO  r   rg   r"  r   r   r   rJ   r{   r  s   &  r7   4test_noCancellerMultipleCancelsAfterCancelAndErrbackKDeferredCancellerTests.test_noCancellerMultipleCancelsAfterCancelAndErrback 	  s    
 %J	t~~t}}5	
""...,,1153G3GH,,			,.!,,1153G3GH	
n&9&9:r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  	  s     ; ; ;r9   c                |   \        4       pVP                  V P                  V P                  4       VP	                  4        V P
                  f   Q hV P                  V P
                  P                  \        P                  4       V P
                  pVP	                  4        V P                  W P
                  4       R# )z
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)r    r   r   r   rO  r   rg   r"  r   r   r{   r  s   &  r7   test_noCancellerMultipleCancel5DeferredCancellerTests.test_noCancellerMultipleCancel	  s     %J	t~~t}}5	
""...,,1153G3GH,,	
n&9&9:r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  !	  s     5 5d 5r9   c                  a  R V 3R llp\        VR7      pVP                  S P                  S P                  4       VP	                  4        S P
                  f   Q hS P                  S P
                  P                  \        P                  4       S P
                  pVP	                  4        S P                  VS P
                  4       S P                  S P                  ^4       R# )z
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.
c                    V ^8  d   QhRRRR/# r2   r  ry  r4   rT   r5   )r6   s   "r7   r8   IDeferredCancellerTests.test_cancellerMultipleCancel.<locals>.__annotate__*	       	) 	)& 	)4 	)r9   c                :   < S;P                   ^,          un         R# r  r  r  rl   s   &r7   rO  CDeferredCancellerTests.test_cancellerMultipleCancel.<locals>.cancel*	      ##q(#r9   r1  N)r    r   r   r   rO  r   rg   r"  r   r   r{   r  )rl   rO  r  r	  s   f   r7   test_cancellerMultipleCancel3DeferredCancellerTests.test_cancellerMultipleCancel!	  s    	) 	) %v6	t~~t}}5	
""...,,1153G3GH,,	
nd&9&9:00!4r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  7	  s     L Ld Lr9   c                  a  R V 3R llp\        VR7      pVP                  S P                  S P                  4       VP	                  4        S P                  S P                  ^4       S P                  f   Q hS P                  S P                  P                  \        P                  4       S P                  \        P                  VP                  R4       S P                  \        P                  VP                  \        4       4       R# )z
Verify that a L{Deferred} calls its specified canceller when
it is cancelled, and that further call/errbacks raise
L{defer.AlreadyCalledError}.
c                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   ADeferredCancellerTests.test_simpleCanceller.<locals>.__annotate__>	  r  r9   c                :   < S;P                   ^,          un         R# r  r  r  s   &r7   rO  ;DeferredCancellerTests.test_simpleCanceller.<locals>.cancel>	  r  r9   r1  N)r    r   r   r   rO  rg   r  r   r"  r   r   r  r  rX   r   rm  rl   rO  r  s   f  r7   test_simpleCanceller+DeferredCancellerTests.test_simpleCanceller7	  s    	) 	) %v6	t~~t}}5	
00!4""...,,1153G3GH 	%22AJJE%22AIIy{Kr9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  L	  s     
 
4 
r9   c                   a a R VV 3R llp\        VR7      oSP                  S P                  S P                  4       SP	                  4        R# )zA
Verify that a canceller is given the correct deferred argument.
c                    V ^8  d   QhRRRR/# )r2   r.  ry  r4   rT   r5   )r6   s   "r7   r8   >DeferredCancellerTests.test_cancellerArg.<locals>.__annotate__Q	  s     	! 	!' 	!D 	!r9   c                ,   < SP                  V S4       R # rA   )r{   )r.  r  rl   s   &r7   rO  8DeferredCancellerTests.test_cancellerArg.<locals>.cancelQ	  s    MM"a r9   r1  N)r    r   r   r   rO  r'  s   f @r7   test_cancellerArg(DeferredCancellerTests.test_cancellerArgL	  s8    
	! 	! %v6	t~~t}}5	
r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  X	  s     8 8$ 8r9   c                f  a  R V 3R llp\        VR7      pVP                  S P                  S P                  4       VP	                  R4       VP                  4        S P                  S P                  ^ 4       S P                  S P                  4       S P                  S P                  R4       R# )zW
Test that cancelling a deferred after it has been callbacked does
not cause an error.
c                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   EDeferredCancellerTests.test_cancelAfterCallback.<locals>.__annotate__^	       	& 	&& 	&4 	&r9   c                l   < S;P                   ^,          un         V P                  \        4       4       R# r  r  r   rJ   r  s   &r7   rO  ?DeferredCancellerTests.test_cancelAfterCallback.<locals>.cancel^	  "    ##q(#IIln%r9   r1  zbiff!N)r    r   r   r   rX   rO  rg   r  r   r   r   r'  s   f  r7   test_cancelAfterCallback/DeferredCancellerTests.test_cancelAfterCallbackX	  s    	& 	& $f5	t~~t}}5	

7	
00!4$--.--w7r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  j	  s     0 0 0r9   c                  a  R V 3R llp\        VR7      pVP                  S P                  S P                  4       VP	                  \        4       4       VP                  4        S P                  S P                  ^ 4       S P                  f   Q hS P                  S P                  P                  \
        4       S P                  S P                  4       R# )zn
Test that cancelling a L{Deferred} after it has been errbacked does
not result in a L{defer.CancelledError}.
c                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   DDeferredCancellerTests.test_cancelAfterErrback.<locals>.__annotate__p	  r6  r9   c                l   < S;P                   ^,          un         V P                  \        4       4       R# r  r8  r  s   &r7   rO  >DeferredCancellerTests.test_cancelAfterErrback.<locals>.cancelp	  r:  r9   r1  N)r    r   r   r   r   rJ   rO  rg   r  r   r"  r   r   r'  s   f  r7   test_cancelAfterErrback.DeferredCancellerTests.test_cancelAfterErrbackj	  s    	& 	& %v6	t~~t}}5			,.!	
00!4""...,,11<@$../r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  }	  s     A AD Ar9   c                J  a  R V 3R llp\        VR7      pVP                  S P                  S P                  4       VP	                  4        S P                  S P                  ^4       S P                  f   Q hS P                  S P                  P                  \        4       R# )z/
Test a canceller which errbacks its deferred.
c                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   GDeferredCancellerTests.test_cancellerThatErrbacks.<locals>.__annotate__	  r6  r9   c                l   < S;P                   ^,          un         V P                  \        4       4       R# r  r8  r  s   &r7   rO  ADeferredCancellerTests.test_cancellerThatErrbacks.<locals>.cancel	  r:  r9   r1  N)
r    r   r   r   rO  rg   r  r   r"  rJ   r'  s   f  r7   test_cancellerThatErrbacks1DeferredCancellerTests.test_cancellerThatErrbacks}	  s|    
	& 	& %v6	t~~t}}5	
00!4""...,,11<@r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  	  s     / /T /r9   c                D  a  R V 3R llp\        VR7      pVP                  S P                  S P                  4       VP	                  4        S P                  S P                  ^4       S P                  S P                  R4       S P                  S P                  4       R# )z,
Test a canceller which calls its deferred.
c                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   HDeferredCancellerTests.test_cancellerThatCallbacks.<locals>.__annotate__	  s     	! 	!& 	!4 	!r9   c                \   < S;P                   ^,          un         V P                  R4       R# )r   hello!N)r  rX   r  s   &r7   rO  BDeferredCancellerTests.test_cancellerThatCallbacks.<locals>.cancel	  s     ##q(#JJx r9   r1  rR  N)
r    r   r   r   rO  rg   r  r   r   r   r'  s   f  r7   test_cancellerThatCallbacks2DeferredCancellerTests.test_cancellerThatCallbacks	  sx    
	! 	! %v6	t~~t}}5	
00!4--x8$--.r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  	  s     I I4 Ir9   c                  a a R V 3R llpR V 3R llp\        VR7      o\        VR7      pVP                  R4       VP                  V3R l4       VP                  4        VP	                  S P
                  S P                  4       S P                  S P                  ^4       S P                  f   Q hS P                  S P                  P                  \        P                  4       R# )z
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.
c                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   FDeferredCancellerTests.test_cancelNestedDeferred.<locals>.__annotate__	  s     	) 	)+ 	) 	)r9   c                :   < S;P                   ^,          un         R# r  r  r  s   &r7   innerCancelEDeferredCancellerTests.test_cancelNestedDeferred.<locals>.innerCancel	  r  r9   c                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   rY  	  s     	# 	#& 	#4 	#r9   c                *   < SP                  R 4       R# FN)ri   r  s   &r7   rO  @DeferredCancellerTests.test_cancelNestedDeferred.<locals>.cancel	  s    OOE"r9   r1  Nc                   < S# rA   r5   )r  rS  s   &r7   r?  BDeferredCancellerTests.test_cancelNestedDeferred.<locals>.<lambda>	  s    1r9   )r    rX   r   rO  r   r   r   rg   r  r   r"  r   r   )rl   r[  rO  r  rS  s   f   @r7   test_cancelNestedDeferred0DeferredCancellerTests.test_cancelNestedDeferred	  s    	) 	)	# 	# %{;$v6	

4	n%	
	t~~t}}500!4 ""...,,1153G3GHr9   )r   r   r  r   N)rL   rM   rN   rO   r   ry  r   r   r   r  r   r  r
  r  r  r  r(  r0  r;  rC  rK  rT  rc  rP   r5   r9   r7   r  r    sl    $7%$
0L"L";;$;5,L*
8$0&A / I Ir9   r  c                      ] tR tRtRtR R ltR R ltR R ltR	 R
 ltR R lt	R R lt
R R ltR R ltR R ltR R ltR R ltRtR# )LogTestsi	  z#
Test logging of unhandled errors.
c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   LogTests.__annotate__	  s     ' 't 'r9   c                h    . V n         \        P                  ! V P                   P                  4       R# )z,
Add a custom observer to observer logging.
N)cr,   r   rf   r   s   &r7   r   LogTests.setUp	  s     (*&r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   rh  	  s     * *$ *r9   c                Z    \         P                  ! V P                  P                  4       R# )z
Remove the observer.
N)r,   removeObserverrj  rf   r   s   &r7   ry  LogTests.tearDown	  s     	466==)r9   c                   V ^8  d   QhRR/# )r2   r4   zList[Dict[str, Any]]r5   )r6   s   "r7   r8   rh  	  s     3 33 3r9   c                	d    V P                    Uu. uF  qR ,          '       g   K  VNK  	  up# u upi )isErrorrj  )rl   r>  s   & r7   _loggedErrorsLogTests._loggedErrors	  s&    6626ay\\6222s   --c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   rh  	  s     2 2 2r9   c                    V P                  4       pV P                  \        V4      ^4       V^,          R,          P                  \        4       V P                  \        4       R# )zF
Check the output of the log observer to see if the error is present.
r|  N)rt  rg   rh   r{  r  rz   )rl   c2s   & r7   r  LogTests._check	  sM     !R!$
1i/001r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   rh  	  s      t r9   c                    \        4       P                  R 4      P                  ^4       \        P                  ! 4        V P                  4        R# )z
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.
c                    ^^ ,          # r  r5   r  s   &r7   r?  (LogTests.test_errorLog.<locals>.<lambda>	      ar9   N)r    r   rX   gccollectr  r   s   &r7   test_errorLogLogTests.test_errorLog	  s2     	
/099!<


r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   rh  	  s       r9   c                j    R R lpV! 4        \         P                  ! 4        V P                  4        R# )z4
Same as L{test_errorLog}, but with an inner frame.
c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   =LogTests.test_errorLogWithInnerFrameRef.<locals>.__annotate__	  s     	 	t 	r9   c                 `    \        4       p V P                  R  4       V P                  ^4       R# )c                    ^^ ,          # r  r5   r  s   &r7   r?  `LogTests.test_errorLogWithInnerFrameRef.<locals>._subErrorLogWithInnerFrameRef.<locals>.<lambda>	      AFr9   N)r    r   rX   rN  s    r7   _subErrorLogWithInnerFrameRefNLogTests.test_errorLogWithInnerFrameRef.<locals>._subErrorLogWithInnerFrameRef	  s!    'zAMM*+JJqMr9   Nr  r  r  )rl   r  s   & r7   test_errorLogWithInnerFrameRef'LogTests.test_errorLogWithInnerFrameRef	  s!    
	
 	&'


r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   rh  	  s      $ r9   c                j    R R lpV! 4        \         P                  ! 4        V P                  4        R# )zA
Same as L{test_errorLogWithInnerFrameRef}, plus create a cycle.
c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   ?LogTests.test_errorLogWithInnerFrameCycle.<locals>.__annotate__	  s     		 		 		r9   c                 |    \        4       p V 3R  R llpV P                  V4       W n        V P                  ^4       R# )c               $    V ^8  d   QhRRRRRR/# )r2   r  r  r  Deferred[int]r4   r5   )r6   s   "r7   r8   hLogTests.test_errorLogWithInnerFrameCycle.<locals>._subErrorLogWithInnerFrameCycle.<locals>.__annotate__	  s!      s } S r9   c                    ^^ ,          # r  r5   )r  r  s   &&r7   unusedCyclegLogTests.test_errorLogWithInnerFrameCycle.<locals>._subErrorLogWithInnerFrameCycle.<locals>.unusedCycle	  s    Avr9   N)r    r   _drX   )r  r  s     r7   _subErrorLogWithInnerFrameCycleRLogTests.test_errorLogWithInnerFrameCycle.<locals>._subErrorLogWithInnerFrameCycle	  s/    'zA78  MM+&DJJqMr9   Nr  )rl   r  s   & r7    test_errorLogWithInnerFrameCycle)LogTests.test_errorLogWithInnerFrameCycle	  s!    
		 	()


r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   rh  
  s     
 
T 
r9   c                   \        4       P                  R 4      P                  ^4       \        P                  ! 4        V P                  4        V P                  ^\        V P                  4      4       \        P                  ! V P                  R,          4      pVf   Q hRpV P                  VP                  V4      RV: 24       R# )z
Verify that when a L{Deferred} with no references to it is fired,
the logged message does not contain a repr of the failure object.
c                    ^^ ,          # r  r5   r  s   &r7   r?  .LogTests.test_errorLogNoRepr.<locals>.<lambda>
  r~  r9   Nr    Expected message starting with: r  )r    r   rX   r  r  r  rg   rh   rj  r,   r   ri   r   )rl   msgr  s   &  r7   test_errorLogNoReprLogTests.test_errorLogNoRepr
  s    
 	
/099!<


CK(##DFF2J/0NN8$.xl;	
r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   rh  
  s     
 
 
r9   c                \   R R lpV! 4        \         P                  ! 4        V P                  4        V P                  ^\	        V P
                  4      4       \        P                  ! V P
                  R,          4      pVf   Q hRpV P                  VP                  V4      RV: 24       R# )z
Verify that when a L{Deferred} with no references to it is fired,
the logged message includes debug info if debugging on the deferred
is enabled.
c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   5LogTests.test_errorLogDebugInfo.<locals>.__annotate__
  s     	 	d 	r9   c                 n    \        4       p R V n        V P                  R 4       V P                  ^4       R# )Tc                    ^^ ,          # r  r5   r  s   &r7   r?  ?LogTests.test_errorLogDebugInfo.<locals>.doit.<locals>.<lambda>
  r  r9   N)r    debugr   rX   rN  s    r7   doit-LogTests.test_errorLogDebugInfo.<locals>.doit
  s(    'zAAGMM*+JJqMr9   Nz
(debug:  Ir  r  )
r  r  r  rg   rh   rj  r,   r   ri   r   )rl   r  r  r  s   &   r7   test_errorLogDebugInfoLogTests.test_errorLogDebugInfo
  s    	 	


CK(##DFF2J/NN8$.xl;	
r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   rh  /
  s     3 3$ 3r9   c                   \        4       pVP                  R 4       VP                  R4       . p. pVP                  VP                  VP                  4       V P                  V. 4       V P                  \        V4      ^4       V^ ,          P                  \        4       ???\        P                  ! 4        V P                  V P                  4       . 4       R# )z
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.
c                @    \         P                  ! \        R 4      4      # )zoop)r   r  rx   r  s   &r7   r?  3LogTests.test_chainedErrorCleanup.<locals>.<lambda>6
  s    %**\&-A"Br9   N)r    r   rX   r   rf   rg   rh   r{  rm  r  r  rt  )rl   r  r  r   s   &   r7   test_chainedErrorCleanup!LogTests.test_chainedErrorCleanup/
  s     %J	BC	

4 ! "	w~~v}}5"%Va(q	y! VQ 	

++-r2r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   rh  K
  s     3 3T 3r9   c                  a \         P                  ! \        R4      4      p\        4       oVf   Q hVP	                  V3R l4       R;op\
        P                  ! 4        V P                  V P                  4       . 4       R# )z
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.
zoh noNc                   < S# rA   r5   )r  goods   &r7   r?  6LogTests.test_errorClearedByChaining.<locals>.<lambda>V
  s    tr9   )	r   r  rm  r    re   r  r  rg   rt  )rl   badr  s   & @r7   test_errorClearedByChaining$LogTests.test_errorClearedByChainingK
  sd     ).

9W3E(F)1+, s


++-r2r9   rs  N)rL   rM   rN   rO   rq   r   ry  rt  r  r  r  r  r  r  r  r  rP   r5   r9   r7   rf  rf  	  sC    '*32(
&
4383 3r9   rf  c                  F    ] tR tRtR R ltR R ltR R ltR R	 ltR
tR# )DeferredListEmptyTestsi^
  c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   #DeferredListEmptyTests.__annotate___
  s      t r9   c                	    ^ V n         R# r   NcallbackRanr   s   &r7   r   DeferredListEmptyTests.setUp_
  s
    r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  b
  s     & &t &r9   c                R    \        . 4      pVP                  V P                  4       R# )zTesting empty DeferredList.N)r"   r   cb_empty)rl   r  s   & r7   testDeferredListEmpty,DeferredListEmptyTests.testDeferredListEmptyb
  s    9Eb9I
t}}%r9   c                    V ^8  d   QhRRRR/# )r2   reszList[Tuple[bool, object]]r4   rT   r5   )r6   s   "r7   r8   r  g
  s     " "5 "$ "r9   c                	8    ^V n         V P                  . V4       R# r  )r  rg   )rl   r  s   &&r7   r  DeferredListEmptyTests.cb_emptyg
  s    S!r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  k
  s     E E$ Er9   c                	>    V P                  V P                  R 4       R# )zCallback was never run.N)ri   r  r   s   &r7   ry  DeferredListEmptyTests.tearDownk
  s    ((*CDr9   r  N)	rL   rM   rN   rO   r   r  r  ry  rP   r5   r9   r7   r  r  ^
  s    &
"E Er9   r  c                      ] tR tRtR R ltR R ltR R ltR R	 ltR
 R ltR R lt	R R lt
R R ltR R ltR R ltR R ltR R ltRtR# )OtherPrimitivesTestsio
  c                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   !OtherPrimitivesTests.__annotate__p
  s      F t r9   c                	8    V ;P                   ^,          un         R# r  counterrl   r}   s   &&r7   _incrOtherPrimitivesTests._incrp
  s    r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  s
  s      t r9   c                	    ^ V n         R# r  r  r   s   &r7   r   OtherPrimitivesTests.setUps
  s	    r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  v
  s     @= @=$ @=r9   c                	t  a
 \        4       pVP                  4       P                  V P                  4       V P	                  VP
                  4       V P                  V P                  ^4       VP                  4       P                  V P                  4       V P	                  VP
                  4       V P                  V P                  ^4       VP                  4        V P	                  VP
                  4       V P                  V P                  ^4       VP                  4        V P                  VP
                  4       V P                  V P                  ^4       V P                  \        VP                  4       \        4       p\        4       p\        4       pRo
R	R V
3R lllpVP                  WRVR7      pV P	                  VP
                  4       V P                  S
V4       VP                  V4       VP                  4       P                  V P                  4       V P	                  VP
                  4       V P                  V P                  ^4       VP                  V4       V P                  S
V4       V P	                  VP
                  4       V P                  V P                  ^4       VP                  4       P!                  V4      pVP#                  4        V P%                  S
\&        4       V P                  \)        \&        S
4      P*                  \,        P.                  4       VP                  4        V P                  VP
                  4       R R lpR R lp	\1        VP                  V4      \        \2        ,          4       \1        VP                  V	4      \        \2        ,          4       R# )
r   Nc               $    V ^8  d   QhRRRRRR/# )r2   resultValuer=   returnValuer4   r5   )r6   s   "r7   r8   3OtherPrimitivesTests.testLock.<locals>.__annotate__
  s!     	 	 	V 	v 	r9   c                   < V oV# rA   r5   )r  r  r}   s   &&r7   helper-OtherPrimitivesTests.testLock.<locals>.helper
  s     Fr9   )r  r  c                   V ^8  d   QhRR/# )r2   r4   r  r5   )r6   s   "r7   r8   r  
  s     	$ 	$M 	$r9   c                 .    \         P                  ! ^4      # )r2   r   r  r5   r9   r7   r  1OtherPrimitivesTests.testLock.<locals>.returnsInt
  s    ==##r9   c                   V ^8  d   QhRR/# rA  r5   )r6   s   "r7   r8   r  
  s     	 	c 	r9   c                    "   ^# 5ir  r5   r5   r9   r7   returnsCoroInt5OtherPrimitivesTests.testLock.<locals>.returnsCoroInt
  rH  rI  rA   )r#   acquirer   r  ri   lockedrg   r  releaserZ  r  r,  runr=   r    rX   r  rO  r  r/   r   r"  r   r   r   r  )rl   lockfirstUniquesecondUniquecontrolDeferredr  resultDeferredr  r  r  r}   s   &         @r7   testLockOtherPrimitivesTests.testLockv
  s   ~""4::.$q)""4::.$q)$q)%q))TXX.hx,4J#'	 	
  " 
 	$-""6*""4::.$q)  ..$q)LLN""6*	
fg.gv.33U5I5IJ%	$	 	DHHZ((3-8DHH^,hsm<r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  
  s      d r9   c                   a  R V 3R llp\        4       pVP                  4       pVP                  V4       VP                  4        R# )zr
When canceling a L{Deferred} from a L{DeferredLock} that already
has the lock, the cancel should have no effect.
c                    V ^8  d   QhRRRR/# r2   r3   r/   r4   rT   r5   )r6   s   "r7   r8   GOtherPrimitivesTests.test_cancelLockAfterAcquired.<locals>.__annotate__
       	2 	2W 	2 	2r9   c                *   < SP                  R 4       R# zUnexpected errback call!Nr  r3   rl   s   &r7   failOnErrbackHOtherPrimitivesTests.test_cancelLockAfterAcquired.<locals>.failOnErrback
      II01r9   N)r#   r  re   rO  )rl   r  r  r  s   f   r7   test_cancelLockAfterAcquired1OtherPrimitivesTests.test_cancelLockAfterAcquired
  s6    	2 	2 ~LLN	]#	
r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  
  s     
= 
=t 
=r9   c                    \        4       pVP                  4        VP                  4       pVP                  4        V P                  V\        P
                  4       R# )z
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)r#   r  rO  ro   r   r   )rl   r  r  s   &  r7   test_cancelLockBeforeAcquired2OtherPrimitivesTests.test_cancelLockBeforeAcquired
  s>     ~LLN	
##Au';';<r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  
  s     12 12t 12r9   c                	  aaa ^p\        V4      p\        4       oRoR VV3R llp. p\        4       pVP                  W5R7      pVP	                  VP
                  4       VP	                  V P                  4       V P                  V. 4       V P                  SV4       SP                  R4       V P                  VP                  4       4       V P                  V P                  ^4       ^ V n        \        ^^V,           4       FH  pVP                  4       P	                  V P                  4       V P                  V P                  V4       KJ  	  . oR V3R llpR V3R llp	VP                  4       P                  W4      p
V
P                  4        V P                  SR	.4       VP                  4       P	                  V P                  4       V P                  V P                  V4       VP!                  4        V P                  V P                  V^,           4       \        ^^V,           4       F6  pVP!                  4        V P                  V P                  V^,           4       K8  	  R# )
   Nc                    V ^8  d   QhRRRR/# )r2   argr=   r4   r  r5   )r6   s   "r7   r8   8OtherPrimitivesTests.testSemaphore.<locals>.__annotate__
  s     	# 	# 	#> 	#r9   c                   < V oS# rA   r5   )r  r  	helperArgs   &r7   r  2OtherPrimitivesTests.testSemaphore.<locals>.helper
  s    I""r9   )r  c                    V ^8  d   QhRRRR/# r2   r  r=   r4   rT   r5   )r6   s   "r7   r8   r  
  s     	" 	"F 	"t 	"r9   c                *   < SP                  R 4       R# r_  r  r  r  s   &r7   r  0OtherPrimitivesTests.testSemaphore.<locals>.fail
  s    NN5!r9   c                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   r  
  s     	! 	!v 	!$ 	!r9   c                *   < SP                  R 4       R# rt  r  r   s   &r7   r  3OtherPrimitivesTests.testSemaphore.<locals>.succeed
  s    NN4 r9   T)r%   r    r=   r  r   rf   r  rg   rX   r   r  r  r  r  r   rO  r  )rl   Nsemr  r  uniqueObjectr  ir  r  r  r  r  r  s   &          @@@r7   testSemaphore"OtherPrimitivesTests.testSemaphore
  s   "*2* 		# 	#
 !#x:""7>>2""4::."%L1  &'++-(q)q!a%AKKM%%djj1T\\1- ! 	" 	"	! 	! KKM&&t5	
4&)!!$**-q)q1u-q!a%AKKMT\\1q51 !r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r    s     = =T =r9   c                r    V P                  \        \        ^ 4       V P                  \        \        R4       R# )zb
If the token count passed to L{DeferredSemaphore} is less than one
then L{ValueError} is raised.
Nr  )r  r  r%   r   s   &r7   test_semaphoreInvalidTokens0OtherPrimitivesTests.test_semaphoreInvalidTokens  s*    
 	*&7;*&7<r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r    s      4 r9   c                   a  R V 3R llp\        ^4      pVP                  4       pVP                  V4       VP                  4        R# )z|
When canceling a L{Deferred} from a L{DeferredSemaphore} that
already has the semaphore, the cancel should have no effect.
c                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   LOtherPrimitivesTests.test_cancelSemaphoreAfterAcquired.<locals>.__annotate__  r  r9   c                *   < SP                  R 4       R# r  r	  r
  s   &r7   r  MOtherPrimitivesTests.test_cancelSemaphoreAfterAcquired.<locals>.failOnErrback  r  r9   N)r%   r  re   rO  )rl   r  r&  r  s   f   r7   !test_cancelSemaphoreAfterAcquired6OtherPrimitivesTests.test_cancelSemaphoreAfterAcquired  s9    	2 	2  "KKM	]#	
r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r    s     
= 
=D 
=r9   c                    \        ^4      pVP                  4        VP                  4       pVP                  4        V P                  V\        P
                  4       R# )z
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.
N)r%   r  rO  ro   r   r   )rl   r&  r  s   &  r7   "test_cancelSemaphoreBeforeAcquired7OtherPrimitivesTests.test_cancelSemaphoreBeforeAcquired  sA      "KKM	
##Au';';<r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  '  s     #; #;4 #;r9   c                	P   ^^r!\        W4      p. p\        V4       F,  pVP                  4       P                  VP                  4       K.  	  V P                  \        P                  VP                  4       \        V4       F?  pVP                  V4       V P                  V\        \        V^,           4      4      4       KA  	  \        V4       F>  pVP                  W,           4       V P                  V\        \        V4      4      4       K@  	  V P                  \        P                  VP                  R4       . p\        V4       F^  pVP                  4       P                  VP                  4       V P                  V\        \        WV,           ^,           4      4      4       K`  	  \        4       p. p\        V4       F,  pVP                  4       P                  VP                  4       K.  	  \        V4       F  pVP                  V4       K  	  V P                  V\        \        V4      4      4       \        ^ R7      pV P                  \        P                  VP                  R4       \        ^ R7      pV P                  \        P                  VP                  4       R# )r2   N)size)backlog)r$   r  getr   rf   r  r   QueueUnderflowputrg   listQueueOverflow)rl   r%  Mqueuegottenr(  s   &     r7   	testQueueOtherPrimitivesTests.testQueue'  s   !1$1!$7qAIIK##FMM2 %..		:qAIIaLVT%A,%78  qAIIaeVT%(^4  	%--uyy$?qAIIK##FMM2VT%q519*=%>?  qAIIK##FMM2 qAIIaL eAh01%%--uyy$?a(%..		:r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  L  s      T r9   c                   a  R V 3R llp\        4       pVP                  4       pVP                  V4       VP                  R4       VP	                  4        R# )zs
When canceling a L{Deferred} from a L{DeferredQueue} that already has
a result, the cancel should have no effect.
c                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   NOtherPrimitivesTests.test_cancelQueueAfterSynchronousGet.<locals>.__annotate__R  r  r9   c                *   < SP                  R 4       R# r  r	  r
  s   &r7   r  OOtherPrimitivesTests.test_cancelQueueAfterSynchronousGet.<locals>.failOnErrbackR  r  r9   N)r$   r?  re   rA  rO  )rl   r  rE  r  s   f   r7   #test_cancelQueueAfterSynchronousGet8OtherPrimitivesTests.test_cancelQueueAfterSynchronousGetL  sA    	2 	2 &3_IIK	]#		$	
r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  [  s     ' '$ 'r9   c                D  a a \        4       oSP                  4       pVP                  4        S P                  V\        P
                  4       R VV 3R llpVP                  V4       . pVP                  VP                  4       S P                  \        V4      ^4       R# )z
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.
c                    V ^8  d   QhRRRR/# )r2   ignorer=   r4   r  r5   )r6   s   "r7   r8   COtherPrimitivesTests.test_cancelQueueAfterGet.<locals>.__annotate__g  s     	@ 	@v 	@. 	@r9   c                z   < SP                  R 4       SP                  4       P                  SP                  R 4      # rA   )rA  r?  r   r{   )rT  rE  rl   s   &r7   r   9OtherPrimitivesTests.test_cancelQueueAfterGet.<locals>.cbg  s-     IIdO99;**4==$??r9   N)
r$   r?  rO  ro   r   r   r   rf   rg   rh   )rl   r  r   donerE  s   f   @r7   test_cancelQueueAfterGet-OtherPrimitivesTests.test_cancelQueueAfterGet[  sy     &3_IIK	
##Au';';<	@ 	@ 	
b	dkk"TA&r9   r  N)rL   rM   rN   rO   r  r   r  r  r  r)  r-  r5  r9  rG  rO  rY  rP   r5   r9   r7   r  r  o
  sG    @=D
=12f=
=#;J' 'r9   r  c                      ] tR tRtRtR R ltR R ltR R ltR	 R
 ltR R lt	R R lt
R R ltR R ltR R ltRtR# )DeferredFilesystemLockTestsis  z0
Test the behavior of L{DeferredFilesystemLock}
c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   (DeferredFilesystemLockTests.__annotate__x  s     P Pt Pr9   c                	x    \        4       V n        \        V P                  4       V P                  R 7      V n        R# ))	schedulerN)r+   clockr!   mktempr  r   s   &r7   r   !DeferredFilesystemLockTests.setUpx  s#    W
*4;;=DJJO	r9   c                   V ^8  d   QhRR/# r2   r4   r  r5   )r6   s   "r7   r8   r^  |  s     5 5 5r9   c                :    V P                   P                  ^R7      # )z9
Test that the lock can be acquired when no lock is held
timeout)r  deferUntilLockedr   s   &r7   test_waitUntilLockedWithNoLock:DeferredFilesystemLockTests.test_waitUntilLockedWithNoLock|  s     yy))!)44r9   c                   V ^8  d   QhRR/# re  r5   )r6   s   "r7   r8   r^    s      ~ r9   c                   V P                  V P                  P                  4       4       V P                  P                  RR7      pV P                  V\        P
                  4       V P                  P                  ^.^
,          4       V# )z[
Test that the lock can not be acquired when the lock is held
for longer than the timeout.
g      @rg  )ri   r  ri  assertFailurer   TimeoutErrorra  pumpr  s   & r7   %test_waitUntilLockedWithTimeoutLockedADeferredFilesystemLockTests.test_waitUntilLockedWithTimeoutLocked  sc    
 			()II&&s&31e001

b!r9   c                   V ^8  d   QhRR/# re  r5   )r6   s   "r7   r8   r^    s       r9   c                l  a  R V 3R llpS P                  S P                  P                  4       4       S P                  P                  ^S P                  P                  4       S P                  P                  ^
R7      pVP                  V4       S P                  P                  ^.^
,          4       V# )zd
Test that a lock can be acquired while a lock is held
but the lock is unlocked before our timeout.
c                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   YDeferredFilesystemLockTests.test_waitUntilLockedWithTimeoutUnlocked.<locals>.__annotate__  s     	3 	3 	3T 	3r9   c                h   < V P                  \        P                  4       SP                  R 4       R# )zShould not have timed outN)r{  r   ro  r  r
  s   &r7   	onTimeoutVDeferredFilesystemLockTests.test_waitUntilLockedWithTimeoutUnlocked.<locals>.onTimeout  s"    FF5%%&II12r9   rg  )ri   r  ra  	callLaterunlockri  re   rp  )rl   rx  r  s   f  r7   'test_waitUntilLockedWithTimeoutUnlockedCDeferredFilesystemLockTests.test_waitUntilLockedWithTimeoutUnlocked  s    	3 	3 			()

Q		 0 01II&&r&2	Y

b!r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r^    s     3 3t 3r9   c                x    \        V P                  4       4      pV P                  VP                  \        4       R# )z5
Test that the default scheduler is set up properly.
N)r!   rb  rg   
_schedulerr   rl   r  s   & r7   test_defaultScheduler1DeferredFilesystemLockTests.test_defaultScheduler  s(     &dkkm4'2r9   c                   V ^8  d   QhRR/# re  r5   )r6   s   "r7   r8   r^    s      n r9   c                x   V P                   P                  4        V P                  P                  ^V P                   P                  4       V P                   P	                  4       pV P                   P	                  4       pV P                  V\        P                  4       V P                  P                  ^4       V# )zd
Test that an appropriate exception is raised when attempting
to use deferUntilLocked concurrently.
)	r  ra  rz  r{  ri  rn  r   AlreadyTryingToLockErroradvancer  s   &  r7   test_concurrentUsage0DeferredFilesystemLockTests.test_concurrentUsage  s    
 			

Q		 0 01YY'')YY'')2u==>

1	r9   c                   V ^8  d   QhRR/# re  r5   )r6   s   "r7   r8   r^    s      ^ r9   c                :  a  R V 3R llpS P                   P                  4        S P                  P                  ^S P                   P                  4       S P                   P	                  4       pVP                  V4       S P                  P                  ^4       V# )z?
Test that a DeferredFilesystemLock can be used multiple times
c                    V ^8  d   QhRRRR/# )r2   r  r=   r4   r  r5   )r6   s   "r7   r8   EDeferredFilesystemLockTests.test_multipleUsages.<locals>.__annotate__  s     	 	V 	 	r9   c                p   < SP                   P                  4        SP                   P                  4       pV# rA   )r  r{  ri  )r  r  rl   s   & r7   lockAquiredDDeferredFilesystemLockTests.test_multipleUsages.<locals>.lockAquired  s*    II		**,AHr9   )r  ra  rz  r{  ri  r   r  )rl   r  r  s   f  r7   test_multipleUsages/DeferredFilesystemLockTests.test_multipleUsages  sp    
	 	
 			

Q		 0 01II&&(	k"

1r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r^    s     = =T =r9   c                   V P                   P                  4        V P                   P                  4       pV P                   P                  pVf   Q hVP                  4        V P	                  VP                  4       4       V P                  V P                   P                  4       V P                  V\        P                  4       R# )z
When cancelling a L{Deferred} returned by
L{DeferredFilesystemLock.deferUntilLocked}, the
L{DeferredFilesystemLock._tryLockCall} is cancelled.
N)
r  ri  _tryLockCallrO  rZ  activer   rP  r   r   )rl   rR   tryLockCalls   &  r7   test_cancelDeferUntilLocked7DeferredFilesystemLockTests.test_cancelDeferUntilLocked  s     			99--/ii,,&&&++-.$))001Xu';';<r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r^    s     = = =r9   c                   V P                   P                  4        V P                   P                  ^R7      pV P                   P                  pVf   Q hVP                  4        V P	                  VP                  4       4       V P                  V P                   P                  4       V P                  V\        P                  4       R# )z
When cancel a L{Deferred} returned by
L{DeferredFilesystemLock.deferUntilLocked}, if the timeout is
set, the timeout call will be cancelled.
rg  N)
r  ri  _timeoutCallrO  rZ  r  r   rP  r   r   )rl   rR   timeoutCalls   &  r7   &test_cancelDeferUntilLockedWithTimeoutBDeferredFilesystemLockTests.test_cancelDeferUntilLockedWithTimeout  s     			99--a-8ii,,&&&++-.$))001Xu';';<r9   )ra  r  N)rL   rM   rN   rO   rq   r   rj  rq  r|  r  r  r  r  r  rP   r5   r9   r7   r\  r\  s  s:    P5(3"(== =r9   r\  c               $    V ^8  d   QhRRRRRR/# )r2   vr=   tfloatr4   r   r5   )r6   s   "r7   r8   r8     s!      V  # r9   c                    R# )z^
Private function to be used to pass as an alternate onTimeoutCancel value
to timeoutDeferred

OVERRIDDENr5   )r  r  s   &&r7   _overrideFuncr    s    
 r9   c                      ] tR tRtRtR R ltR R ltR R ltR	 R
 ltR R lt	R R lt
R R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R  ltR! R" ltR# R$ ltR% R& ltR'tR(# ))DeferredAddTimeoutTestsi  z/
Tests for the function L{Deferred.addTimeout}
c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   $DeferredAddTimeoutTests.__annotate__  s     	: 	:t 	:r9   c                    \        4       pVP                  ^\        4       4       VP                  R 4       VP	                  R4       V P                  RV P                  V4      4       R# )z]
L{Deferred.addTimeout} returns its own L{Deferred} so it
can be called in a callback chain.
c                    R # )rX  r5   r  s   &r7   r?  ?DeferredAddTimeoutTests.test_timeoutChainable.<locals>.<lambda>  s    r9   NrX  )r    
addTimeoutr+   r   rX   rg   rY  r  s   & r7   test_timeoutChainable-DeferredAddTimeoutTests.test_timeoutChainable  sO    
 %J	Q 	&'	

4!5!5a!89r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r    s     + + +r9   c                R  aa \        4       p\        4       pVP                  ^
V4       \        4       oRoR VV3R llpVP                  V4       VP	                  R4       V P                  RS4       V P                  SR4       VP                  ^4       V P                  S4       R# )z
The L{Deferred} callbacks with the result if it succeeds before
the timeout. No cancellation happens after the callback either,
which could also cancel inner deferreds.
Nc                    V ^8  d   QhRRRR/# r2   r  r   r4   r  r5   )r6   s   "r7   r8   MDeferredAddTimeoutTests.test_successResultBeforeTimeout.<locals>.__annotate__       	! 	! 	! 	!r9   c                   < V oS# rA   r5   r  dCallbackedinnerDeferreds   &r7   
onCallbackKDeferredAddTimeoutTests.test_successResultBeforeTimeout.<locals>.onCallback      !K  r9   r  )	r+   r    r  r   rX   assertIsNotrg   r  rq  rl   ra  r  r  r  r  s   &   @@r7   test_successResultBeforeTimeout7DeferredAddTimeoutTests.test_successResultBeforeTimeout  s     #:	R )1
%)	! 	!
 	
j!	

9 	{+i0 	bM*r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  )  s      +  +t  +r9   c                ^  aa \        4       p\        4       pVP                  ^
V\        R7       \        4       oRoR VV3R llpVP	                  V4       VP                  R4       V P                  RS4       V P                  SR4       VP                  ^4       V P                  S4       R# )z
The L{Deferred} callbacks with the result if it succeeds before
the timeout, even if a custom C{onTimeoutCancel} function is provided.
No cancellation happens after the callback either, which could also
cancel inner deferreds.
onTimeoutCancelNc                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   SDeferredAddTimeoutTests.test_successResultBeforeTimeoutCustom.<locals>.__annotate__9  r  r9   c                   < V oS# rA   r5   r  s   &r7   r  QDeferredAddTimeoutTests.test_successResultBeforeTimeoutCustom.<locals>.onCallback9  r  r9   r  )
r+   r    r  r  r   rX   r  rg   r  rq  r  s   &   @@r7   %test_successResultBeforeTimeoutCustom=DeferredAddTimeoutTests.test_successResultBeforeTimeoutCustom)  s     #:	R> )1
%)	! 	!
 	
j!	

9 	{+i0 	bM*r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  K  s     !+ !+4 !+r9   c                  aa \        4       p\        4       pVP                  ^
V4       \        4       oRo\        R4      pR VV3R llpVP	                  V4       VP                  V4       Sf   Q hV P                  S\        4       V P                  SP                  V4       VP                  ^4       V P                  S4       R# )z
The L{Deferred} errbacks with the failure if it fails before the
timeout. No cancellation happens after the errback either, which
could also cancel inner deferreds.
Nr  c                    V ^8  d   QhRRRR/# r2   r3   r/   r4   r  r5   )r6   s   "r7   r8   GDeferredAddTimeoutTests.test_failureBeforeTimeout.<locals>.__annotate__[       	! 	! 	!^ 	!r9   c                   < V oS# rA   r5   r3   
dErrbackedr  s   &r7   	onErrbackDDeferredAddTimeoutTests.test_failureBeforeTimeout.<locals>.onErrback[      J  r9   )r+   r    r  r  re   r   r  r/   r{   rk   r  rq  rl   ra  r  r|   r  r  r  s   &    @@r7   test_failureBeforeTimeout1DeferredAddTimeoutTests.test_failureBeforeTimeoutK  s     $J	R )1
(,
6"	! 	!
 	
Y			% %%%j'2j&&. 	bM*r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  n  s     "+ "+ "+r9   c                  aa \        4       p\        4       pVP                  ^
V\        R7       \        4       oRo\	        R4      pR VV3R llpVP                  V4       VP                  V4       Sf   Q hV P                  S\        4       V P                  SP                  V4       VP                  ^4       V P                  S4       R# )z
The L{Deferred} errbacks with the failure if it fails before the
timeout, even if using a custom C{onTimeoutCancel} function.
No cancellation happens after the errback either, which could also
cancel inner deferreds.
r  Nr  c                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   MDeferredAddTimeoutTests.test_failureBeforeTimeoutCustom.<locals>.__annotate__  r  r9   c                   < V oS# rA   r5   r  s   &r7   r  JDeferredAddTimeoutTests.test_failureBeforeTimeoutCustom.<locals>.onErrback  r  r9   )r+   r    r  r  r  re   r   r  r/   r{   rk   r  rq  r  s   &    @@r7   test_failureBeforeTimeoutCustom7DeferredAddTimeoutTests.test_failureBeforeTimeoutCustomn  s     $J	R> )1
(,
6"	! 	!
 	
Y			% %%%j'2j&&. 	bM*r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r    s     4 4t 4r9   c                    \        4       p\        4       pVP                  ^
V4       V P                  V4       VP	                  ^4       V P                  V\        P                  4       R# )zt
The L{Deferred} by default errbacks with a L{defer.TimeoutError}
if it times out before callbacking or errbacking.
N)r+   r    r  rq  r  rP  r   ro  rl   ra  r  s   &  r7   test_timedOut%DeferredAddTimeoutTests.test_timedOut  sP    
 $J	RAbQ 2 23r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r    s     @ @T @r9   c                    \        4       p\        4       pVP                  ^
V\        R7       V P	                  V4       VP                  ^4       V P                  RV P                  V4      4       R# )a  
If a custom C{onTimeoutCancel] function is provided, the
L{Deferred} returns the custom function's return value if the
L{Deferred} times out before callbacking or errbacking.
The custom C{onTimeoutCancel} function can return a result instead of
a failure.
r  r  Nr+   r    r  r  rq  r  rg   rY  r  s   &  r7   test_timedOutCustom+DeferredAddTimeoutTests.test_timedOutCustom  sY     $J	R>Abt';';A'>?r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r    s     F FD Fr9   c                    \        4       p\        R 4      pVP                  ^
V4       V P                  V4       VP	                  ^4       V P                  V P                  V4      R4       R# )z
If a cancellation function is provided when the L{Deferred} is
initialized, the L{Deferred} returns the cancellation value's
non-failure return value when the L{Deferred} times out.
c                $    V P                  R 4      # )I was cancelled!rW   rs  s   &r7   r?  LDeferredAddTimeoutTests.test_timedOutProvidedCancelSuccess.<locals>.<lambda>  s    ajj9K.Lr9   r  N)r+   r    r  rq  r  rg   rY  r  s   &  r7   "test_timedOutProvidedCancelSuccess:DeferredAddTimeoutTests.test_timedOutProvidedCancelSuccess  sZ     #$LM	RAb--a02DEr9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r    s     & &D &r9   c                  a \        4       p\        R4      o\        V3R l4      pVP                  ^
V4       V P	                  V4       VP                  ^4       V P                  V\        4      pV P                  VP                  S4       R# )z
If a cancellation function is provided when the L{Deferred} is
initialized, the L{Deferred} returns the cancellation value's
non-L{CanceledError} failure when the L{Deferred} times out.
what!c                &   < V P                  S4      # rA   )r   )rj  r|   s   &r7   r?  LDeferredAddTimeoutTests.test_timedOutProvidedCancelFailure.<locals>.<lambda>  s    qyy/?r9   N)	r+   r  r    r  rq  r  rP  r{   rk   )rl   ra  r  r3   r|   s   &   @r7   "test_timedOutProvidedCancelFailure:DeferredAddTimeoutTests.test_timedOutProvidedCancelFailure  sm     7#$%?@	RAb  J/aggu%r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r    s     !+ !+$ !+r9   c                  aa \        4       p\        4       pVP                  ^
V4       \        4       oRoR VV3R llpVP                  V4       VP	                  4        Sf   Q hV P                  S\        4       V P                  SP                  \        P                  4       VP                  ^4       V P                  S4       R# )a  
If the L{Deferred} is manually cancelled before the timeout, it
is not re-cancelled (no L{AlreadyCancelled} error, and also no
canceling of inner deferreds), and the default C{onTimeoutCancel}
function is not called, preserving the original L{CancelledError}.
Nc                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   FDeferredAddTimeoutTests.test_cancelBeforeTimeout.<locals>.__annotate__  r  r9   c                   < V oS# rA   r5   r3   	dCanceledr  s   &r7   r  CDeferredAddTimeoutTests.test_cancelBeforeTimeout.<locals>.onErrback      I  r9   )r+   r    r  re   rO  r  r/   r{   r"  r   r   r  rq  rl   ra  r  r  r  r  s   &   @@r7   test_cancelBeforeTimeout0DeferredAddTimeoutTests.test_cancelBeforeTimeout  s     $J	R )1
		! 	!
 	
Y	
 $$$i1inne&:&:; 	bM*r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r    s     !+ !+ !+r9   c                  aa \        4       p\        4       pVP                  ^
V\        R7       \        4       oRoR VV3R llpVP	                  V4       VP                  4        Sf   Q hV P                  S\        4       V P                  SP                  \        P                  4       VP                  ^4       V P                  S4       R# )a  
If the L{Deferred} is manually cancelled before the timeout, it
is not re-cancelled (no L{AlreadyCancelled} error, and also no
canceling of inner deferreds), and the custom C{onTimeoutCancel}
function is not called, preserving the original L{CancelledError}.
r  Nc                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   LDeferredAddTimeoutTests.test_cancelBeforeTimeoutCustom.<locals>.__annotate__  r  r9   c                   < V oS# rA   r5   r   s   &r7   r  IDeferredAddTimeoutTests.test_cancelBeforeTimeoutCustom.<locals>.onErrback  r  r9   )r+   r    r  r  re   rO  r  r/   r{   r"  r   r   r  rq  r  s   &   @@r7   test_cancelBeforeTimeoutCustom6DeferredAddTimeoutTests.test_cancelBeforeTimeoutCustom  s     $J	R> )1
		! 	!
 	
Y	
 $$$i1inne&:&:; 	bM*r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r    s     @ @d @r9   c                    \        4       p\        R 4      pVP                  ^
V\        R7       V P	                  V4       VP                  ^4       V P                  RV P                  V4      4       R# )z]
A custom translation function can handle a L{Deferred} with a
custom cancellation function.
c                6    V P                  \        R 4      4      # )r  )r   r  rs  s   &r7   r?  VDeferredAddTimeoutTests.test_providedCancelCalledBeforeTimeoutCustom.<locals>.<lambda>  s    qyyG9L/Mr9   r  r  Nr  r  s   &  r7   ,test_providedCancelCalledBeforeTimeoutCustomDDeferredAddTimeoutTests.test_providedCancelCalledBeforeTimeoutCustom  s]    
 $%MN	R>Abt';';A'>?r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  %  s     4 4 4r9   c                z  a \        4       p\        4       pRoR V3R llpVP                  V4       VP                  ^
V4       VP	                  ^4       Sf   Q hV P                  S\        4       V P                  SP                  \        P                  4       V P                  V\        P                  4       R# )z
An errback added before a timeout is added errbacks with a
L{defer.CancelledError} when the timeout fires.  If the
errback returns the L{defer.CancelledError}, it is translated
to a L{defer.TimeoutError} by the timeout implementation.
Nc                    V ^8  d   QhRRRR/# r2   r3   r/   r4   r5   )r6   s   "r7   r8   LDeferredAddTimeoutTests.test_errbackAddedBeforeTimeout.<locals>.__annotate__1       	 	w 	7 	r9   c                   < V oV # rA   r5   r3   r  s   &r7   r   GDeferredAddTimeoutTests.test_errbackAddedBeforeTimeout.<locals>.errback1      JHr9   )r+   r    re   r  r  r  r/   rk   r   r   rP  ro  rl   ra  r  r   r  s   &   @r7   test_errbackAddedBeforeTimeout6DeferredAddTimeoutTests.test_errbackAddedBeforeTimeout%  s     $J
	 	
 	
W	Rb%%%j'2j..0D0DEQ 2 23r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  A  s        d  r9   c                \  a \        4       p\        4       pRoR V3R llpVP                  V4       VP                  ^
V4       VP	                  ^4       Sf   Q hV P                  S\        4       V P                  SP                  \        P                  4       V P                  V4       R# )z
An errback added before a timeout is added errbacks with a
L{defer.CancelledError} when the timeout fires.  If the
errback suppresses the L{defer.CancelledError}, the deferred
successfully completes.
Nc                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   bDeferredAddTimeoutTests.test_errbackAddedBeforeTimeoutSuppressesCancellation.<locals>.__annotate__M  s     	) 	)w 	)4 	)r9   c                J   < V oV P                  \        P                  4       R # rA   )r{  r   r   r  s   &r7   r   ]DeferredAddTimeoutTests.test_errbackAddedBeforeTimeoutSuppressesCancellation.<locals>.errbackM  s    JFF5''(r9   )r+   r    re   r  r  r  r/   rk   r   r   rY  r  s   &   @r7   4test_errbackAddedBeforeTimeoutSuppressesCancellationLDeferredAddTimeoutTests.test_errbackAddedBeforeTimeoutSuppressesCancellationA  s     $J
	) 	)
 	
W	Rb%%%j'2j..0D0DEQr9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  ]  s     @ @d @r9   c                  a \        4       p\        4       pRoR V3R llpVP                  V4       VP                  ^
V\        4       VP                  ^4       Sf   Q hV P                  S\        4       V P                  SP                  \        P                  4       V P                  RV P                  V4      4       R# )z
An errback added before a timeout is added with a custom
timeout function errbacks with a L{defer.CancelledError} when
the timeout fires.  The timeout function runs if the errback
returns the L{defer.CancelledError}.
Nc                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   RDeferredAddTimeoutTests.test_errbackAddedBeforeTimeoutCustom.<locals>.__annotate__i  r  r9   c                   < V oV # rA   r5   r  s   &r7   r   MDeferredAddTimeoutTests.test_errbackAddedBeforeTimeoutCustom.<locals>.errbacki  r  r9   r  r+   r    re   r  r  r  r  r/   rk   r   r   rg   rY  r  s   &   @r7   $test_errbackAddedBeforeTimeoutCustom<DeferredAddTimeoutTests.test_errbackAddedBeforeTimeoutCustom]  s     $J
	 	
 	
W	R.b%%%j'2j..0D0DEt';';A'>?r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  y  s     @ @D @r9   c                  a \        4       p\        4       pRoR V3R llpVP                  V4       VP                  ^
V\        4       VP                  ^4       Sf   Q hV P                  S\        4       V P                  SP                  \        P                  4       V P                  RV P                  V4      4       R# )z
An errback added before a timeout is added with a custom
timeout function errbacks with a L{defer.CancelledError} when
the timeout fires.  The timeout function runs if the errback
suppresses the L{defer.CancelledError}.
Nc                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   hDeferredAddTimeoutTests.test_errbackAddedBeforeTimeoutSuppressesCancellationCustom.<locals>.__annotate__  s     	 	w 	4 	r9   c                   < V oR # rA   r5   r  s   &r7   r   cDeferredAddTimeoutTests.test_errbackAddedBeforeTimeoutSuppressesCancellationCustom.<locals>.errback  s    Jr9   r  r0  r  s   &   @r7   :test_errbackAddedBeforeTimeoutSuppressesCancellationCustomRDeferredAddTimeoutTests.test_errbackAddedBeforeTimeoutSuppressesCancellationCustomy  s     $J
	 	 	
W	R.b%%%j'2j..0D0DEt';';A'>?r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r    s     8 84 8r9   c                $  aa \        4       pRo\        V3R l4      pRoR V3R llpVP                  V4       VP                  ^
V4       VP	                  ^4       V P                  SS4       V P                  SV P                  V4      4       R# )z
Given a deferred with a cancellation function that resumes the
callback chain, a callback that is added to the deferred
before a timeout is added to runs when the timeout fires.  The
deferred completes successfully, without a
L{defer.TimeoutError}.
r  c                &   < V P                  S4      # rA   rW   r  r  s   &r7   r?  SDeferredAddTimeoutTests.test_callbackAddedToCancelerBeforeTimeout.<locals>.<lambda>      ajj.Ar9   Nc                    V ^8  d   QhRRRR/# r2   rk   r   r4   r5   )r6   s   "r7   r8   WDeferredAddTimeoutTests.test_callbackAddedToCancelerBeforeTimeout.<locals>.__annotate__       	 	C 	C 	r9   c                   < V oV # rA   r5   rk   r  s   &r7   rX   SDeferredAddTimeoutTests.test_callbackAddedToCancelerBeforeTimeout.<locals>.callback      KLr9   )r+   r    r   r  r  rg   r{   rY  rl   ra  r  rX   r  r  s   &   @@r7   )test_callbackAddedToCancelerBeforeTimeoutADeferredAddTimeoutTests.test_callbackAddedToCancelerBeforeTimeout  s|     #$AB	 	
 	
h	Rbg.gt33A67r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r    s     @ @ @r9   c                0  aa \        4       pRo\        V3R l4      pRoR V3R llpVP                  V4       VP                  ^
V\        R7       VP                  ^4       V P                  SS4       V P                  RV P                  V4      4       R# )a,  
Given a deferred with a cancellation function that resumes the
callback chain, a callback that is added to the deferred
before a timeout is added to runs when the timeout fires.  The
deferred completes successfully, without a
L{defer.TimeoutError}.  The timeout's custom timeout function
also runs.
r  c                &   < V P                  S4      # rA   rW   r>  s   &r7   r?  YDeferredAddTimeoutTests.test_callbackAddedToCancelerBeforeTimeoutCustom.<locals>.<lambda>  r@  r9   Nc                    V ^8  d   QhRRRR/# rB  r5   )r6   s   "r7   r8   ]DeferredAddTimeoutTests.test_callbackAddedToCancelerBeforeTimeoutCustom.<locals>.__annotate__  rD  r9   c                   < V oV # rA   r5   rF  s   &r7   rX   YDeferredAddTimeoutTests.test_callbackAddedToCancelerBeforeTimeoutCustom.<locals>.callback  rH  r9   r  r  )r+   r    r   r  r  r  rg   rY  rI  s   &   @@r7   /test_callbackAddedToCancelerBeforeTimeoutCustomGDeferredAddTimeoutTests.test_callbackAddedToCancelerBeforeTimeoutCustom  s     #$AB	 	
 	
h	R>bg.t';';A'>?r9   r5   N)rL   rM   rN   rO   rq   r  r  r  r  r  r  r  r  r  r  r  r  r   r(  r1  r9  rJ  rT  rP   r5   r9   r7   r  r    ss    	:+B +D!+F"+H4@"F&"!+F!+F@48 8@8@688@ @r9   r  c                  J    ] tR tRtRtR R ltR R ltR R ltR	 R
 ltRt	R# )EnsureDeferredTestsi  z
Tests for L{ensureDeferred}.
c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8    EnsureDeferredTests.__annotate__  s      T r9   c                R    \        4       p\        V4      pV P                  W4       R# )z;
L{ensureDeferred} will pass through a Deferred unchanged.
N)r    r)   r{   r  s   &  r7   test_passesThroughDeferreds/EnsureDeferredTests.test_passesThroughDeferreds  s!     &ZBbr9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   rY    s     ( ( (r9   c                    V P                  \        P                  4      ;_uu_ 4        \        R4       RRR4       R#   + '       g   i     R# ; i)zZ
Passing L{ensureDeferred} a non-coroutine and a non-Deferred will
raise a L{ValueError}.
	somethingN)r  r   r  r)   r   s   &r7   'test_willNotAllowNonDeferredOrCoroutine;EnsureDeferredTests.test_willNotAllowNonDeferredOrCoroutine  s2    
 u7788;' 9888s	   >A	c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   rY         % %d %r9   c                   R R lpV! 4       pV P                  V\        P                  4       \        V4      p\	        V\
        \        ,          4       V P                  V\
        4       V P                  V4      pV P                  VR4       R# )z=
L{ensureDeferred} will turn a coroutine into a L{Deferred}.
c                   V ^8  d   QhRR/# )r2   r4   r   r5   )r6   s   "r7   r8   FEnsureDeferredTests.test_ensureDeferredCoroutine.<locals>.__annotate__  s     	 	3 	r9   c                 R   "   \         P                  ! R 4      p V G Rj  xL
 pV#  L5irj  Nr  r  r  s     r7   r  =EnsureDeferredTests.test_ensureDeferredCoroutine.<locals>.run  s$     e$A'CJ    '%'rj  N)	r  typesCoroutineTyper)   r   r    r   rY  rg   rl   r  r  r  r  s   &    r7   test_ensureDeferredCoroutine0EnsureDeferredTests.test_ensureDeferredCoroutine  r    
	 Ea!4!45 1Ax}%a* ""1%e$r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   rY    rc  r9   c                   R R lpV! 4       pV P                  V\        P                  4       \        V4      p\	        V\
        \        ,          4       V P                  V\
        4       V P                  V4      pV P                  VR4       R# )zH
L{ensureDeferred} will turn a yield-from coroutine into a L{Deferred}.
c                   V ^8  d   QhRR/# )r2   r4   z#Generator[Deferred[str], None, str]r5   )r6   s   "r7   r8   FEnsureDeferredTests.test_ensureDeferredGenerator.<locals>.__annotate__  s     	 	8 	r9   c               3  R   "   \         P                  ! R 4      p T  Rj  xL
 pV#  L5irh  r  ri  s     r7   r  =EnsureDeferredTests.test_ensureDeferredGenerator.<locals>.run  s$     e$A,CJ rk  rj  N)	r  rl  GeneratorTyper)   r   r    r   rY  rg   rn  s   &    r7   test_ensureDeferredGenerator0EnsureDeferredTests.test_ensureDeferredGenerator  rq  r9   r5   N)
rL   rM   rN   rO   rq   r[  r`  ro  ry  rP   r5   r9   r7   rW  rW    s     (%.% %r9   rW  c                  &    ] tR tRtRtR R ltRtR# )TimeoutErrorTestsi  z)
L{twisted.internet.defer} timeout code.
c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   TimeoutErrorTests.__annotate__  s     
 
 
r9   c                |   \        4       p\        P                  ! V4       V P                  V\        P                  4       V P                  V P                  .4      pV P                  \        V4      ^4       V P                  V^ ,          R,          \        4       V P                  V^ ,          R,          R4       R# )z2
L{twisted.internet.defer.timeout} is deprecated.
r   r   z~twisted.internet.defer.timeout was deprecated in Twisted 17.1.0; please use twisted.internet.defer.Deferred.addTimeout insteadN)r    r   rh  rn  ro  r   test_deprecatedTimeoutrg   rh   r{   r   )rl   rR   warningsShowns   &  r7   r  (TimeoutErrorTests.test_deprecatedTimeout  s     &.Zh8U%7%78**D,G,G+HI]+Q/mA&z24FG!Y'M	
r9   r5   N)rL   rM   rN   rO   rq   r  rP   r5   r9   r7   r|  r|    s    
 
r9   r|  c                    V ^8  d   QhRRRR/# )r2   loopr   r4   rT   r5   )r6   s   "r7   r8   r8   (  s     	 	, 	 	r9   c                \    V P                  V P                  4       V P                  4        R# )z
Tickle an asyncio event loop to call all of the things scheduled with
call_soon, inasmuch as this can be done via the public API.

@param loop: The asyncio event loop to flush the previously-called
    C{call_soon} entries from.
N)	call_soonstoprun_foreverr  s   &r7   callAllSoonCallsr  (  s      	NN499r9   c                  v    ] tR tRtR R ltR R ltR R ltR R	 ltR
 R ltR R lt	R R lt
R R ltRtR# )DeferredFutureAdapterTestsi4  c                   V ^8  d   QhRR/# )r2   r4   r   r5   )r6   s   "r7   r8   'DeferredFutureAdapterTests.__annotate__5  s      * r9   c                P    \        4       pV P                  VP                  4       V# )zE
Create a new event loop that will be closed at the end of the test.
)_new_event_loopr   closer  s   & r7   newLoop"DeferredFutureAdapterTests.newLoop5  s!     !"%r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  =  s     / /t /r9   c                V   \        4       pV P                  4       pVP                  V4      pV P                  VP	                  4       R4       VP                  ^4       \        V4       V P                  V P                  V4      R4       V P                  VP                  4       ^4       R# )z_
L{Deferred.asFuture} returns a L{asyncio.Future} which fires when
the given L{Deferred} does.
FN)	r    r  asFuturerg   rX  rX   r  rY  r}   )rl   r  r  aFutures   &   r7   test_asFuture(DeferredFutureAdapterTests.test_asFuture=  s    
 $:||~**T"/	

2--a0$7)2.r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  K  s     : :4 :r9   c                P  a RoR V3R llp\        V4      pV P                  4       pVP                  V4      pVP                  4        \	        V4       V P                  S4       V P                  V P                  V4      R4       V P                  \        VP                  4       R# )zo
L{Deferred.asFuture} returns a L{asyncio.Future} which, when
cancelled, will cancel the original L{Deferred}.
Fc                    V ^8  d   QhRRRR/# r2   dprimery  r4   rT   r5   )r6   s   "r7   r8   JDeferredFutureAdapterTests.test_asFutureCancelFuture.<locals>.__annotate__S  s     	 	- 	$ 	r9   c                   < R oR# rt  r5   )r  r  s   &r7   cancelerFDeferredFutureAdapterTests.test_asFutureCancelFuture.<locals>.cancelerS  s    Fr9   N)r    r  r  rO  r  ri   rg   rY  r  r   r}   )rl   r  r  r  r  r  s   &    @r7   test_asFutureCancelFuture4DeferredFutureAdapterTests.test_asFutureCancelFutureK  s     	 	 %X.||~**T"--a0$7.'..9r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  `  s     : :D :r9   c                "   R R lp\        V4      pV P                  4       pVP                  V4      pVP                  4        \	        V4       V P                  V P                  V4      R4       V P                  \        VP                  4       R# )z
While Futures don't support succeeding in response to cancellation,
Deferreds do; if a Deferred is coerced into a success by a Future
cancellation, that should just be ignored.
c                    V ^8  d   QhRRRR/# r  r5   )r6   s   "r7   r8   KDeferredFutureAdapterTests.test_asFutureSuccessCancel.<locals>.__annotate__g  s     	 	- 	$ 	r9   c                (    V P                  ^	4       R# )	   NrW   )r  s   &r7   r  GDeferredFutureAdapterTests.test_asFutureSuccessCancel.<locals>.cancelerg  s    OOAr9   N)
r    r  r  rO  r  rg   rY  r  r   r}   )rl   r  r  r  r  s   &    r7   test_asFutureSuccessCancel5DeferredFutureAdapterTests.test_asFutureSuccessCancel`  sm    	 %X.||~**T"--a0$7.'..9r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  r  s     < <d <r9   c                   \        4       p\        \        4       4      pV P                  4       pVP	                  V4      p\        V4       VP                  V4       \        V4       V P                  \        VP                  4       R# )zh
L{Deferred.asFuture} makes a L{asyncio.Future} fire with an
exception when the given L{Deferred} does.
N)	r    r/   r  r  r  r  r   r  r}   )rl   r  
theFailurer  futures   &    r7   test_asFutureFailure/DeferredFutureAdapterTests.test_asFutureFailurer  sc    
 %J.01
||~D!			*+V]];r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r    s     5 5 5r9   c                   V P                  4       p\        VR7      p\        P                  ! V4      pV P	                  V4       VP                  ^4       \        V4       V P                  V P                  V4      ^4       R# )z`
L{Deferred.fromFuture} returns a L{Deferred} that fires
when the given L{asyncio.Future} does.
r  N)	r  r   r    
fromFuturerq  
set_resultr  rg   rY  )rl   r  r  r  s   &   r7   test_fromFuture*DeferredFutureAdapterTests.test_fromFuture  sh    
 ||~%40(A1--a0!4r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r    s     5 5 5r9   c                (   V P                  4       p\        VR7      p\        P                  ! V4      pVP	                  4        \        V4       V P                  \        VP                  4       V P                  V4      P                  \        4       R# )z
L{Deferred.fromFuture} makes a L{Deferred} fire with
an L{asyncio.CancelledError} when the given
L{asyncio.Future} is cancelled.
r  N)r  r   r    r  rO  r  r  r   r}   rP  r{  rl   r  	cancelledr  s   &   r7   test_fromFutureFutureCancelled9DeferredFutureAdapterTests.test_fromFutureFutureCancelled  sl     ||~"(d"3		*.)*:*:;Q$$^4r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r    s     5 5$ 5r9   c                h   V P                  4       p\        VR7      p\        P                  ! V4      pVP	                  4        \        V4       V P                  VP                  4       R4       V P                  \        VP                  4       V P                  V4      P                  \        4       R# )zv
L{Deferred.fromFuture} makes a L{Deferred} which, when
cancelled, cancels the L{asyncio.Future} it was created from.
r  TN)r  r   r    r  rO  r  rg   r  r  r   r}   rP  r{  r  s   &   r7    test_fromFutureDeferredCancelled;DeferredFutureAdapterTests.test_fromFutureDeferredCancelled  s    
 ||~"(d"3		*	
,,.5.)*:*:;Q$$^4r9   r5   N)rL   rM   rN   rO   r  r  r  r  r  r  r  r  rP   r5   r9   r7   r  r  4  s/    /:*:$<555 5r9   r  c                  |    ] tR tRtR R ltR R lt]R R l4       t]R R	 l4       t]R
 R l4       t	R R lt
RtR# )CoroutineContextVarsTestsi  c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   &CoroutineContextVarsTests.__annotate__  s     O8 O8$ O8r9   c                  a aaaaa \        4       o\        P                  ! R4      oSP                  ^4       \	        4       oSP                  V3R l4       \	        4       oSP                  V3R l4       SP                  R 4       \        P                  R VV3R ll4       o\        S\        . \        R,          3,          4       \        P                  R VVVV VV3R	 ll4       p\        V\        . \        \        R
,          ,          3,          4       SP                  ^4       V! 4       pSP                  ^4       SP                  ^4       SP                  ^4       S P                  S P                  V4      R
4       R# )z
When an inlineCallbacks function is called, the context is taken from
when it was first called. When it resumes, the same context is applied.
testvarc                &   < SP                  ^4      # r  setr  vars   &r7   r?  DCoroutineContextVarsTests.test_withInlineCallbacks.<locals>.<lambda>      swwqzr9   c                &   < SP                  ^4      #    r  r  s   &r7   r?  r        
r9   c                    ^^ ,          # r  r5   r  s   &r7   r?  r        Ar9   c                   V ^8  d   QhRR/# r2   r4   z#Generator[Deferred[Any], Any, None]r5   )r6   s   "r7   r8   HCoroutineContextVarsTests.test_withInlineCallbacks.<locals>.__annotate__  s     	 	"E 	r9   c               3     <"   \        4       p SP                  ^V P                  R4       V x  SP                  ^4       R# 5ir   TNr    rz  rX   r  r  ra  r  s    r7   yieldingDeferredLCoroutineContextVarsTests.test_withInlineCallbacks.<locals>.yieldingDeferred  s1     'zAOOAqzz40GGGAJs   ?ANc                   V ^8  d   QhRR/# )r2   r4   z,Generator[Deferred[Any], Any, Literal[True]]r5   )r6   s   "r7   r8   r    s     "	 "	J "	r9   c               3  P  <"   SP                  SP                  4       ^4       \        P                  ! ^4      x  SP                  SP                  4       ^4       S P	                  ^SP
                  R4       Sx  SP                  SP                  4       ^4       S P	                  ^SP
                  R4        Sx  \        R4      h  \         d$    SP                  SP                  4       ^4        Mi ; iS! 4       x  SP                  SP                  4       ^4       R# 5i)r2   T???? should have failedrg   r?  r   r  rz  rX   rm  )ra  mutatingDeferredmutatingDeferredThatFailsrl   r  r  s   r7   testFunctionHCoroutineContextVarsTests.test_withInlineCallbacks.<locals>.testFunction  s      SWWY* --"" SWWY* OOA/88$?"" SWWY* OOA8AA4H;//   9::  /  A./ #$$SWWY*s*   B7D&;C
 ?D&
+C85D&7C88.D&T)r+   contextvars
ContextVarr  r    r   r   inlineCallbacksr   r   r   r  rg   rY  )rl   r  r  ra  r  r  r  r  s   f  @@@@@r7   test_withInlineCallbacks2CoroutineContextVarsTests.test_withInlineCallbacks  s3   
 +6+A+A)+L
 ,4:$$%9:3;:!!--.BC!--o>				 	 
	 	$hr8D>/A&BC 
		"	 "	 
"	H 	L(2x/F+F"GH
N 	a 	a 	a--a0$7r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r    s        t  r9   c                   a aa \        4       o\        P                  ! R4      o\        P                  R VV V3R ll4       pSP                  ^4       V! 4       pSP                  ^4       S P                  V4       R# )z|
When an inlineCallbacks function resumes, we should be able to reset() a
contextvar that was set when it was first called.
r  c                   V ^8  d   QhRR/# r  r5   )r6   s   "r7   r8   MCoroutineContextVarsTests.test_resetWithInlineCallbacks.<locals>.__annotate__  s     	+ 	+"E 	+r9   c               3  *  <"   SP                  ^4      p \        4       pSP                  ^VP                  R4       Vx  SP	                  SP                  4       ^4       SP                  V 4       SP	                  SP                  4       ^4       R# 5i)r  TN)r  r    rz  rX   rg   r?  reset)tokenr  ra  rl   r  s     r7   r  QCoroutineContextVarsTests.test_resetWithInlineCallbacks.<locals>.yieldingDeferred  so      GGAJE  (zAOOAqzz40GSWWY*IIeSWWY*s   BBN)r+   r  r  r   r  r  r  rY  )rl   r  r  ra  r  s   f  @@r7   test_resetWithInlineCallbacks7CoroutineContextVarsTests.test_resetWithInlineCallbacks  sj    
 +6+A+A)+L				+ 	+ 
	+ 	
 	aQr9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r    s     & &$ &r9   c                  a"   \        4       oRpS;_uu_4       GRj  xL
  V P                  SP                  4       SP                  4       pVP	                  V3R l4       V P                  SP                  4       V P                  VP                  4       RRR4      GRj  xL
  V P                  VP                  4       VG Rj  xL
  V P                  SP                  4       R#  L LH  + GRj  xL 
 '       g   i     L_; i LA5i)zA
L{DeferredLock} can be used as an asynchronous context manager.
Nc                $   < SP                  4       # rA   r  )r  r  s   &r7   r?  >CoroutineContextVarsTests.test_asyncWithLock.<locals>.<lambda>&  s    DLLNr9   )r#   ri   r  r  r   rZ  r  )rl   r  r  s   & @r7   test_asyncWithLock,CoroutineContextVarsTests.test_asyncWithLock  s     
 ~44OODKK(AMM23OODKK(QXX& 4 	!% 444 	sW   DC+DA7C/D$C-%$D	D
"D-D/D	5C86
D	D		Dc                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  .  s     ( (t (r9   c           
       a"   \        ^4      oS;_uu_4       GRj  xL
  V P                  SP                  ^4       S;_uu_4       GRj  xL
  V P                  SP                  ^4       SP                  4       pSP                  4       pV P                  SP                  ^ 4       V P	                  VP
                  4       V P                  VP
                  4       RRR4      GRj  xL
  V P                  SP                  ^ 4       V P	                  XP
                  4       XP                  V3R l4       VP                  V3R l4       VG Rj  xL
  VG Rj  xL
  V P                  SP                  ^4       RRR4      GRj  xL
  V P                  SP                  ^4       R#  EL ELe L  + GRj  xL 
 '       g   i     L; i L| Lt LJ  + GRj  xL 
 '       g   i     La; i5i)zF
L{DeferredSemaphore} can be used as an asynchronous context
manager.
Nc                $   < SP                  4       # rA   r  r  r&  s   &r7   r?  CCoroutineContextVarsTests.test_asyncWithSemaphore.<locals>.<lambda>@      S[[]r9   c                $   < SP                  4       # rA   r  r  s   &r7   r?  r  A  r  r9   )r%   rg   tokensr  ri   r  rZ  r   )rl   r.  rC  r&  s   &  @r7   test_asyncWithSemaphore1CoroutineContextVarsTests.test_asyncWithSemaphore-  s<      "33SZZ+ss  Q/[[][[]  Q/		*  + s SZZ+OOBII&NN23NN23HHHHSZZ+ 3  	Q'! sss  333s   G4F.G4+GF1GBF6	G*F4+A*GG	GG  G G4G#G41G4G6G<F?=
GG
	GGG4G1	G!
G1	*G1	,G4c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  H  s     
& 
&4 
&r9   c           
     ~  "   \        4       pV P                  \        R4      ;_uu_ 4        T;_uu_4       GRj  xL
  V P                  VP                  4       \        R4      h L*  + GRj  xL 
 '       g   i     M; i RRR4       M  + '       g   i     M; iT P                  TP                  4       R# 5i)z_
C{DeferredLock} correctly propagates exceptions when
used as an asynchronous context manager.
zsome specific exceptionN)r#   assertRaisesRegexrm  ri   r  rZ  r  s   & r7   test_asyncWithLockException5CoroutineContextVarsTests.test_asyncWithLockExceptionG  sw      ~##I/HIItt, 9:: tttt JIII 	%sO   )B=BA%B'A'	%B'B -A0.
B 9B ;B	B=B	%B=c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r  T  s     I8 I8 I8r9   c                .  a aaaaa \        4       o\        P                  ! R4      oSP                  ^4       \	        4       oSP                  V3R l4       \	        4       oSP                  V3R l4       SP                  R 4       R VV3R lloR VVVVV V3R llpSP                  ^4       \        V! 4       4      pSP                  ^4       SP                  ^4       SP                  ^4       S P                  S P                  V4      R	4       R
# )z
When a coroutine is called, the context is taken from when it was first
called. When it resumes, the same context is applied.
r  c                &   < SP                  ^4      # r  r  r  s   &r7   r?  JCoroutineContextVarsTests.test_contextvarsWithAsyncAwait.<locals>.<lambda>`  r  r9   c                &   < SP                  ^4      # r  r  r  s   &r7   r?  r  c  r  r9   c                    ^^ ,          # r  r5   r  s   &r7   r?  r  d  r  r9   c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   NCoroutineContextVarsTests.test_contextvarsWithAsyncAwait.<locals>.__annotate__f  s     	 	 	r9   c                    <"   \        4       p SP                  ^V P                  R4       V G Rj  xL
  SP                  ^4       R#  L5ir  r  r  s    r7   asyncFuncAwaitingDeferred[CoroutineContextVarsTests.test_contextvarsWithAsyncAwait.<locals>.asyncFuncAwaitingDeferredf  s8      (
AOOAqzz40GGGGAJ s   -A
AA
c                   V ^8  d   QhRR/# )r2   r4   r  r5   )r6   s   "r7   r8   r  m  s     !	 !	D !	r9   c                   <"   SP                  SP                  4       ^4       \        P                  ! ^4      G Rj  xL
  SP                  SP                  4       ^4       SP	                  ^ SP
                  R4       SG Rj  xL
  SP                  SP                  4       ^4       SP	                  ^SP
                  R4        SG Rj  xL
  \        R4      h L LY L  \         d$    SP                  SP                  4       ^4        Mi ; iS ! 4       G Rj  xL 
  SP                  SP                  4       ^4       R# 5i)r2   NTr  r  )r  ra  r  r  rl   r  s   r7   r  NCoroutineContextVarsTests.test_contextvarsWithAsyncAwait.<locals>.testFunctionm  s    SWWY* --""" SWWY* OOA/88$?""" SWWY* OOA8AA4H;///   9::) # # 0 /  A./ ,---SWWY*se   :ECAECAEC" C C" EE C" "+DEDED 'ETN)
r+   r  r  r  r    r   r)   r  rg   rY  )rl   r  r  r  ra  r  r  r  s   f  @@@@@r7   test_contextvarsWithAsyncAwait8CoroutineContextVarsTests.test_contextvarsWithAsyncAwaitT  s    
 +6+A+A)+L
 ,4:$$%9:4<J!!--.BC!--o>	 	!	 !	H 	
<>* 	a 	a 	a--a0$7r9   r5   N)rL   rM   rN   rO   r  r  rH   r  r  r  r  rP   r5   r9   r7   r  r    sW    O8b @ & &  ( (2 
& 
&I8 I8r9   r  c                  Z    ] tR tRtR R lt]P                  ! ]R4      R R l4       tRt	R# )	InlineCallbackTestsi  c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8    InlineCallbackTests.__annotate__  r  r9   c                    R ^RV P                   R\        .pV F2  pV P                  \        P                  \        P
                  V4       K4  	  R# )r  c                    V # rA   r5   r  s   &r7   r?  IInlineCallbackTests.test_fromCoroutineRequiresCoroutine.<locals>.<lambda>  r  r9   TNr  r  s   &  r7   r  7InlineCallbackTests.test_fromCoroutineRequiresCoroutine  r  r9   r  c                   V ^8  d   QhRR/# ru   r5   )r6   s   "r7   r8   r!    s     * *4 *r9   c                R   \        4       p\        P                  ! V4      pR R lp\        P                  ! V! V4      4      pV P                  WP                  V4      4       \        P                  ! V4      p??V P                  V! 4       4       V P                  V! 4       4       R# )z
Tests that there is no circular dependency when using
L{Deferred.fromCoroutine}, so that the machinery gets cleaned up
immediately rather than waiting for a GC.
c                    V ^8  d   QhRRRR/# )r2   r  r   r4   r5   )r6   s   "r7   r8   KInlineCallbackTests.test_coroutineNoCircularReference.<locals>.__annotate__  s     	 	# 	# 	r9   c                   "   V # 5irA   r5   )r  s   &r7   r  CInlineCallbackTests.test_coroutineNoCircularReference.<locals>.func  s
     HrI  N)r  r  r  r    rB   rg   rY  r   )rl   obj
objWeakRefr  funcDfuncDWeakRefs   &     r7   !test_coroutineNoCircularReference5InlineCallbackTests.test_coroutineNoCircularReference  s     [[%
	 &&tCy12259:{{5)  	*,',.)r9   r5   N)
rL   rM   rN   rO   r  r  r   r-   r0  rP   r5   r9   r7   r  r    s(    W. ]]59:* ;*r9   r  )brq   
__future__r   r  rF   r  rk  r  rl  r0   r  r   r  asyncior   r   r   r   r  typingr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   hamcrestr   r   r   
hypothesisr   hypothesis.strategiesr   r   twisted.internetr   r   twisted.internet.deferr   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   twisted.internet.taskr+   twisted.pythonr,   twisted.python.compatr-   twisted.python.failurer/   twisted.trialrH   rm  rJ   rZ   r[   r^   rd   rs   SynchronousTestCaser   r  r3  r5  rX  rp  r  rf  r  r  r\  r  r  rW  r|  r  r  r  r  r5   r9   r7   <module>r@     s!   #   	 	          & 2 1  *  +    (  ' * "	9 	) m954 4,*M!! *MZU9H002G U9p4 &~7,, ~7B;$h22 ;$|L$55 L$^GIX99 GITc3x++ c3LEX99 E"A'8779N A'Hz=("3"3 z=zS@h:: S@lA%(++ A%H
))+@ 
,	s5!2!2 s5ls8 1 1 s8l3*(66 3*r9   