+
    Dfjj                        R t ^ RIt^ RIt^ RIt^ RIHt ^ RIHtH	t	H
t
HtHt ^ RIHtHt ^ RIHtHtHtHtHtHtHt ^ RIHt ^ RIHtHt R tR	 tR$R
 R lltR$R R llt  ! R R]!4      t" ! R R]4      t# ! R R]4      t$ ! R R]4      t% ! R R]4      t& ! R R]4      t' ! R R]!4      t( ! R R]!4      t) ! R R]!4      t* ! R  R!]4      t+ ! R" R#]4      t,R# )%z0
Tests for L{twisted.internet.inlineCallbacks}.
N)Enum)Any	GeneratorListSetUnion)reactortask)CancelledErrorDeferredFailurefailinlineCallbacksreturnValuesucceed)_PYPY)SynchronousTestCaseTestCasec                 ^    \        4       p\        P                  ! ^ VP                  V 4       V#     )r   r   	callLatercallback)valueds   & E/usr/lib/python3/dist-packages/twisted/internet/test/test_inlinecb.pygetValueViaDeferredr      s$    
AaU+H    c                 4   "   \        V 4      G R j  xL
 #  L5iNr   )r   s   &r   getValueViaCoror!   #   s     $U++++s   c                J    V ^8  d   QhR\         \        R3,          R\        /#    msgNreturn)r   strr   )formats   "r   __annotate__r)   '   s#      E#t),  r   c                R     \        V 4      h  \         d    \        4       p T# i ; i)z.
Make a L{Failure} of a divide-by-zero error.
)ZeroDivisionErrorBaseExceptionr   )r%   fs   & r   getDivisionFailurer.   '   s-    $$ IHs    &&c                B    V ^8  d   QhR\         \        R3,          RR/# r#   )r   r'   )r(   s   "r   r)   r)   2   s#     ! !eCI&6 !$ !r   c                J   "   \        R4      G Rj  xL
  \        V 4      h L5i)z6
Make a coroutine that throws a divide-by-zero error.
r   N)r   r+   )r%   s   &r   getDivisionFailureCoror1   2   s%      g
&&&
C
   '   #!#c                       ] tR t^:tRtRtR# )TerminalExceptionzO
Just a specific exception type for use in inlineCallbacks tests in this
file.
 N__name__
__module____qualname____firstlineno____doc____static_attributes__r5   r   r   r4   r4   :   s    
 	r   r4   c                      a  ] tR t^Ct o RtR tR tR tR tR t	R t
R tR	 tR
 tR tR tR tR tR tR tR t]P,                  ! ]R4      V 3R lR l4       tRtV tR# )
BasicTestsaV  
This test suite tests basic use cases of L{inlineCallbacks}. For more
complex tests see e.g. StackedInlineCallbacksTests.

