+
    Dfj9                        R t ^ RIt^ RIHt ^ RIHt ^ RIHt ^ RIH	t	 ^ RIH
t
 ^ RIHt ^ RIHtHtHt ^ R	IHt ^ R
IHt ^ RIHtHtHt ^ RIHt ^ RIHt ^ RIHtHt  ^ RI t!]!t ]
! R4      t#]	! ]]4       ! R R4      4       t$ ! R R]4      t%R t& ! R R4      t' ! R R]']4      t( ! R R]']4      t) ! R R]4      t*]! ] '       * R4       ! R R]4      4       t+R#   ]" d    Rt  Li ; i) z%
Tests for L{twisted.internet.base}.
N)Queue)Callable)skipIf)implementer)	ParamSpec)FirstOneWins)DelayedCallReactorBaseThreadedResolver)Deferred)DNSLookupError)IReactorThreadsIReactorTimeIResolverSimple)Clock)
ThreadPool)SkipTestTestCase_Pc                   x   a  ] tR t^$t o RtR tV 3R lR ltR tR tR t	V 3R lR	 lt
V 3R
 lR ltR tRtV tR# )FakeReactorz`
A fake reactor implementation which just supports enough reactor APIs for
L{ThreadedResolver}.
c                   a  \        4       S n        S P                  P                  S n        \        4       S n        S P                  P                  4        V 3R  lS n        \        4       S n        R# )c                     < S P                   # N)_threadpoolselfs   A/usr/lib/python3/dist-packages/twisted/internet/test/test_base.py<lambda>&FakeReactor.__init__.<locals>.<lambda>1   s    T%5%5    N)	r   _clock	callLaterr   r   startgetThreadPoolr   _threadCallsr   s   fr   __init__FakeReactor.__init__+   sK    g..%< 5!Gr    c                n   < V ^8  d   QhRS[ S[S[3,          RS[P                  RS[P                  RR/#    callableargskwargsreturnNr   r   objectr,   r-   )format__classdict__s   "r   __annotate__FakeReactor.__annotate__5   s>     8 8 V,857WW8HJ		8	8r    c                @    V P                   P                  WV34       R # r   )r%   putr   r+   r,   r-   s   &&*,r   callFromThreadFakeReactor.callFromThread5   s     	xv67r    c                P    V P                   P                  4       w  rpV! V/ VB  R # r   )r%   get)r   fr,   r-   s   &   r   _runThreadCallsFakeReactor._runThreadCalls:   s'    ++//1	46r    c                :    V P                   P                  4        R # r   )r   stopr   s   &r   _stopFakeReactor._stop>   s    r    c                    R # r    r   s   &r   getDelayedCallsFakeReactor.getDelayedCallsA       r    c                    < V ^8  d   QhRS[ /# )r*   r.   )float)r1   r2   s   "r   r3   r4   E   s       r    c                    R # r   rD   r   s   &r   secondsFakeReactor.secondsE   rG   r    c                n   < V ^8  d   QhRS[ S[S[3,          RS[P                  RS[P                  RR/# r)   r/   )r1   r2   s   "r   r3   r4   I   s>       V,57WWHJ			r    c                    R # r   rD   r7   s   &&*,r   callInThreadFakeReactor.callInThreadI   s     	r    c                    R # r   rD   )r   sizes   &&r   suggestThreadPoolSize!FakeReactor.suggestThreadPoolSizeO   rG   r    )r!   r%   r   r"   r$   N)__name__
__module____qualname____firstlineno____doc__r&   r8   r=   rA   rE   rK   rO   rS   __static_attributes____classdictcell__r2   s   @r   r   r   $   sF     
$8 8
    r    r   c                   <   a  ] tR t^Tt o RtR tR tR tR tRt	V t
R# )ThreadedResolverTestsz 
Tests for L{ThreadedResolver}.
c                  aa	 RoRp^p\        4       pV P                  VP                  4       . o	. pVV	3R lpV P                  \        RV4       \        V4      pVP                  W34      pVP                  VP                  4       VP                  4        V P                  S	V.4       V P                  VS.4       VP                  P                  V^,           4       V P                  VP                  P                  . 4       R# )z
L{ThreadedResolver.getHostByName} returns a L{Deferred} which fires
with the value returned by the call to L{socket.gethostbyname} in the
threadpool of the reactor passed to L{ThreadedResolver.__init__}.
z	10.0.0.17zfoo.bar.example.comc                 *   < SP                  V 4       S# r   )append)nameiplookedUps   &r   fakeGetHostByName=ThreadedResolverTests.test_success.<locals>.fakeGetHostByNamei   s    OOD!Ir    gethostbynameN)r   
addCleanuprA   patchsocketr
   getHostByNameaddCallbackra   r=   assertEqualr!   advancecalls)
