+
    Dfj&                     t   R t ^ RIt^ RIt^ RIHtHtHtHtHtH	t	H
t
HtHt ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^RIHt RtRt ]P$                  P3                  R	4      '       d   ^ R
IHtHt RtRt]! 4       P;                  4       t]! ]]4      t ]PC                  4         ! R R]]4      t"R#   ] d     LEi ; i)z/
Tests for L{twisted.internet.asyncioreactor}.
N)	AbstractEventLoopAbstractEventLoopPolicyDefaultEventLoopPolicyFutureSelectorEventLoopget_event_loopget_event_loop_policyset_event_loopset_event_loop_policy)skipIf)AsyncioSelectorReactor)platform)SynchronousTestCase)ReactorBuilderFwin32)WindowsProactorEventLoopPolicyWindowsSelectorEventLoopPolicyTc            
       <  a  ] tR t^0t o RtR tV 3R lR lt]! ]'       * RP                  ]
! ]4      ]P                  P                  ]P                  P                  ]P"                  ! 4       4      4      R 4       t]! ]'       * RP                  ]
! ]4      ]P                  P                  ]P                  P                  ]P"                  ! 4       4      4      R 4       t]! ]RP                  ]
! ]4      ]P                  P                  ]P                  P                  ]P"                  ! 4       4      4      R	 4       t]! ]'       * R
4      R 4       t]! ]'       * R4      R 4       t]! ]'       * R4      R 4       t]! ]'       * R4      R 4       tR tR tR tR tRtV t R# )AsyncioSelectorReactorTestsz"
L{AsyncioSelectorReactor} tests.
c                   aa \        4       p. oVV3R lpVP                  V4       VP                  R4       V P                  S. 4       V P	                  S^R7       V P                  SR.4       R# )zV
Ensure that C{reactor} has an event loop that works
properly with L{asyncio.Future}.
c                 f   < SP                  V P                  4       4       SP                  4        R # N)appendresultstop)futurereactorr   s   &K/usr/lib/python3/dist-packages/twisted/internet/test/test_asyncioreactor.py	completedRAsyncioSelectorReactorTests.assertReactorWorksWithAsyncioFuture.<locals>.completed=   s    MM&--/*LLN    T)timeoutN)r   add_done_callback
set_resultassertEqual
runReactor)selfr   r   r   r   s   &f  @r   #assertReactorWorksWithAsyncioFuture?AsyncioSelectorReactorTests.assertReactorWorksWithAsyncioFuture5   sf    
 	 	  +$$+$(r    c                &   < V ^8  d   QhRS[ RS[/# )   policyreturn)r   r   )format__classdict__s   "r   __annotate__(AsyncioSelectorReactorTests.__annotate__H   s      5 :K r    c                   aaa \        4       o\        4       oVP                  4       oV P                  VVV3R l4       pS# )zx
Make a new asyncio loop from a policy for use with a reactor, and add
appropriate cleanup to restore any global state.
c                  T   < SP                  4        \        S 4       \        S4       R # r   )closer	   r
   )existingLoopexistingPolicyr   s   r   cleanUp4AsyncioSelectorReactorTests.newLoop.<locals>.cleanUpQ   s    LLN<(!.1r    )r   r   new_event_loop
addCleanup)r&   r+   r6   r4   r5   r   s   && @@@r   newLoop#AsyncioSelectorReactorTests.newLoopH   s@    
 &'.0&&(		2 
	2
 r    zLdefault event loop: {}
is not of type SelectorEventLoop on Python {}.{} ({})c                <    \        4       pV P                  V4       R# )z
L{AsyncioSelectorReactor} wraps the global policy's event loop
by default.  This ensures that L{asyncio.Future}s and
coroutines created by library code that uses
L{asyncio.get_event_loop} are bound to the same loop.
N)r   r'   r&   r   s   & r   -test_defaultSelectorEventLoopFromGlobalPolicyIAsyncioSelectorReactorTests.test_defaultSelectorEventLoopFromGlobalPolicyY   s    " )*009r    c                    V P                  \        4       4      p\        V4      p\        V4       V P	                  V4       R# )z
If we use the L{asyncio.DefaultLoopPolicy} to create a new event loop,
and then pass that event loop to a new L{AsyncioSelectorReactor},
this reactor should work properly with L{asyncio.Future}.
N)r:   r   r   r	   r'   r&   
event_loopr   s   &  r   3test_newSelectorEventLoopFromDefaultEventLoopPolicyOAsyncioSelectorReactorTests.test_newSelectorEventLoopFromDefaultEventLoopPolicym   s6      \\"8":;
(4z"009r    zHdefault event loop: {}
is of type SelectorEventLoop on Python {}.{} ({})c                :    V P                  \        \        4       R# )a9  
On Windows Python 3.5 to 3.7, L{get_event_loop()} returns a
L{WindowsSelectorEventLoop} by default.
On Windows Python 3.8+, L{get_event_loop()} returns a
L{WindowsProactorEventLoop} by default.
L{AsyncioSelectorReactor} should raise a
L{TypeError} if the default event loop is not a
L{WindowsSelectorEventLoop}.
N)assertRaises	TypeErrorr   r&   s   &r   1test_defaultNotASelectorEventLoopFromGlobalPolicyMAsyncioSelectorReactorTests.test_defaultNotASelectorEventLoopFromGlobalPolicy   s    ( 	)%;<r    z&WindowsProactorEventLoop not availablec                n    V P                  \        4       4      pV P                  \        \        V4       R# )zp
L{AsyncioSelectorReactor} will raise a L{TypeError}
if instantiated with a L{asyncio.WindowsProactorEventLoop}
N)r:   r   rF   rG   r   )r&   rB   s   & r   test_WindowsProactorEventLoop9AsyncioSelectorReactorTests.test_WindowsProactorEventLoop   s)     \\"@"BC
)%;ZHr    z(WindowsSelectorEventLoop only on Windowsc                    V P                  \        4       4      p\        V4      p\        V4       V P	                  V4       R# )zB
L{WindowsSelectorEventLoop} works with L{AsyncioSelectorReactor}
N)r:   r   r   r	   r'   rA   s   &  r   test_WindowsSelectorEventLoop9AsyncioSelectorReactorTests.test_WindowsSelectorEventLoop   s6     \\"@"BC
(4z"009r    z.WindowsProactorEventLoopPolicy only on Windowsc                    \        \        4       4       V P                  R 4       V P                  \        4      ;_uu_ 4        \        4        RRR4       R#   + '       g   i     R# ; i)zn
L{AsyncioSelectorReactor} will raise a L{TypeError}
if L{asyncio.WindowsProactorEventLoopPolicy} is default.
c                      \        R 4      # r   r
    r    r   <lambda>QAsyncioSelectorReactorTests.test_WindowsProactorEventLoopPolicy.<locals>.<lambda>   
     5d ;r    N)r
   r   r9   rF   rG   r   rH   s   &r   #test_WindowsProactorEventLoopPolicy?AsyncioSelectorReactorTests.test_WindowsProactorEventLoopPolicy   sC     	<>?;<y))"$ *)))s   AA)	z.WindowsSelectorEventLoopPolicy only on Windowsc                    \        \        4       4       V P                  R 4       \        4       pV P	                  V4       R# )za