Note that it is important to directly call addCallbacks and other
functions exposed as an API, because both L{inlineCallbacks} and
L{Deferred} may be optimized in ways that are only exercised in particular
situations.
c                d   a  \         V 3R l4       pV! 4       P                  S P                  R4      # )z
Test that a normal inlineCallbacks works.  Tests yielding a
deferred which callbacks, as well as a deferred errbacks. Also
ensures returning a final value works.
c               3      <"   \        R 4      x p SP                  V R 4        \        R4      x  R#   \         d'   pSP                  \	        T4      R4        Rp?R# Rp?ii ; i5i)hiOMGNWOOSH)r   assertEqualr.   r+   r'   xeselfs     r   
_genBasics)BasicTests.testBasics.<locals>._genBasicsU   sc     )$//AQ%0(//  % 0  Q//0s*    A'3 A'A$AA'A$$A'rC   r   addCallbackrD   rH   rI   s   f r   
testBasicsBasicTests.testBasicsN   s4     
		 
		 |''(8(8'BBr   c                d   a  \         V 3R l4       pV! 4       P                  S P                  R4      # )zC
C{inlineCallbacks} can yield a coroutine and catch its exception.
c               3      <"   \        R 4      x p SP                  V R 4        \        R4      x  R#   \         d2   pSP                  \	        T4      R4       \        R4        Rp?R# Rp?ii ; i5i)rA   rB   rC   N)r!   rD   r1   r+   r'   r   rE   s     r   rI   .BasicTests.testBasicsAsync.<locals>._genBasicsh   sa     %d++AQ%%,U33$ %  Q/G$$%s*    A23 A2A/&A*$A2*A//A2rC   rK   rM   s   f r   testBasicsAsyncBasicTests.testBasicsAsyncc   s4    
 
		% 
		% |''(8(8'BBr   c                P    \         R 4       pV P                  V! 4       \        4      # )z
Ensure that a generator that produces an exception signals
a Failure condition on result deferred by converting the exception to
a L{Failure}.
c               3   :   "   \        R 4      x  ^^ ,           R# 5i)rA   Nr    r5   r   r   _genProduceException>BasicTests.testProducesException.<locals>._genProduceException}   s     %d++EE   )r   assertFailurer+   )rH   rW   s   & r   testProducesException BasicTests.testProducesExceptionv   s0     
	 
	 !!"6"8:KLLr   c                \    \         R 4       pV! 4       P                  V P                  R4      # )z9Test that a generator which never yields results in None.c               3      "   R# 5i)FNr5   r5   r   r   _genNothing+BasicTests.testNothing.<locals>._genNothing   s     s   NrK   )rH   r_   s   & r   testNothingBasicTests.testNothing   s3     
	 
	 }(()9)94@@r   c                \    \         R 4       pV! 4       P                  V P                  R4      # )z
Create a Deferred Generator which yields a Deferred which fails and
handles the exception which results.  Assert that the Deferred
Generator does not errback its Deferred.
c               3   `   "    \        \        R 4      4      x  R#   \         d     R# i ; i5i)Handled Terminal FailureN)r   r4   r5   r   r   _genHandledTerminalFailureIBasicTests.testHandledTerminalFailure.<locals>._genHandledTerminalFailure   s-     ,-GHII$ s   . .+.+.NrK   )rH   rf   s   & r   testHandledTerminalFailure%BasicTests.testHandledTerminalFailure   s4     
	 
	 *+778H8H$OOr   c                    \         R 4       p\        4       pV! V4      pVP                  \        R4      4       VP	                  V P
                  R4      # )zf
Just like testHandledTerminalFailure, only with a Deferred which fires
asynchronously with an error.
c              3   <   "    V x  R #   \          d     R # i ; i5ir   r4   r   s   &r   _genHandledTerminalAsyncFailureSBasicTests.testHandledTerminalAsyncFailure.<locals>._genHandledTerminalAsyncFailure   s      $ s   
 re   N)r   r   errbackr4   rL   rD   )rH   rn   r   deferredGeneratorResultDeferreds   &   r   testHandledTerminalAsyncFailure*BasicTests.testHandledTerminalAsyncFailure   sV     
	 
	 J*I!*L'			#$>?@.::4;K;KTRRr   c                   aa \        4       oV3R lo\        V3R l4       p\        4       oV! 4       pSP                  \        R4      4       VP	                  V P
                  R4      # )z
Just like testHandledCoroAsyncFailure, only with a Deferred which fires
asynchronously with an error and is wrapped in coroutine.
c                  $   <"   S G R j  xL
 #  L5ir   r5   rm   s   r   coro4BasicTests.testHandledCoroAsyncFailure.<locals>.coro   s     7N7s   c               3   H   <"    S ! 4       x  R #   \          d     R # i ; i5ir   rl   )rv   s   r   function8BasicTests.testHandledCoroAsyncFailure.<locals>.function   s#     f$ s   "	 """re   N)r   r   rp   r4   rL   rD   )rH   ry   inlineResultDeferredrv   r   s   &  @@r   testHandledCoroAsyncFailure&BasicTests.testHandledCoroAsyncFailure   sb     J	 
	 
	 J'z			#$>?@#//0@0@$GGr   c                \    \         R 4       pV! 4       P                  V P                  ^ 4      # )zR
Make sure we don't blow the stack when yielding immediately
available deferreds.
c               3   L   "   \        R 4       F  p \        ^4      x  K  	  ^ # 5ii  )ranger   rF   s    r   _genStackUsage1BasicTests.testStackUsage.<locals>._genStackUsage   s"     4[aj  ! s   "$rK   )rH   r   s   & r   testStackUsageBasicTests.testStackUsage   s4     
	 
	 ++D,<,<a@@r   c                \    \         R 4       pV! 4       P                  V P                  ^ 4      # )zO
Make sure we don't blow the stack when yielding immediately
available values.
c               3   :   "   \        R 4       F  p ^x  K	  	  ^ # 5ir   )r   r   s    r   _genStackUsage23BasicTests.testStackUsage2.<locals>._genStackUsage2   s     4[ ! rY   rK   )rH   r   s   & r   testStackUsage2BasicTests.testStackUsage2   s4     
	 
	  ,,T-=-=qAAr   c                `    R p\        V4      pV! 4       P                  V P                  ^4      # )z
Ensure that yielding a non-deferred passes it back as the
result of the yield expression.

@return: A L{twisted.internet.Deferred}
@rtype: L{twisted.internet.Deferred}
c               3      "   ^x  ^# 5i   r5   r5   r   r   _test.BasicTests.testYieldNonDeferred.<locals>._test   s     G   	rK   )rH   r   s   & r   testYieldNonDeferredBasicTests.testYieldNonDeferred   s.    	  &w""4#3#3Q77r   c                `    R p\        V4      pV! 4       P                  V P                  R4      # )z9Ensure a standard python return results in a None result.c               3      "   ^x  R# 5ir   Nr5   r5   r   r   	_noReturn/BasicTests.testReturnNoValue.<locals>._noReturn   s     Gr   NrK   )rH   r   s   & r   testReturnNoValueBasicTests.testReturnNoValue   s.    	 $I.	{&&t'7'7>>r   c                >   \         R 4       pV! 4       pV P                  4       pV P                  ^\        V4      4       V P	                  \
        V^ ,          R,          4       V P                  RV^ ,          R,          4       VP                  V P                  ^4      # )z?C{returnValue} is now deprecated but continues to be available.c               3   ,   "   ^x  \        ^4       R# 5ir   r   r5   r   r   _return5BasicTests.testReturnValueDeprecated.<locals>._return  s     GNs   category<twisted.internet.defer.returnValue was deprecated in Twistedmessage)r   flushWarningsrD   lenassertIsDeprecationWarningassertInrL   )rH   r   r   warningss   &   r   testReturnValueDeprecated$BasicTests.testReturnValueDeprecated  s     
	 
	 I%%'CM*((1+j*ABJQK	"	

 }}T--q11r   c           	         R p\        V4      pV P                  R\        V P                  \        V4      4      4       R# )z
Ensure that C{TypeError} with a message about L{inlineCallbacks} is
raised when a non-generator returns something other than a generator.
c                      ^# r   r5   r5   r   r   _noYield4BasicTests.test_nonGeneratorReturn.<locals>._noYield  s    r   r   Nr   r   r'   assertRaises	TypeErrorrH   r   s   & r   test_nonGeneratorReturn"BasicTests.test_nonGeneratorReturn  s4    	 #8,'T->->y(-S)TUr   c           	         R p\        V4      pV P                  R\        V P                  \        V4      4      4       R# )zw
Ensure that C{TypeError} with a message about L{inlineCallbacks} is
raised when a non-generator calls L{returnValue}.
c                      \        ^4       R# r   r   r5   r   r   r   9BasicTests.test_nonGeneratorReturnValue.<locals>._noYield(  s	    Nr   r   Nr   r   s   & r   test_nonGeneratorReturnValue'BasicTests.test_nonGeneratorReturnValue"  s4    	 #8,'T->->y(-S)TUr   c                  aa \         P                  ! 4       o\        V3R l4       o\        V3R l4       pV! 4       pSP                  ^ 4       V P	                  V4      pV P                  4       pV P                  ^\        V4      4       V P                  \        V^ ,          R,          4       V P                  RV^ ,          R,          4       V P                  RV4       V P                  RV4       V P                  RV4       R	# )
z
When one inlineCallbacks calls another, the internal L{_DefGen_Return}
flow control exception raised by calling L{defer.returnValue} doesn't
leak into tracebacks captured in the caller.
c               3  X   <"   \         P                  ! S ^ 4      x  \        R4       R# 5i)z/
This is the inner function using returnValue.
z"actual-value-not-used-for-the-testN)r	   
deferLaterr   clocks   r   _returnsEBasicTests.test_internalDefGenReturnValueDoesntLeak.<locals>._returns7  s"     
 //%++<=s   '*c               3      <"    S ! 4       x  \        R 4      h  \          d    \        P                  ! 4       u # i ; i5i)zboom returnValuer4   	traceback
format_excr   s   r   _raisesDBasicTests.test_internalDefGenReturnValueDoesntLeak.<locals>._raises?  s<     .j '(:;;$ . ++--.   ?  <?<?r   r   r   _DefGen_ReturnBDuring handling of the above exception, another exception occurredz1test_inlinecb.TerminalException: boom returnValueN)r	   Clockr   advancesuccessResultOfr   rD   r   r   r   r   assertNotIn)rH   r   r   tbr   r   r   s   &    @@r   (test_internalDefGenReturnValueDoesntLeak3BasicTests.test_internalDefGenReturnValueDoesntLeak/  s     

		> 
	> 
	. 
	. Ia!!!$%%'CM*((1+j*ABJQK	"	
 	)2.PRT	
 	I2Nr   c                .  aa \         P                  ! 4       o\        V3R l4       o\        V3R l4       pV! 4       pSP                  ^ 4       V P	                  V4      pV P                  RV4       V P                  RV4       V P                  RV4       R# )aa  
When one inlineCallbacks calls another, the internal L{StopIteration}
flow control exception generated when the inner generator returns
doesn't leak into tracebacks captured in the caller.

This is similar to C{test_internalDefGenReturnValueDoesntLeak} but the
inner function uses the "normal" return statemement rather than the
C{returnValue} helper.
c               3   B   <"   \         P                  ! S ^ 4      x  ^# 5ir   )r	   r   r   s   r   r   ABasicTests.test_internalStopIterationDoesntLeak.<locals>._returnsh  s     //%++s   c               3      <"    S ! 4       x  \        R 4      h  \          d    \        P                  ! 4       u # i ; i5i)zboom normal returnr   r   s   r   r   @BasicTests.test_internalStopIterationDoesntLeak.<locals>._raisesm  s<     .j '(<==$ . ++--.r   StopIterationr   z3test_inlinecb.TerminalException: boom normal returnN)r	   r   r   r   r   r   r   )rH   r   r   r   r   r   s   &   @@r   $test_internalStopIterationDoesntLeak/BasicTests.test_internalStopIterationDoesntLeak\  s     

		 
	 
	. 
	. Ia!!!$ 	"-PRT	
 	KRPr   zGC works differently on PyPy.c                   < V ^8  d   QhRR/# r$   r&   Nr5   )r(   __classdict__s   "r   r)   BasicTests.__annotate__  s     !* !* !*r   c                <   \        4       p\        P                  ! V4      p\        R R l4       pV! V4      pV P	                  WP                  V4      4       \        P                  ! V4      p??V P                  V! 4       4       V P                  V! 4       4       R# )aU  
When using L{defer.inlineCallbacks}, after the function exits, it will
not keep references to the function itself or the arguments.

This ensures that the machinery gets deallocated immediately rather than
waiting for a GC, on CPython.