r   rb   timeoutreactor
resolvedTore   resolverdrc   rd   s
   &       @@r   test_success"ThreadedResolverTests.test_successY   s     $-&
	 	

6?,=>#G,""44	j''(!D6*bT* 	w{+--r2r    c                   ^p\        4       pV P                  VP                  4       R pV P                  \        RV4       . p\        V4      pVP                  RV34      pV P                  V\        4       VP                  VP                  4       VP                  4        V P                  \        V4      ^4       VP                  P                  V^,           4       V P                  VP                  P                   . 4       R# )z
L{ThreadedResolver.getHostByName} returns a L{Deferred} which fires a
L{Failure} if the call to L{socket.gethostbyname} raises an exception.
c                     \        R 4      h)zENOBUFS (this is a funny joke))OSError)rb   s   &r   re   =ThreadedResolverTests.test_failure.<locals>.fakeGetHostByName   s    :;;r    rg   	some.nameN)r   rh   rA   ri   rj   r
   rk   assertFailurer   rl   ra   r=   rm   lenr!   rn   ro   )r   rp   rq   re   
failedWithrs   rt   s   &      r   test_failure"ThreadedResolverTests.test_failure|   s    
 -&	< 	

6?,=>
#G,"";
;1n-	j''(!Z!, 	w{+--r2r    c                N  a ^
p\        4       pV P                  VP                  4       \        4       oV3R lpV P	                  \
        RV4       . p\        V4      pVP                  RV34      pV P                  V\        4       VP                  VP                  4       VP                  P                  V^,
          4       V P                  V. 4       VP                  P                  ^4       V P                  \        V4      ^4       SP!                  \#        R4      4       R# )z
If L{socket.gethostbyname} does not complete before the specified
timeout elapsed, the L{Deferred} returned by
L{ThreadedResolver.getHostByName} fails with L{DNSLookupError}.
c                 $   < SP                  4       hr   )r;   )rb   results   &r   re   =ThreadedResolverTests.test_timeout.<locals>.fakeGetHostByName   s    **,r    rg   r{   zThe I/O was errorfulN)r   rh   rA   r   ri   rj   r
   rk   r|   r   rl   ra   r!   rn   rm   r}   r6   IOError)r   rp   rq   re   r~   rs   rt   r   s   &      @r   test_timeout"ThreadedResolverTests.test_timeout   s     -&	 	