L{AsyncioSelectorReactor} will work if
if L{asyncio.WindowsSelectorEventLoopPolicy} is default.
c                      \        R 4      # r   rS   rT   r    r   rU   QAsyncioSelectorReactorTests.test_WindowsSelectorEventLoopPolicy.<locals>.<lambda>   rW   r    N)r
   r   r9   r   r'   r=   s   & r   #test_WindowsSelectorEventLoopPolicy?AsyncioSelectorReactorTests.test_WindowsSelectorEventLoopPolicy   s3     	<>?;<(*009r    c                    \         '       d&   \        \        4       4       V P                  R 4       \	        4       pVP                  4       pV P                  VR4       V P                  VR4       R# )z0L{seconds} should return a plausible epoch time.c                      \        R 4      # r   rS   rT   r    r   rU   :AsyncioSelectorReactorTests.test_seconds.<locals>.<lambda>   
    $9$$?r    i ^l    #G4 N)!hasWindowsSelectorEventLoopPolicyr
   r   r9   r   secondsassertGreater
assertLess)r&   r   r   s   &  r   test_seconds(AsyncioSelectorReactorTests.test_seconds   sW    ,,!"@"BCOO?@(*" 	6:. 	
+r    c                  aa \         '       d&   \        \        4       4       V P                  R 4       \	        4       oR.oVV3R lpSP                  4       pSP                  ^ V4      pVP                  R4       SP                  ^SP                  4       SP                  4        V P                  S^ ,          4       V P                  S^ ,          V,
          R4       R# )zA
L{DelayedCall.reset()} properly reschedules timer to later time
c                      \        R 4      # r   rS   rT   r    r   rU   JAsyncioSelectorReactorTests.test_delayedCallResetToLater.<locals>.<lambda>   rb   r    Nc                  .   < S P                  4       S^ &   R#     Nrd   r   timer_called_ats   r   on_timerJAsyncioSelectorReactorTests.test_delayedCallResetToLater.<locals>.on_timer       !(!2OAr          ?皙?)rc   r
   r   r9   r   rd   	callLaterresetr   runassertIsNotNonere   )r&   rr   
start_timedcr   rq   s   &   @@r   test_delayedCallResetToLater8AsyncioSelectorReactorTests.test_delayedCallResetToLater   s     -,!"@"BCOO?@(*&	3 __&
q(+
!W\\*_Q/0?1-
:C@r    c                  aa \         '       d   \        \        4       4       \        4       oR.oVV3R lpSP	                  4       pSP                  RV4      pVP                  ^ 4       SP                  ^SP                  4       ^ RIp^ RI	H
p VP                  4       pV! V4      ;_uu_ 4        SP                  4        RRR4       V P                  VP                  4       R4       V P                  S^ ,          4       V P!                  S^ ,          V,
          R4       \         '       d   \        R4       R# R#   + '       g   i     L; i)zC
L{DelayedCall.reset()} properly reschedules timer to earlier time
Nc                  .   < S P                  4       S^ &   R# rm   ro   rp   s   r   rr   LAsyncioSelectorReactorTests.test_delayedCallResetToEarlier.<locals>.on_timer   rt   r    ru   )redirect_stderr rv   )rc   r
   r   r   rd   rw   rx   r   io
contextlibr   StringIOry   r$   getvaluerz   rf   )	r&   rr   r{   r|   r   r   stderrr   rq   s	   &      @@r   test_delayedCallResetToEarlier:AsyncioSelectorReactorTests.test_delayedCallResetToEarlier   s     -,!"@"BC(*&	3 __&
sH-
!W\\*.V$$KKM % 	*B/_Q/0*Z7=,,!$' - %$s   /D;;E	c                   \         '       d   \        \        4       4       \        P                  ! 4       p\        P
                  ! 4         \        \        P                  ! 4       4      pRp\        4       p\        V4       F  pVP                  ^ R 4       K  	  VP                  4        \        \        P                  ! 4       4      pV P                  Wb,
          V,          ^4       V'       d   \        P                  ! 4        \         '       d   \        R4       R# R#   T'       d   \        P                  ! 4        i i ; i)zG
L{AsyncioSelectorReactor.callLater()} doesn't leave cyclic references
i  c                      R # r   rT   rT   r    r   rU   OAsyncioSelectorReactorTests.test_noCycleReferencesInCallLater.<locals>.<lambda>  s    Tr    N)rc   r
   r   gc	isenableddisablelenget_objectsr   rangerw   runUntilCurrentrf   enable)r&   gc_was_enabledobjects_beforetimer_countr   _objects_afters   &      r   !test_noCycleReferencesInCallLater=AsyncioSelectorReactorTests.test_noCycleReferencesInCallLater  s     -,!"@"BC


	 !12NK,.G;'!!!\2 (##% 01MOO];{JAN		,,!$' - 		 s   BD  D?rT   N)!__name__
__module____qualname____firstlineno____doc__r'   r:   r   _defaultEventLoopIsSelectorr-   type_defaultEventLoopsysversion_infomajorminorr   getTyper>   rC   rI   !hasWindowsProactorEventLoopPolicyrL   rc   rO   rX   r]   rg   r}   r   r   __static_attributes____classdictcell__)r.   s   @r   r   r   0   s    )& " ''	%v"#""""	 
	:	: ''	%v"#""""	 
		:		: #	%v"#""""	 
	
=	
= --/WII --2:	: --8%	% --8:	:,A0(>( (r    r   )#r   r   r   asyncior   r   r   r   r   r   r   r	   r
   unittestr   twisted.internet.asyncioreactorr   twisted.python.runtimer   twisted.trial.unittestr   reactormixinsr   r   rc   
startswithr   r   ImportErrorr8   r   
isinstancer   r3   r   rT   r    r   <module>r      s    
 

 
 
  B + 6 )$) !$) !
	
||w''	

 -1),0)
 +,;;= ():<MN     x(.2E x(  		s    B- %B- -B76B7