The GC on PyPy works differently (del doesn't immediately deallocate the
object), so we skip the test.
c                0    V ^8  d   QhR\         R\         /# )r$   ar&   )r   )r(   s   "r   r)   HBasicTests.test_inlineCallbacksNoCircularReference.<locals>.__annotate__  s     	 	C 	C 	r   c              3      "   V x  V # 5ir   r5   r   s   &r   func@BasicTests.test_inlineCallbacksNoCircularReference.<locals>.func  s     GHr   N)setweakrefrefr   rD   r   assertIsNone)rH   obj
objWeakRefr   funcDfuncDWeakRefs   &     r   'test_inlineCallbacksNoCircularReference2BasicTests.test_inlineCallbacksNoCircularReference  s     [[%
		 
	
 S	2259:{{5)  	*,',.)r   r5   N)r7   r8   r9   r:   r;   rN   rS   r[   ra   rh   rr   r|   r   r   r   r   r   r   r   r   r   pyunitskipIfr   r   r<   __classdictcell__r   s   @r   r>   r>   C   s     C*C&MAP S$H.AB8"	?2(VV+OZ$QL ]]59:!* ;!*r   r>   c                   *   a  ] tR tRt o RtR tRtV tR# )StopIterationReturnTestsi  z
On Python 3.4 and newer generator functions may use the C{return} statement
with a value, which is attached to the L{StopIteration} exception that is
raised.

L{inlineCallbacks} will use this value when it fires the C{callback}.
c                    R\         /p\        RV4       \        4       pVR,          ! V4      pVP                  R4       V P	                  V P                  V4      ^4       R# )z
If the C{return} statement has a value it is propagated back to the
L{Deferred} that the C{inlineCallbacks} function returned.
r   z>
@inlineCallbacks
def f(d):
    yield d
    return 14
        r-   N)r   execr   r   rD   r   )rH   environd1d2s   &   r   test_returnWithValue-StopIterationReturnTests.test_returnWithValue  s^    
 %o6 	
 ZS\"