6?,=>
#G,"";
;1n-	j''(w{+R(q!Z!, 	

7123r    c                ~  a . o\        \        4       ! V3R lR4      4       p ! R R\        4      pV! 4       pV! 4       pVP                  V4       \	        \        4       4      pVP                  P                  VR4       VP                  P                  VR4       VP                  P                  VR4       VP                  P                  VR4       VP                  P                  VR4       V P                  \        S4      ^4       V P                  \        \        \        S4      4      \        .^,          4       V P                  RS^ ,          4       V P                  RS^,          4       V P                  R	S^,          4       V P                  R
S^,          4       V P                  RS^,          4       R# )zU
L{ThreadedResolver.getHostByName} is passed L{str}, encoded using IDNA
if required.
c                   2   <a  ] tR t^t o RV3R lltRtV tR# )AThreadedResolverTests.test_resolverGivenStr.<locals>.FakeResolverc                :   < SP                  V4       \        4       # r   )ra   r   )r   rb   timeoutsro   s   &&&r   rk   OThreadedResolverTests.test_resolverGivenStr.<locals>.FakeResolver.getHostByName   s    T"z!r    rD   N)rD   )rU   rV   rW   rX   rk   rZ   r[   )r2   ro   s   @r   FakeResolverr      s     " "r    r   c                   &   a  ] tR t^t o R tRtV tR# )FThreadedResolverTests.test_resolverGivenStr.<locals>.JustEnoughReactorc                    R # r   rD   r   s   &r   installWakerSThreadedResolverTests.test_resolverGivenStr.<locals>.JustEnoughReactor.installWaker   s    r    rD   N)rU   rV   rW   rX   r   rZ   r[   r\   s   @r   JustEnoughReactorr      s      r    r   zexample.exampleu   vääntynyt.exampleu   рф.examplezxn----7sbb4ac0ad0be6cf.xn--p1aizxn--vntynyt-5waa.examplezxn--p1ai.exampleN)r   r   r	   installResolverr   r   nameResolverresolveHostNamerm   r}   listmaptypestr)r   r   r   fakerq   recro   s   &     @r   test_resolverGivenStr+ThreadedResolverTests.test_resolverGivenStr   so   
 	_	%	" 	" 
&	"
	 	 ~#%%8:&,,S2CD,,S2CD,,S2KL,,S2HI,,S2STUQ'c$./#;*E!H5*E!H53U1X>+U1X6:E!HEr    rD   N)rU   rV   rW   rX   rY   ru   r   r   r   rZ   r[   r\   s   @r   r^   r^   T   s'     !3F3:4B!F !Fr    r^   c                     R# )z0
Function used by L{DelayedCallTests.test_str}.
NrD   rD   r    r   nothingr          r    c                   `   a  ] tR t^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# )DelayedCallMixin
L{DelayedCall}
c           	     *    R p\        VR R/ W"R4      # )z
Get a L{DelayedCall} instance at a given C{time}.

@param time: The absolute time at which the returned L{DelayedCall}
    will be scheduled.
c                     R # r   rD   )calls   &r   noop0DelayedCallMixin._getDelayedCallAt.<locals>.noop   s    r    c                      R # r   rD   rD   r    r   r   4DelayedCallMixin._getDelayedCallAt.<locals>.<lambda>   s    r    NrD   )r   )r   timer   s   && r   _getDelayedCallAt"DelayedCallMixin._getDelayedCallAt   s    	 4r2t4HHr    c                ^    V P                  ^ 4      V n        V P                  ^4      V n        R# )zJ
Create two L{DelayedCall} instanced scheduled to run at different
times.
N)r   zerooner   s   &r   setUpDelayedCallMixin.setUp   s(    
 **1-	))!,r    c           	         \        ^\        RR^/RRR 4      pV P                  \        V4      R\	        V4      3,          4       R# )
The string representation of a L{DelayedCall} instance, as returned by
L{str}, includes the unsigned id of the instance, as well as its state,
the function to be called, and the function arguments.
ANc                      R # g      ?rD   rD   r    r   r   +DelayedCallMixin.test_str.<locals>.<lambda>      #r    z?<DelayedCall 0x%x [10.5s] called=0 cancelled=0 nothing(3, A=5)>   )r   r   rm   r   idr   dcs   & r   test_strDelayedCallMixin.test_str   sD     WdS!HdD+NGM"vi	
r    c           	     ~    \        ^\        RR^	/RRR 4      pV P                  \        V4      \	        V4      4       R# )zy
The string representation of a L{DelayedCall} instance, as returned by
{repr}, is identical to that returned by L{str}.
r   Nc                      R # )g?rD   rD   r    r   r   ,DelayedCallMixin.test_repr.<locals>.<lambda>  r   r    )   )r   r   rm   r   reprr   s   & r   	test_reprDelayedCallMixin.test_repr  s6    
 WdS!HdD+NR$r(+r    c                    V P                   V P                  r!V P                  W8  4       V P                  W!8  4       V P                  W8  4       V P                  W"8  4       R# )zz
For two instances of L{DelayedCall} C{a} and C{b}, C{a < b} is true
if and only if C{a} is scheduled to run before C{b}.
Nr   r   
assertTrueassertFalser   r   r   s   &  r   test_ltDelayedCallMixin.test_lt  sQ    
 IItxxc
#$%#r    c                    V P                   V P                  r!V P                  W8*  4       V P                  W!8*  4       V P                  W8*  4       V P                  W"8*  4       R# )z
For two instances of L{DelayedCall} C{a} and C{b}, C{a <= b} is true
if and only if C{a} is scheduled to run before C{b} or at the same
time as C{b}.
Nr   r   s   &  r   test_leDelayedCallMixin.test_le  sM     IItxxc$%%
#r    c                    V P                   V P                  r!V P                  W!8  4       V P                  W8  4       V P                  W8  4       V P                  W"8  4       R# )zy
For two instances of L{DelayedCall} C{a} and C{b}, C{a > b} is true
if and only if C{a} is scheduled to run after C{b}.
Nr   r   s   &  r   test_gtDelayedCallMixin.test_gt*  sQ    
 IItxxc
#$%#r    c                    V P                   V P                  r!V P                  W!8  4       V P                  W8  4       V P                  W8  4       V P                  W"8  4       R# )z
For two instances of L{DelayedCall} C{a} and C{b}, C{a > b} is true
if and only if C{a} is scheduled to run after C{b} or at the same
time as C{b}.
Nr   r   s   &  r   test_geDelayedCallMixin.test_ge5  sM     IItxxc$%%
#r    c                    V P                  V P                  V P                  8H  4       V P                  V P                  V P                  8H  4       V P                  V P                  V P                  8H  4       R# )z4
A L{DelayedCall} instance is only equal to itself.
N)r   r   r   r   r   s   &r   test_eqDelayedCallMixin.test_eqA  sQ     	dhh./		TYY./DHH,-r    c                    V P                  V P                  V P                  8g  4       V P                  V P                  V P                  8g  4       V P                  V P                  V P                  8g  4       R# )z=
A L{DelayedCall} instance is not equal to any other object.
N)r   r   r   r   r   s   &r   test_neDelayedCallMixin.test_neK  sS     			TXX-.dii/0TXX-.r    )r   r   N)rU   rV   rW   rX   rY   r   r   r   r   r   r   r   r   r   r   rZ   r[   r\   s   @r   r   r      sB     I-
,	$
$	$
$./ /r    r   c                   6   a  ] tR tRt o RtR tR tR tRtV t	R# )DelayedCallNoDebugTestsiV  r   c                ^    V P                  \        RR4       \        P                  V 4       R# )z
Turn debug off.
debugFNri   r   r   r   r   s   &r   r   DelayedCallNoDebugTests.setUp[  s"     	

;/t$r    c           	         \        ^\        RR^/RRR 4      pRP                  \        V4      4      pV P	                  \        V4      V4       R# )r   r   Nc                      R # r   rD   rD   r    r   r   2DelayedCallNoDebugTests.test_str.<locals>.<lambda>h  r   r    zA<DelayedCall 0x{:x} [10.5s] called=0 cancelled=0 nothing(3, A=5)>r   )r   r   r1   r   rm   r   )r   r   expecteds   &  r   r    DelayedCallNoDebugTests.test_strb  sK     WdS!HdD+N%vbf~ 	 	R(+r    c           	         \        ^R R/ \        \        R 4      p^Vn        V P                  R\	        V4      4       R# )z
If L{DelayedCall.debug} changes from C{0} to C{1} between
L{DelayeCall.__init__} and L{DelayedCall.__repr__} then
L{DelayedCall.__repr__} returns a string that does not include the
creator stack.
c                      R # r   rD   rD   r    r   r   <DelayedCallNoDebugTests.test_switchToDebug.<locals>.<lambda>v      Dr    c                      ^# r*   rD   rD   r    r   r   r   v      Ar    traceback at creationNrD   )r   r   r   assertNotInr   r   s   & r   test_switchToDebug*DelayedCallNoDebugTests.test_switchToDebugo  s6     L"b'7IN0$r(;r    rD   N)
rU   rV   rW   rX   rY   r   r   r   rZ   r[   r\   s   @r   r   r   V  s     %,	< 	<r    r   c                   6   a  ] tR tRt o RtR tR tR tRtV t	R# )DelayedCallDebugTestsi{  r   c                ^    V P                  \        RR4       \        P                  V 4       R# )z
Turn debug on.
r   TNr   r   s   &r   r   DelayedCallDebugTests.setUp  s"     	

;.t$r    c           	         \        ^\        RR^/RRR 4      pRP                  \        V4      4      pV P	                  \        V4      V4       R# )r   r   Nc                      R # r   rD   rD   r    r   r   0DelayedCallDebugTests.test_str.<locals>.<lambda>  r   r    z\<DelayedCall 0x{:x} \[10.5s\] called=0 cancelled=0 nothing\(3, A=5\)

traceback at creation:r   )r   r   r1   r   assertRegexr   )r   r   expectedRegexps   &  r   r   DelayedCallDebugTests.test_str  sK     WdS!HdD+N%%+VBrF^ 	
 	R.1r    c           	         \        ^R R/ \        \        R 4      p^ Vn        V P                  R\	        V4      4       R# )z
If L{DelayedCall.debug} changes from C{1} to C{0} between
L{DelayeCall.__init__} and L{DelayedCall.__repr__} then
L{DelayedCall.__repr__} returns a string that includes the creator
stack (we captured it, we might as well display it).
c                      R # r   rD   rD   r    r   r   <DelayedCallDebugTests.test_switchFromDebug.<locals>.<lambda>  r   r    c                      ^# r   rD   rD   r    r   r   r    r   r    r   NrD   )r   r   r   assertInr   r   s   & r   test_switchFromDebug*DelayedCallDebugTests.test_switchFromDebug  s4     L"b'7IN-tBx8r    rD   N)
rU   rV   rW   rX   rY   r   r   r  rZ   r[   r\   s   @r   r   r   {  s     %2	9 	9r    r   c                   *   a  ] tR tRt o RtR tRtV tR# )TestSpySignalCapturingReactori  zU
Subclass of ReactorBase to capture signals delivered to the
reactor for inspection.
c                    R# )z
Required method, unused.
NrD   r   s   &r   r   *TestSpySignalCapturingReactor.installWaker  r   r    rD   N)rU   rV   rW   rX   rY   r   rZ   r[   r\   s   @r   r  r    s     
 r    r  zsignal module not availablec                   <   a  ] tR tRt o RtR tR tR tR tRt	V t
R# )	ReactorBaseSignalTestsi  z=
Tests to exercise ReactorBase's signal exit reporting path.
c                R    \        4       pV P                  RVP                  4       R# )z9
The default value of the _exitSignal attribute is None.
N)r  assertIs_exitSignalr   rq   s   & r   test_exitSignalDefaultsToNone4ReactorBaseSignalTests.test_exitSignalDefaultsToNone  s      01dG//0r    c                    \        4       pVP                  \        P                  R4       V P	                  \        P                  VP
                  4       R# )zV
ReactorBase's SIGINT handler saves the value of SIGINT to the
_exitSignal attribute.
N)r  sigIntsignalSIGINTassertEqualsr  r  s   & r   test_captureSIGINT)ReactorBaseSignalTests.test_captureSIGINT  s8    
 01v}}d+&--)<)<=r    c                    \        4       pVP                  \        P                  R4       V P	                  \        P                  VP
                  4       R# )zX
ReactorBase's SIGTERM handler saves the value of SIGTERM to the
_exitSignal attribute.
N)r  sigTermr  SIGTERMr  r  r  s   & r   test_captureSIGTERM*ReactorBaseSignalTests.test_captureSIGTERM  s8    
 01-&..'*=*=>r    c                    \        \        R4      '       g   \        R4      h\        4       pVP	                  \        P
                  R4       V P                  \        P
                  VP                  4       R# )zZ
ReactorBase's SIGBREAK handler saves the value of SIGBREAK to the
_exitSignal attribute.
SIGBREAKz$signal module does not have SIGBREAKN)hasattrr  r   r  sigBreakr   r  r  r  s   & r   test_captureSIGBREAK+ReactorBaseSignalTests.test_captureSIGBREAK  sS    
 vz**ABB/1$/&//7+>+>?r    rD   N)rU   rV   rW   rX   rY   r  r  r  r#  rZ   r[   r\   s   @r   r  r    s%     1>?
@ 
@r    r  ),rY   rj   queuer   typingr   unittestr   zope.interfacer   r   twisted.internet._resolverr   twisted.internet.baser   r	   r
   twisted.internet.deferr   twisted.internet.errorr   twisted.internet.interfacesr   r   r   twisted.internet.taskr   twisted.python.threadpoolr   twisted.trial.unittestr   r   r  _signalImportErrorr   r   r^   r   r   r   r   r  r  rD   r    r   <module>r3     s       &  3 L L + 1 V V ' 0 5 Ft_ \?+, , ,,^GFH GFTo/ o/d"<. "<J#9,h #9L
K 
 F
12)@X )@ 3)@g  Fs    C 	C)(C)