D--b126r   r5   N)r7   r8   r9   r:   r;   r   r<   r   r   s   @r   r   r     s     7 7r   r   c                   `   a  ] tR tRt o RtR tR tR tR tR t	R t
R	 tR
 tR tR tRtV tR# )StackedInlineCallbacksTestsi  z
We have an optimization that invokes generators directly when an
inlineCallbacks-decorated function yields value directly to yield of
another inlineCallbacks-decorated function.
c                    V F?  w  r#\        V\        4      '       d   VP                  V4       K.  VP                  V4       KA  	  R# )z
Given a list of L{Deferred}, value tuples, invokes each L{Deferred}
with the corresponding value. Depending on whether value is an
exception, either callback or errback is called.
N)
isinstance	Exceptionrp   r   )rH   deferredListr   rF   s   &&  r   runCallbacksOnDeferreds3StackedInlineCallbacksTests.runCallbacksOnDeferreds  s3     !DA!Y''		!

1	 !r   c                  aaaa . o. o\         VV3R l4       o\         VV3R l4       o\         VV3R l4       pV! ^4      pV P                  S4       V P                  V P                  V4      ^4       V P                  S. RO4       R# )zh
Tests the case when a chain of L{inlineCallbacks} calls end up
yielding and blocking on a L{Deferred}.
c              3      <"   SP                  R V 34       \        4       pSP                  W34       Vx p V ^,          p SP                  RV 34       V # 5if1 enterf1 exitappendr   rF   r   r  expectationss   & r   f1IStackedInlineCallbacksTests.test_nonCalledDeferredSingleYield.<locals>.f1  V     Q0
A'AFAA/H   AAc              3      <"   SP                  R V 34       S! V 4      x p V ^,          p SP                  RV 34       V # 5if2 enterf2 exitr  rF   r  r  s   &r   f2IStackedInlineCallbacksTests.test_nonCalledDeferredSingleYield.<locals>.f2  C     Q0eAFAA/H   <?c              3      <"   SP                  R V 34       S! V 4      x p V ^,          p SP                  RV 34       V # 5if3 enterf3 exitr  rF   r  r  s   &r   f3IStackedInlineCallbacksTests.test_nonCalledDeferredSingleYield.<locals>.f3  r  r  Nr      r  r'  r
  r'  r  r$   r     r!     r   r  rD   r   rH   r#  resr  r  r  r  s   &  @@@@r   !test_nonCalledDeferredSingleYield=StackedInlineCallbacksTests.test_nonCalledDeferredSingleYield  s    
  			 
		 
	 
	 
	 
	 e$$\2--c2A6
	
r   c                   aaaa . o. o\         VV3R l4       oVV3R lo\         VV3R l4       pV! ^4      pV P                  S4       V P                  V P                  V4      ^4       V P                  S. RO4       R# )z}
Tests the case when a chain of L{inlineCallbacks} mixed with coroutine
calls end up yielding and blocking on a L{Deferred}.
c              3      <"   SP                  R V 34       \        4       pSP                  W34       Vx p V ^,          p SP                  RV 34       \        V 4       R# 5ir
  r  Nr  r   r   r  s   & r   r  MStackedInlineCallbacksTests.test_nonCalledDeferredSingleYieldCoro.<locals>.f1  X     Q0
A'AFAA/N   AA c                    <"   SP                  R V 34       S! V 4      G Rj  xL
 p V ^,          p SP                  RV 34       V #  L"5ir  Nr  r  r  s   &r   r  MStackedInlineCallbacksTests.test_nonCalledDeferredSingleYieldCoro.<locals>.f2(  sH     Q0eAFAA/H	 s   AA#Ac              3      <"   SP                  R V 34       S! V 4      x p V ^,          p SP                  RV 34       \        V 4       R# 5ir   r!  Nr  r   r"  s   &r   r#  MStackedInlineCallbacksTests.test_nonCalledDeferredSingleYieldCoro.<locals>.f31  sE     Q0eAFAA/Ns   AA
Nr%  r/  r0  s   &  @@@@r   %test_nonCalledDeferredSingleYieldCoroAStackedInlineCallbacksTests.test_nonCalledDeferredSingleYieldCoro  s    
  			 
			 
	 
	 e$$\2--c2A6
	
r   c                (  aaaa . o. o\         VV3R l4       o\         VV3R l4       o\         VV3R l4       pV! ^4      pS F  w  r4VP                  V4       K  	  V P                  V P                  V4      ^4       V P                  S. RO4       R# )z
Tests the case when a chain of L{inlineCallbacks} calls end up yielding
and blocking on a L{Deferred}. In this case the same decorated function
is yielded multiple times.
c              3      <"   SP                  R V 34       \        4       pSP                  W34       Vx p V ^,          p SP                  RV 34       V # 5ir	  r  r  s   & r   r  LStackedInlineCallbacksTests.test_nonCalledDeferredMultipleYields.<locals>.f1V  r  r  c              3      <"   SP                  R V 34       S! V 4      x p S! V 4      x p S! V 4      x p V ^,          p SP                  RV 34       V # 5ir  r  r  s   &r   r  LStackedInlineCallbacksTests.test_nonCalledDeferredMultipleYields.<locals>.f2b  Y     Q0eAeAeAFAA/H   AAc              3      <"   SP                  R V 34       S! V 4      x p S! V 4      x p S! V 4      x p V ^,          p SP                  RV 34       V # 5ir  r  r"  s   &r   r#  LStackedInlineCallbacksTests.test_nonCalledDeferredMultipleYields.<locals>.f3n  rI  rJ  Nr&  r(  r)  r*  r
  r$   r     )r
  rP  )r  r,  )r     )r  rQ  )r
  rQ  )r     )r
  rR  )r  r.  )r
  r.  )r  	   )r     )r  rT  )r
  rT  )r     )r
  rU  )r     )r
  rV  )r     )r     )r!     r   r   rD   r   	rH   r#  r1  r   rF   r  r  r  r  s	   &    @@@@r   $test_nonCalledDeferredMultipleYields@StackedInlineCallbacksTests.test_nonCalledDeferredMultipleYieldsK  s      			 
		 
		 
		 
		 
		 e DAJJqM ! 	--c2B7	
r   c                  aaaa . o. o\         VV3R l4       oVV3R lo\         VV3R l4       pV! ^4      pS F  w  r4VP                  V4       K  	  V P                  V P                  V4      ^4       V P                  S. RO4       R# )z
Tests the case when a chain of L{inlineCallbacks} calls mixed with async
function calls end up yielding and blocking on a L{Deferred}. In this case
the same decorated function is yielded multiple times.
c              3      <"   SP                  R V 34       \        4       pSP                  W34       Vx p V ^,          p SP                  RV 34       \        V 4       R# 5ir6  r7  r  s   & r   r  PStackedInlineCallbacksTests.test_nonCalledDeferredMultipleYieldsCoro.<locals>.f1  r9  r:  c                    <"   SP                  R V 34       S! V 4      G Rj  xL
 p S! V 4      G Rj  xL
 p S! V 4      G Rj  xL
 p V ^,          p SP                  RV 34       V #  LB L4 L&5ir<  r  r  s   &r   r  PStackedInlineCallbacksTests.test_nonCalledDeferredMultipleYieldsCoro.<locals>.f2  sd     Q0eAeAeAFAA/H s1   A+A%A+A'A+A)#A+'A+)A+c              3      <"   SP                  R V 34       S! V 4      x p S! V 4      x p S! V 4      x p V ^,          p SP                  RV 34       \        V 4       R# 5ir?  r@  r"  s   &r   r#  PStackedInlineCallbacksTests.test_nonCalledDeferredMultipleYieldsCoro.<locals>.f3  s[     Q0eAeAeAFAA/Ns   AANrM  rZ  r[  s	   &    @@@@r   (test_nonCalledDeferredMultipleYieldsCoroDStackedInlineCallbacksTests.test_nonCalledDeferredMultipleYieldsCoro  s      			 
				 
		 
		 e DAJJqM ! 	--c2B7	
r   c                   aaa . o\         V3R l4       oV3R lo\         VVV3R l4       pV P                  V P                  V! ^4      4      ^4       V P                  S. RO4       R# )z
Tests the case when a L{Deferred} produced from L{inlineCallbacks} gets
a callback added via L{addCallback} and then yielded in a function
decorated with L{inlineCallbacks}. In this case the initial L{Deferred}
already has a value.
c              3   v   <"   SP                  R V 34       V x p V ^,          p SP                  RV 34       V # 5ir	  r  rF   r  s   &r   r  QStackedInlineCallbacksTests.test_intermediateAddCallbacksAndNoWaiting.<locals>.f1  s?     Q0AFAA/Hs   69c                 f   < SP                  R V 34       V ^,          p SP                  RV 34       V # r  r  ri  s   &r   r  QStackedInlineCallbacksTests.test_intermediateAddCallbacksAndNoWaiting.<locals>.f2  5    Q0FAA/Hr   c              3      <"   SP                  R V 34       S! V 4      pVP                  S4       Vx p V ^,          p SP                  RV 34       V # 5ir  r  rL   rF   r   r  r  r  s   & r   r#  QStackedInlineCallbacksTests.test_intermediateAddCallbacksAndNoWaiting.<locals>.f3  T     Q01AMM"AFAA/H   AANr&  r)  r*  r  r$   r+  r-  )r   rD   r   )rH   r#  r  r  r  s   & @@@r   )test_intermediateAddCallbacksAndNoWaitingEStackedInlineCallbacksTests.test_intermediateAddCallbacksAndNoWaiting  sl     		 
		 
		 
		 	--be4a8
	
r   c                   aaaa . o. o\         VV3R l4       oV3R lo\         VVV3R l4       pV! ^4      pV P                  S4       V P                  V P                  V4      ^4       V P                  S. RO4       R# )a  
Tests the case when a L{Deferred} produced from L{inlineCallbacks} gets
a callback added via L{addCallback} and then yielded in a function
decorated with L{inlineCallbacks}. In this case the initial L{Deferred}
does not have a value and blocks entire callback chain.
c              3      <"   SP                  R V 34       \        4       pSP                  W34       Vx p V ^,          p SP                  RV 34       V # 5ir	  r  r  s   & r   r  ]StackedInlineCallbacksTests.test_intermediateAddCallbacksAndWithWaitingFirstYield.<locals>.f10  r  r  c                 f   < SP                  R V 34       V ^,          p SP                  RV 34       V # r  r  ri  s   &r   r  ]StackedInlineCallbacksTests.test_intermediateAddCallbacksAndWithWaitingFirstYield.<locals>.f2<  rm  r   c              3      <"   SP                  R V 34       S! V 4      pVP                  S4       Vx p V ^,          p SP                  RV 34       V # 5ir  ro  rp  s   & r   r#  ]StackedInlineCallbacksTests.test_intermediateAddCallbacksAndWithWaitingFirstYield.<locals>.f3B  rr  rs  Nrt  r/  r0  s   &  @@@@r   5test_intermediateAddCallbacksAndWithWaitingFirstYieldQStackedInlineCallbacksTests.test_intermediateAddCallbacksAndWithWaitingFirstYield$  s      			 
			 
		 
		 e$$\2--c2A6
	
r   c                   aaaa . o. o\         VV3R l4       oV3R lo\         VVV3R l4       pV! ^4      pV P                  S4       V P                  V P                  V4      ^	4       V P                  S. RO4       R# )a_  
Tests the case when a L{Deferred} produced from L{inlineCallbacks} gets
a callback added via L{addCallback} and then yielded in a function
decorated with L{inlineCallbacks}. In this case the initial L{Deferred}
does not have a value and blocks the entire callback chain.
Additionally, a subsequent L{Deferred} blocks the entire callback chain
again.
c              3      <"   SP                  R V 34       \        4       pSP                  W34       Vx p V ^,          p SP                  RV 34       V # 5ir	  r  r  s   & r   r  ^StackedInlineCallbacksTests.test_intermediateAddCallbacksAndWithWaitingSecondYield.<locals>.f1l  r  r  c                 f   < SP                  R V 34       V ^,          p SP                  RV 34       V # r  r  ri  s   &r   r  ^StackedInlineCallbacksTests.test_intermediateAddCallbacksAndWithWaitingSecondYield.<locals>.f2x  rm  r   c              3      <"   SP                  R V 34       S! V 4      x p S! V 4      pVP                  S4       Vx p V ^,          p SP                  RV 34       V # 5ir  ro  rp  s   & r   r#  ^StackedInlineCallbacksTests.test_intermediateAddCallbacksAndWithWaitingSecondYield.<locals>.f3~  s_     Q0eA1AMM"AFAA/Hs   AAN)r&  r)  r*  rN  rO  )r  rP  )r  r   )r!  rS  r/  r0  s   &  @@@@r   6test_intermediateAddCallbacksAndWithWaitingSecondYieldRStackedInlineCallbacksTests.test_intermediateAddCallbacksAndWithWaitingSecondYield^  s      			 
			 

	 

	 e$$\2--c2A6		
r   c                  a aaaa . o. o ! R R\         4      o\        VVV3R l4       o\        VVVV 3R l4       pV! ^4      pS P                  S4       S P                  S P	                  V4      ^4       S P                  S. RO4       R# )zr
Tests the case when a function decorated with L{inlineCallbacks} yields
a L{Deferred} that results in a failure.
c                       ] tR tRtRtR# )iStackedInlineCallbacksTests.test_raisesExceptionFromDeferredWithWaitingFirstCallback.<locals>.MyExceptioni  r5   Nr7   r8   r9   r:   r<   r5   r   r   MyExceptionr        r   r  c              3      <"   SP                  R V 34       \        4       pSP                  VS! 4       34       Vx p SP                  RV 34       V # 5ir  r  rF   r   r  r  r  s   & r   r  `StackedInlineCallbacksTests.test_raisesExceptionFromDeferredWithWaitingFirstCallback.<locals>.f2  T     Q0
AKM 23A
 A/Hrs  c              3      <"   SP                  R V 34       SP                  S4      ;_uu_ 4        S! V 4      x p RRR4       V ^,          p SP                  RV 34       V #   + '       g   i     L.; i5ir   Nr!  r  r   )rF   r  r  r  rH   s   &r   r#  `StackedInlineCallbacksTests.test_raisesExceptionFromDeferredWithWaitingFirstCallback.<locals>.f3  sa     Q0"";//Q%K 0FAA/H 0/s   -A4A!&A4!A1	,A4N)r&  r(  )r!  r   r  r   r  rD   r   )rH   r#  r1  r  r  r  r  s   f  @@@@r   8test_raisesExceptionFromDeferredWithWaitingFirstCallbackTStackedInlineCallbacksTests.test_raisesExceptionFromDeferredWithWaitingFirstCallback  s    
  	) 	 
	 
	 
	 
	 e$$\2--c2A6	
r   c                <  a aaaaa . o. o ! R R\         4      o\        VV3R l4       o\        VVV3R l4       o\        VVVVV 3R l4       pV! ^4      pS P                  S4       S P                  S P	                  V4      ^4       S P                  S. RO4       R# )z
Tests the case when a function decorated with L{inlineCallbacks} blocks
on a L{Deferred} produced by another function decorated with
L{inlineCallbacks}. Once that unblocks, a L{Deferred} that results
in an failure is yielded.
c                       ] tR tRtRtR# )jStackedInlineCallbacksTests.test_raisesExceptionFromDeferredWithWaitingSecondCallback.<locals>.MyExceptioni  r5   Nr  r5   r   r   r  r    r  r   r  c              3      <"   SP                  R V 34       \        4       pSP                  W34       Vx p V ^,          p SP                  RV 34       V # 5ir	  r  r  s   & r   r  aStackedInlineCallbacksTests.test_raisesExceptionFromDeferredWithWaitingSecondCallback.<locals>.f1  r  r  c              3      <"   SP                  R V 34       \        4       pSP                  VS! 4       34       Vx p SP                  RV 34       V # 5ir  r  r  s   & r   r  aStackedInlineCallbacksTests.test_raisesExceptionFromDeferredWithWaitingSecondCallback.<locals>.f2  r  rs  c              3      <"   SP                  R V 34       S! V 4      x p SP                  S4      ;_uu_ 4        S! V 4      x p RRR4       V ^,          p SP                  RV 34       V #   + '       g   i     L.; i5ir  r  )rF   r  r  r  r  rH   s   &r   r#  aStackedInlineCallbacksTests.test_raisesExceptionFromDeferredWithWaitingSecondCallback.<locals>.f3  sl     Q0eA"";//Q%K 0FAA/H 0/s   7A>A+&A>+A;	6A>N)r&  r)  r*  ru  )r!  rQ  r  )rH   r#  r1  r  r  r  r  r  s   f  @@@@@r   9test_raisesExceptionFromDeferredWithWaitingSecondCallbackUStackedInlineCallbacksTests.test_raisesExceptionFromDeferredWithWaitingSecondCallback  s      	) 	 
		 
		 
	 
	 
		 		 
		 e$$\2--c2A6		
r   r5   N)r7   r8   r9   r:   r;   r  r2  rB  r\  re  rv  r  r  r  r  r<   r   r   s   @r   r   r     sM     
8
t7
rR
hQ
f0
d8
t=
~0
dA
 A
r   r   c                   <   a  ] tR tRt o RtR tR tR tR tRt	V t
R# )	NonLocalExitTestsi  a  
It's possible for L{returnValue} to be (accidentally) invoked at a stack
level below the L{inlineCallbacks}-decorated function which it is exiting.
If this happens, L{returnValue} should report useful errors.

If L{returnValue} is invoked from a function not decorated by
L{inlineCallbacks}, it will emit a warning if it causes an
L{inlineCallbacks} function further up the stack to exit.
c                    \        ^4       R# )zs
This method mistakenly invokes L{returnValue}, despite the fact that it
is not decorated with L{inlineCallbacks}.
Nr   rH   s   &r   mistakenMethod NonLocalExitTests.mistakenMethod  s    
 	Ar   c                   V P                  V^.4       V P                  V P                  .R7      pV P                  \        V4      ^4       V P                  V^ ,          R,          \        4       V P                  V^,          R,          \        4       V P                  RV^ ,          R,          4       V P                  V^,          R,          R4       R# )a3  
Flush the current warnings and assert that we have been told that
C{mistakenMethod} was invoked, and that the result from the Deferred
that was fired (appended to the given list) is C{mistakenMethod}'s
result.  The warning should indicate that an inlineCallbacks function
called 'inline' was made to exit.
)offendingFunctionsr   r   r   zreturnValue() in 'mistakenMethod' causing 'inline' to exit: returnValue should only be invoked by functions decorated with inlineCallbacksN)rD   r   r  r   r   r   )rH   
resultListr   s   && r   assertMistakenMethodWarning-NonLocalExitTests.assertMistakenMethodWarning%  s     	aS)%%$:M:M9N%OX*!Z02DE!Z02DEJQK	"	
 	QK	"	
r   c                   a  \         V 3R l4       pV! 4       p. pVP                  VP                  4       S P                  V4       R# )z~
L{returnValue} will emit a non-local exit warning in the simplest case,
where the offending function is invoked immediately.
c               3   N   <"   S P                  4        \        ^4       ^ x  R# 5ir$   Nr  r   r  s   r   inlineANonLocalExitTests.test_returnValueNonLocalWarning.<locals>.inlineC  s     !NG   "%N)r   rL   r  r  )rH   r  r   resultss   f   r   test_returnValueNonLocalWarning1NonLocalExitTests.test_returnValueNonLocalWarning=  sC     
	 
	
 H	gnn%((1r   c                   a a \        4       o\        VV 3R l4       pV! 4       p. pVP                  VP                  4       S P	                  V. 4       SP                  ^4       S P                  V4       R# )z
L{returnValue} will emit a non-local warning in the case where the
L{inlineCallbacks}-decorated function has already yielded a Deferred
and therefore moved its generator function along.
c               3   N   <"   S x  SP                  4        \        ^4       R# 5ir  r  )causerH   s   r   r  BNonLocalExitTests.test_returnValueNonLocalDeferred.<locals>.inlineV  s     K!Nr  N)r   r   rL   r  rD   r   r  )rH   r  effectr  r  s   f   @r    test_returnValueNonLocalDeferred2NonLocalExitTests.test_returnValueNonLocalDeferredN  sh     
		 
	
 7>>*"%q((1r   r5   N)r7   r8   r9   r:   r;   r  r  r  r  r<   r   r   s   @r   r  r    s#     
02"2 2r   r  c                   J   a  ] tR tRt o R tR tR tR tV 3R lR ltRt	V t
R	# )
ForwardTraceBackTestsid  c                   a \         R 4       o\         V3R l4       pV! 4       pV P                  V4      pVP                  4       pV P                  RV4       V P                  RV4       V P                  RV4       R# )z
Chained inlineCallbacks are forwarding the traceback information
from generator to generator.

A first simple test with a couple of inline callbacks.
c               3   (   "   R x  \        R4      h5izforcing generatorError Markerr  r5   r   r   erroring>ForwardTraceBackTests.test_forwardTracebacks.<locals>.erroringm       %%N++   c               3   "   <"   S ! 4       x  R # 5ir   r5   r  s   r   calling=ForwardTraceBackTests.test_forwardTracebacks.<locals>.callingr       *   in erroring
in callingr  Nr   failureResultOfgetTracebackr   )rH   r  r   r-   r   r  s   &    @r   test_forwardTracebacks,ForwardTraceBackTests.test_forwardTracebackse  sz     
	, 
	, 
	 
	 I  #^^mR(lB'nb)r   c                f   a a R o\         V3R l4       pV! 4       pVP                  V 3R l4       pV# )zl
Chained inlineCallback and coroutine are forwarding the traceback
information from coroutine to generator.
c                  J   "   \        R 4      G Rj  xL
  \        R4      h L5i)r   Nr  )r   r  r5   r   r   r  BForwardTraceBackTests.test_forwardTracebacksCoro.<locals>.erroring  s#     %g...N++ /r2   c               3   "   <"   S ! 4       x  R # 5ir   r5   r  s   r   r  AForwardTraceBackTests.test_forwardTracebacksCoro.<locals>.calling  r  r  c                    < V P                  4       pSP                  R V4       SP                  RV4       SP                  RV4       R# )r  r  r  N)r  r   )r-   r   rH   s   & r   check?ForwardTraceBackTests.test_forwardTracebacksCoro.<locals>.check  s9    !BMM-,MM,+MM."-r   )r   
addErrback)rH   r  r   r  r  s   f   @r   test_forwardTracebacksCoro0ForwardTraceBackTests.test_forwardTracebacksCoro}  sB    	, 
	 
	 I	
	. 
	. r   c                  aaa \         R 4       o\         V3R l4       o\         V3R l4       o\         V3R l4       pV! 4       pV P                  V4      pVP                  4       pV P                  RV4       V P                  RV4       V P                  RV4       V P                  RV4       V P                  R	V4       V P                  RVP                  4       4       R
# )aE  
Several Chained inlineCallbacks gives information about all generators.

A wider test with a 4 chained inline callbacks.

Application stack-trace should be reported, and implementation details
like "throwExceptionIntoGenerator" symbols are omitted from the stack.

Note that the previous test is testing the simple case, and this one is
testing the deep recursion case.

That case needs specific code in failure.py to accomodate to stack
breakage introduced by throwExceptionIntoGenerator.

Hence we keep the two tests in order to sort out which code we
might have regression in.
c               3   (   "   R x  \        R4      h5ir  r  r5   r   r   r  DForwardTraceBackTests.test_forwardLotsOfTracebacks.<locals>.erroring  r  r  c               3   "   <"   S ! 4       x  R # 5ir   r5   r  s   r   calling3DForwardTraceBackTests.test_forwardLotsOfTracebacks.<locals>.calling3  r  r  c               3   "   <"   S ! 4       x  R # 5ir   r5   r  s   r   calling2DForwardTraceBackTests.test_forwardLotsOfTracebacks.<locals>.calling2  r  r  c               3   "   <"   S ! 4       x  R # 5ir   r5   r  s   r   r  CForwardTraceBackTests.test_forwardLotsOfTracebacks.<locals>.calling  r  r  r  r  in calling2in calling3r  Nr  rH   r  r   r-   r   r  r  r  s   &    @@@r   test_forwardLotsOfTracebacks2ForwardTraceBackTests.test_forwardLotsOfTracebacks  s    & 
	, 
	, 
	 
	 
	 
	 
	 
	 I  #^^mR(lB'mR(mR(nb)mQ^^%56r   c                  aaa \         R 4       oV3R lo\         V3R l4       o\         V3R l4       pV! 4       pV P                  V4      pVP                  4       pV P                  RV4       V P                  RV4       V P                  RV4       V P                  RV4       V P                  R	V4       V P                  RVP                  4       4       R
# )z
Several chained inlineCallbacks mixed with coroutines gives information
about all generators.

A wider test with a 4 chained inline callbacks.
c               3   (   "   R x  \        R4      h5ir  r  r5   r   r   r  HForwardTraceBackTests.test_forwardLotsOfTracebacksCoro.<locals>.erroring  r  r  c                  2   <"   S ! 4       G R j  xL
  R #  L5ir   r5   r  s   r   r  HForwardTraceBackTests.test_forwardLotsOfTracebacksCoro.<locals>.calling3  s     *s   c               3   "   <"   S ! 4       x  R # 5ir   r5   r  s   r   r  HForwardTraceBackTests.test_forwardLotsOfTracebacksCoro.<locals>.calling2  r  r  c               3   "   <"   S ! 4       x  R # 5ir   r5   r  s   r   r  GForwardTraceBackTests.test_forwardLotsOfTracebacksCoro.<locals>.calling  r  r  r  r  r  r  r  Nr  r  s   &    @@@r    test_forwardLotsOfTracebacksCoro6ForwardTraceBackTests.test_forwardLotsOfTracebacksCoro  s     
	, 
	,	 
	 
	 
	 
	 I  #^^mR(lB'mR(mR(nb)mQ^^%56r   c                   < V ^8  d   QhRR/# r   r5   )r(   r   s   "r   r)   "ForwardTraceBackTests.__annotate__  s     "9 "9D "9r   c                   \        R4      p\        4       p VP                  4        R R lp\        V4       V P                  V4      p\        P                  ! VP                  4       4      pV P                  \        V4      ^4       V P                  RV^,          ^ ,          4       V P                  RV^,          ^,          4       V P                  RV^,          ^,          4       V P                  RV^ ,          ^ ,          4       V P                  RV^ ,          ^,          4       V P                  RV^ ,          ^,          4       R	#   \         d    TP	                  4         ELAi ; i)
z
L{defer.inlineCallbacks} that receives tracebacks from a regular Deferred and
re-raise tracebacks into their deferred should not lose their tracebacks.
r%   c                T    V ^8  d   QhR\         R\        \        \        R3,          /# )r$   r   r&   N)objectr   r   )r(   s   "r   r)   NForwardTraceBackTests.test_reraiseTracebacksFromDeferred.<locals>.__annotate__  s%     		 		& 		YsC~6 		r   c              3     "   V x  R# 5i)z
This is never called.
It is only used as the decorated function.
The resulting function is never called in this test.
This is used to make sure that if we wrap
an already failed deferred, inlineCallbacks
will not add any extra traceback frames.
Nr5   rm   s   &r   icDForwardTraceBackTests.test_reraiseTracebacksFromDeferred.<locals>.ic  s      Gr   test_inlinecbr.   zraise ZeroDivisionError(msg)"test_reraiseTracebacksFromDeferredzf.raiseException()N)r.   r   raiseExceptionr,   rp   r   r  r   
extract_tbgetTracebackObjectrD   r   r   )rH   r-   r   r	  
newFailurer   s   &     r   r  8ForwardTraceBackTests.test_reraiseTracebacksFromDeferred  s   
 u%$J			 	))!,
!!*"?"?"ABR!$or!uQx0-r!uQx87AqBor!uQx0=r!uQxH-r!uQx83  	IIK	s   E
 
E)(E)r5   N)r7   r8   r9   r:   r  r  r  r   r  r<   r   r   s   @r   r  r  d  s%     *02,7\ 7D"9 "9r   r  c                       ] tR tRtRtRtR# )UntranslatedErrori  zD
Untranslated exception type when testing an exception translation.
r5   Nr6   r5   r   r   r  r        r   r  c                       ] tR tRtRtRtR# )TranslatedErrori  zB
Translated exception type when testing an exception translation.
r5   Nr6   r5   r   r   r  r    r  r   r  c                   *   a  ] tR tRt o RtR tRtV tR# )DontFaili  z
Sample exception type.
c                <    \         P                  V 4       Wn        R # r   )r  __init__actualValue)rH   actuals   &&r   r  DontFail.__init__  s    4 !r   )r  N)r7   r8   r9   r:   r;   r  r<   r   r   s   @r   r  r    s     " "r   r  c                   "    ] tR tRt^ t^t^tRtR# )CancellationTestsStackedTypei!  r5   N)r7   r8   r9   r:   NOT_STACKEDSTACKED_INLINECBSTACKED_COROr<   r5   r   r   r  r  !  s    KLr   r  c                   D  a  ] tR tRt o RtR tR t]R 4       tR t	]R,R l4       t
R	 tR-R
 ltR.R ltR tR tR tR tR tR.R ltR tR tR tR tR tR.R ltR tR tR tR tR tR.R ltR t R t!R  t"R! t#R" t$R.R# lt%R$ t&R% t'R& t(R' t)R( t*V 3R) lR* lt+R+t,V t-R# )/CancellationTestsi'  a	  
Tests for cancellation of L{Deferred}s returned by L{inlineCallbacks}.
For each of these tests, let:
    - C{G} be a generator decorated with C{inlineCallbacks}
    - C{D} be a L{Deferred} returned by C{G}
    - C{C} be a L{Deferred} awaited by C{G} with C{yield}
c                    . V n         R# )z.
Set up the list of outstanding L{Deferred}s.
NdeferredsOutstandingr  s   &r   setUpCancellationTests.setUp0  s     %'!r   c                N    V P                   '       d   V P                  4        K$  R# )z7
If any L{Deferred}s are still outstanding, fire them.
N)r'  deferredGottenr  s   &r   tearDownCancellationTests.tearDown6  s!     '''! (r   c              #      "   V! 4       x pV# 5ir   r5   )rH   getChildDeferredrF   s   && r   stackedInlineCB!CancellationTests.stackedInlineCB=  s     "$$s   c                ,   "   V! 4       G R j  xL
 #  L5ir   r5   )rH   r/  s   &&r   stackedCoroCancellationTests.stackedCoroB  s     %''''s   Nc              #    "   Vf   V P                   p V\        P                  8X  d   V! 4       x pV^,           # V'       d   Vx  V\        P                  8X  d   V P	                  V4      x pV^,           # V P                  V4      x p V^,           #   \         d    \        4       h\         d&   pTP                  ^,
          p Rp?T^,           # Rp?ii ; i5i)z
Generator for testing cascade cancelling cases.

@param getChildDeferred: Some callable returning L{Deferred} that we
    awaiting (with C{yield})
N)
getDeferredr  r   r!  r3  r0  r  r  r  r  )rH   	stackTyper/  firstDeferredrF   dfs   &&&&  r   sampleInlineCB CancellationTests.sampleInlineCBE  s      ##//	#8DDD*,, 1u !'' < M MM"../?@@A 1u #223CDDA
 1u	 ! 	$!## 	#"A1u	#sP   CB 	CB ,B /	C8B 
CC3C4CCCCc                n    V P                   P                  \        4       4       V P                   R,          # )z
A sample function that returns a L{Deferred} that can be fired on
demand, by L{CancellationTests.deferredGotten}.

@return: L{Deferred} that can be fired on demand.
)r'  r  r   r  s   &r   r6  CancellationTests.getDeferred_  s+     	!!((4((,,r   c                Z    V P                   P                  ^ 4      P                  V4       R# )z
Fire the L{Deferred} returned from the least-recent call to
L{CancellationTests.getDeferred}.

@param result: result object to be used when firing the L{Deferred}.
N)r'  popr   )rH   results   &&r   r+   CancellationTests.deferredGotteni  s#     	!!%%a(11&9r   c                  a R.oV3R lpRpV'       d   \        4       pV P                  VVVR7      pVP                  R 4       V'       d   VP                  ^4       VP	                  4        V P                  S^ ,          \        R4       R# )z
When C{D} cancelled, C{C} will be immediately cancelled too.

@param stackType: defines test stacking scenario

@param cancelOnSecondDeferred: if True, tests cancellation on the
    second yield in inlineCallbacks
FAILUREc                  J   < \        4       p V3R  lpV P                  V4       V # )c                 8   < V P                  \        4      S^ &   V # r   )r  r
   )rA  childResultHolders   &r   _ebTCancellationTests.doCascadeCancellingOnCancel.<locals>.getChildDeferred.<locals>._eb  s    '-||N'C!!$r   r   r  )r   rH  rG  s     r   r/  GCancellationTests.doCascadeCancellingOnCancel.<locals>.getChildDeferred}  s"    
A LLHr   Nr/  r7  r8  c                     R # r   r5   )rA  s   &r   <lambda>?CancellationTests.doCascadeCancellingOnCancel.<locals>.<lambda>  s    Dr   zno cascade cancelling occurs)r   r:  r  r   cancelrD   r
   )rH   r7  cancelOnSecondDeferredr/  r8  r   rG  s   &&&   @r   doCascadeCancellingOnCancel-CancellationTests.doCascadeCancellingOnCancelr  s     'K	 !$JM-'   

 	
()""1%	
a *	
r   c                D    V P                  \        P                  4       R # r   )rR  r  r   r  s   &r   (test_CascadeCancellingOnCancelNotStacked:CancellationTests.test_CascadeCancellingOnCancelNotStacked      (()E)Q)QRr   c                D    V P                  \        P                  4       R # r   rR  r  r!  r  s   &r   -test_CascadeCancellingOnCancelStackedInlineCb?CancellationTests.test_CascadeCancellingOnCancelStackedInlineCb      (()E)V)VWr   c                H    V P                  \        P                  R R7       R# T)rQ  NrY  r  s   &r   =test_CascadeCancellingOnCancelStackedInlineCbOnSecondDeferredOCancellationTests.test_CascadeCancellingOnCancelStackedInlineCbOnSecondDeferred  !    (((99RV 	) 	
r   c                D    V P                  \        P                  4       R # r   rR  r  r"  r  s   &r   )test_CascadeCancellingOnCancelStackedCoro;CancellationTests.test_CascadeCancellingOnCancelStackedCoro      (()E)R)RSr   c                H    V P                  \        P                  R R7       R# r^  rc  r  s   &r   9test_CascadeCancellingOnCancelStackedCoroOnSecondDeferredKCancellationTests.test_CascadeCancellingOnCancelStackedCoroOnSecondDeferred       (((55d 	) 	
r   c                   RpV'       d   \        4       pV P                  WR7      pV'       d   VP                  ^4       VP                  4        V P	                  \
        V P                  V4      P                  4       R# )z
When C{D} cancelled, CancelledError from C{C} will be errbacked
through C{D}.

@param stackType: defines test stacking scenario

@param cancelOnSecondDeferred: if True, tests cancellation on the
    second yield in inlineCallbacks
N)r7  r8  )r   r:  r   rP  r   r
   r  r  )rH   r7  rQ  r8  r   s   &&&  r   doErrbackCancelledErrorOnCancel1CancellationTests.doErrbackCancelledErrorOnCancel  sa     !$JM)Q""1%	
.$*>*>q*A*P*PQr   c                D    V P                  \        P                  4       R # r   )rl  r  r   r  s   &r   "test_ErrbackCancelledErrorOnCancel4CancellationTests.test_ErrbackCancelledErrorOnCancel  s    ,,-I-U-UVr   c                D    V P                  \        P                  4       R # r   rl  r  r!  r  s   &r   1test_ErrbackCancelledErrorOnCancelStackedInlineCbCCancellationTests.test_ErrbackCancelledErrorOnCancelStackedInlineCb  s    ,,(99	
r   c                H    V P                  \        P                  R R7       R# r^  rr  r  s   &r   Atest_ErrbackCancelledErrorOnCancelStackedInlineCbOnSecondDeferredSCancellationTests.test_ErrbackCancelledErrorOnCancelStackedInlineCbOnSecondDeferred  s!    ,,(99RV 	- 	
r   c                D    V P                  \        P                  4       R # r   rl  r  r"  r  s   &r   -test_ErrbackCancelledErrorOnCancelStackedCoro?CancellationTests.test_ErrbackCancelledErrorOnCancelStackedCoro  s    ,,-I-V-VWr   c                H    V P                  \        P                  R R7       R# r^  ry  r  s   &r   =test_ErrbackCancelledErrorOnCancelStackedCoroOnSecondDeferredOCancellationTests.test_ErrbackCancelledErrorOnCancelStackedCoroOnSecondDeferred  s     ,,(55d 	- 	
r   c                *  a R pRpV'       d   \        4       p\        V4      oV P                  V3R lWR7      pV'       d   VP                  ^4       VP                  4        V P	                  \
        V P                  V4      P                  4       R# )z
When C{D} is cancelled, and C raises a particular type of error, C{G}
may catch that error at the point of yielding and translate it into
a different error which may be received by application code.
c                 8    V P                  \        4       4       R # r   )rp   r  its   &r   rP  ;CancellationTests.doErrorToErrorTranslation.<locals>.cancel  s    JJ(*+r   Nc                     < S # r   r5   r   s   r   rN  =CancellationTests.doErrorToErrorTranslation.<locals>.<lambda>      Qr   rL  )r   r:  r   rP  r   r  r  r  )rH   r7  rQ  rP  r8  r   r   s   &&&   @r   doErrorToErrorTranslation+CancellationTests.doErrorToErrorTranslation  sz    	, !$JMV&)   
 ""1%	
/4+?+?+B+Q+QRr   c                D    V P                  \        P                  4       R # r   )r  r  r   r  s   &r   test_ErrorToErrorTranslation.CancellationTests.test_ErrorToErrorTranslation  s    &&'C'O'OPr   c                D    V P                  \        P                  4       R # r   r  r  r!  r  s   &r   +test_ErrorToErrorTranslationStackedInlineCb=CancellationTests.test_ErrorToErrorTranslationStackedInlineCb  s    &&'C'T'TUr   c                H    V P                  \        P                  R R7       R# r^  r  r  s   &r   ;test_ErrorToErrorTranslationStackedInlineCbOnSecondDeferredMCancellationTests.test_ErrorToErrorTranslationStackedInlineCbOnSecondDeferred  s!    &&(99RV 	' 	
r   c                D    V P                  \        P                  4       R # r   r  r  r"  r  s   &r   'test_ErrorToErrorTranslationStackedCoro9CancellationTests.test_ErrorToErrorTranslationStackedCoro  s    &&'C'P'PQr   c                H    V P                  \        P                  R R7       R# r^  r  r  s   &r   7test_ErrorToErrorTranslationStackedCoroOnSecondDeferredICancellationTests.test_ErrorToErrorTranslationStackedCoroOnSecondDeferred  s     &&(55d 	' 	
r   c                ,  a R pRpV'       d   \        4       p\        V4      oV P                  V3R lWR7      p. pVP                  VP                  4       V'       d   VP	                  ^4       VP                  4        V P                  VR.4       R# )z
When C{D} is cancelled, and C{C} raises a particular type of error,
C{G} may catch that error at the point of yielding and translate it
into a result value which may be received by application code.
c                 :    V P                  \        R 4      4       R# )i  N)rp   r  r  s   &r   rP  =CancellationTests.doErrorToSuccessTranslation.<locals>.cancel  s    JJx~&r   Nc                     < S # r   r5   r   s   r   rN  ?CancellationTests.doErrorToSuccessTranslation.<locals>.<lambda>  r  r   rL  i  )r   r:  rL   r  r   rP  assertEquals)rH   r7  rQ  rP  r8  r   r  r   s   &&&    @r   doErrorToSuccessTranslation-CancellationTests.doErrorToSuccessTranslation  s    	' !$JMV&)   
 	gnn%""1%	
'D6*r   c                D    V P                  \        P                  4       R # r   )r  r  r   r  s   &r   test_ErrorToSuccessTranslation0CancellationTests.test_ErrorToSuccessTranslation  rW  r   c                D    V P                  \        P                  4       R # r   r  r  r!  r  s   &r   -test_ErrorToSuccessTranslationStackedInlineCb?CancellationTests.test_ErrorToSuccessTranslationStackedInlineCb  r\  r   c                H    V P                  \        P                  R R7       R# r^  r  r  s   &r   =test_ErrorToSuccessTranslationStackedInlineCbOnSecondDeferredOCancellationTests.test_ErrorToSuccessTranslationStackedInlineCbOnSecondDeferred  ra  r   c                D    V P                  \        P                  4       R # r   r  r  r"  r  s   &r   )test_ErrorToSuccessTranslationStackedCoro;CancellationTests.test_ErrorToSuccessTranslationStackedCoro!  rf  r   c                H    V P                  \        P                  R R7       R# r^  r  r  s   &r   9test_ErrorToSuccessTranslationStackedCoroOnSecondDeferredKCancellationTests.test_ErrorToSuccessTranslationStackedCoroOnSecondDeferred$  rj  r   c                \  aa \        4       oV3R loV3R lpRpV'       d   \        4       pV P                  W1VR7      pV'       d   VP                  ^4       VP                  4        V P	                  V4       SP                  R4       V P                  V P                  V4      R4       R# )z
When C{D} is cancelled, it won't reach the callbacks added to it by
application code until C{C} reaches the point in its callback chain
where C{G} awaits it.  Otherwise, application code won't be able to
track resource usage that C{D} may be using.
c                 2   < V P                  \        4       S# r   )trapr
   )rA  moreDeferreds   &r   deferMeMoreACancellationTests.doAsynchronousCancellation.<locals>.deferMeMore2  s    KK'r   c                  >   < \        4       p V P                  S4       V # r   rJ  )r   r  s    r   deferMe=CancellationTests.doAsynchronousCancellation.<locals>.deferMe6  s    
ALL%Hr   NrL  i  i  )r   r:  r   rP  assertNoResultrD   r   )rH   r7  rQ  r  r8  r   r  r  s   &&&   @@r   doAsynchronousCancellation,CancellationTests.doAsynchronousCancellation)  s      z	 	
 !$JM$   
 ""1%	
Ad#--a0$7r   c                D    V P                  \        P                  4       R # r   )r  r  r   r  s   &r   test_AsynchronousCancellation/CancellationTests.test_AsynchronousCancellationH  s    ''(D(P(PQr   c                D    V P                  \        P                  4       R # r   r  r  r!  r  s   &r   ,test_AsynchronousCancellationStackedInlineCb>CancellationTests.test_AsynchronousCancellationStackedInlineCbK  s    ''(D(U(UVr   c                H    V P                  \        P                  R R7       R# r^  r  r  s   &r   <test_AsynchronousCancellationStackedInlineCbOnSecondDeferredNCancellationTests.test_AsynchronousCancellationStackedInlineCbOnSecondDeferredN  s!    ''(99RV 	( 	
r   c                D    V P                  \        P                  4       R # r   r  r  r"  r  s   &r   (test_AsynchronousCancellationStackedCoro:CancellationTests.test_AsynchronousCancellationStackedCoroS  s    ''(D(Q(QRr   c                H    V P                  \        P                  R R7       R# r^  r  r  s   &r   8test_AsynchronousCancellationStackedCoroOnSecondDeferredJCancellationTests.test_AsynchronousCancellationStackedCoroOnSecondDeferredV  s     ''(55d 	( 	
r   c                   < V ^8  d   QhRR/# r   r5   )r(   r   s   "r   r)   CancellationTests.__annotate__[  s     50 50D 50r   c                |  aa . p. p\        VP                  4      o\        VP                  4      o\        R VV3R ll4       pV! 4       pV P                  S4       V P                  S4       V P                  V4       V P	                  V. 4       V P	                  V. 4       VP                  4        V P	                  VS.4       V P	                  V. 4       V P                  V4       VP                  4        V P                  V4      pV P	                  VP                  \        4       V P	                  VS.4       R# )a,  
Cancelling an L{defer.inlineCallbacks} correctly handles the function
catching the L{defer.CancelledError}.

The desired behavior is:
    1. If the function is waiting on an inner deferred, that inner
       deferred is cancelled, and a L{defer.CancelledError} is raised
       within the function.
    2. If the function catches that exception, execution continues, and
       the deferred returned by the function is not resolved.
    3. Cancelling the deferred again cancels any deferred the function
       is waiting on, and the exception is raised.
c                ^    V ^8  d   QhR\         \        \        ,          \        R3,          /# r   )r   r   r  )r(   s   "r   r)   JCancellationTests.test_inlineCallbacksCancelCaptured.<locals>.__annotate__o  s$     	 	)HV$4fd$BC 	r   c               3   D   <"    S x  Sx  R #   \          d     Li ; i5ir   r  )r   r   s   r   testFuncFCancellationTests.test_inlineCallbacksCancelCaptured.<locals>.testFuncn  s*      H  s        N)	r   r  r   r  rD   rP  r  typer
   )rH   canceller1Callscanceller2Callsr  r   failurer   r   s   &     @@r   "test_inlineCallbacksCancelCaptured4CancellationTests.test_inlineCallbacksCancelCaptured[  s    3524'(>(>?'(>(>?		 	 
	 
BBE""-"-
 	2$/"-E"
 	&&u-~62$/r   r&  )NNr   )F).r7   r8   r9   r:   r;   r(  r,  r   r0  r3  r:  r6  r+  rR  rU  rZ  r_  rd  rh  rl  ro  rs  rv  rz  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r<   r   r   s   @r   r$  r$  '  s     '"  (  2-:%
NSX

T

R(W



X

S,QV

R

+0SX

T

8>RW

S

50 50r   r$  r   )-r;   r   unittestr   r   enumr   typingr   r   r   r   r   twisted.internetr   r	   twisted.internet.deferr
   r   r   r   r   r   r   twisted.python.compatr   twisted.trial.unittestr   r   r   r!   r.   r1   r  r4   r>   r   r   r  r  r  r  r  r  r$  r5   r   r   <module>r     s   
     3 3 *   ( @,!		 	a* a*H7x 7<K	
( K	
\N2 N2bd9/ d9N	 i "y "4 i0+ i0r   