+
    Dfj=.                     b   R t ^ RIt^ RIHt ^ RIHt ^ RIHtHt ^ RI	H
t
 ^ RIHt ^ RIHt Rt ^ RIHt ^ R	IHt ^ RIHt ^ RIH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#   ] d    R
t Lqi ; i)z>
Tests for L{twisted.internet.posixbase} and supporting code.
N)DeferredIReadDescriptor)PosixReactorBase_Waker)ServerFactory)platform)TestCase)unix)ClientProtoz)Platform does not support AF_UNIX sockets)reactor)Portc                   B   a a ] tR t^t oRtV 3R ltV 3R ltRtVtV ;t	# )WarningCheckerTestCasez_
A test case that will make sure that no warnings are left unchecked at the end of a test run.
c                   < \         SV `  4        \        P                  P	                  R R4      P                  4       R8X  d0   \        P                  ! 4       '       d   V P                  4        R# R# R# )CI trueN)	supersetUposenvirongetlowerr   	isWindowsflushWarnings)self	__class__s   &F/usr/lib/python3/dist-packages/twisted/internet/test/test_posixbase.pyr   WarningCheckerTestCase.setUp    sQ     ::>>$#))+v5(:L:L:N:N  ;O5    c                0  <  \         SV `  4        V P                  4       p\        P                  P                  R R4      P                  4       R8X  d   \        P                  ! 4       '       d   R# V P                  \        V4      ^ RV 24       R#   T P                  4       p\        P                  P                  R R4      P                  4       R8X  d    \        P                  ! 4       '       d     R# T P                  \        T4      ^ RT 24       i ; i)r   r   r   Nz'Warnings found at the end of the test:
)r   tearDownr   r   r   r   r   r   r   assertEquallen)r   warningsr   s   & r   r"   WarningCheckerTestCase.tearDown+   s    	G))+Hzz~~dB'--/69h>P>P>R>R Hq$LXJ"W ))+Hzz~~dB'--/69h>P>P>R>R Hq$LXJ"Ws   B AD1D5 D )
__name__
__module____qualname____firstlineno____doc__r   r"   __static_attributes____classdictcell____classcell__)r   __classdict__s   @@r   r   r      s     	! r    r   c                   >   a  ] tR t^=t o R tR tR tR tR tRt	V t
R# )TrivialReactorc                N    / V n         / V n        \        P                  ! V 4       R # N)_readers_writersr   __init__r   s   &r   r7   TrivialReactor.__init__>   s    !!$'r    c                $    R V P                   V&   R# TNr5   r   readers   &&r   	addReaderTrivialReactor.addReaderC        $fr    c                     V P                   V R # r4   r<   r=   s   &&r   removeReaderTrivialReactor.removeReaderF       MM&!r    c                $    R V P                   V&   R# r;   r6   r   writers   &&r   	addWriterTrivialReactor.addWriterI   rA   r    c                     V P                   V R # r4   rG   rH   s   &&r   removeWriterTrivialReactor.removeWriterL   rE   r    )r5   r6   N)r(   r)   r*   r+   r7   r?   rC   rJ   rM   r-   r.   r0   s   @r   r2   r2   =   s#     (
%"%" "r    r2   c                   <   a  ] tR t^Pt o RtR tR tR tR tRt	V t
R# )PosixReactorBaseTestsz 
Tests for L{PosixReactorBase}.
c                    V P                  VP                  \        4       V P                  VP                  VP                  4       V P                  VP                  VP
                  4       R # r4   )assertIsInstancewakerr   assertIn_internalReadersr5   r   r   s   &&r   _checkWaker!PosixReactorBaseTests._checkWakerU   sF    gmmV4gmmW%=%=>gmmW%5%56r    c                <    \        4       pV P                  V4       R# )zg
When L{PosixReactorBase} is instantiated, it creates a waker and adds
it to its internal readers set.
N)r2   rX   rW   s   & r   test_wakerIsInternalReader0PosixReactorBaseTests.test_wakerIsInternalReaderZ   s    
 !"!r    c                d   \        4       p\        4       pVP                  P                  V4       VP                  ! V4       VP
                  ! VP                  VP                  4       V P                  V4       V P                  W!P                  4       V P                  W!P                  4       R# )zs
Any L{IReadDescriptor}s in L{PosixReactorBase._internalReaders} are
left alone by L{PosixReactorBase._removeAll}.
N)
r2   objectrV   addr?   
_removeAllr5   r6   rX   rU   )r   r   extras   &  r   "test_removeAllSkipsInternalReaders8PosixReactorBaseTests.test_removeAllSkipsInternalReadersb   s    
 !"  $$U+% 7++W-=-=>!e556e--.r    c                |   \        4       p\        4       p\        4       pVP                  ! V4       VP                  ! V4       VP                  ! VP
                  VP                  4      pV P                  \        V4      W#04       V P                  W!P
                  4       V P                  W1P                  4       R# )zn
L{PosixReactorBase._removeAll} returns a list of removed
L{IReadDescriptor} and L{IWriteDescriptor} objects.
N)
r2   r^   r?   rJ   r`   r5   r6   r#   setassertNotIn)r   r   r>   rI   removeds   &    r   'test_removeAllReturnsRemovedDescriptors=PosixReactorBaseTests.test_removeAllReturnsRemovedDescriptorsp   s    
 !"&!&!$$W%5%5w7G7GHW'78!1!12!1!12r    r'   N)r(   r)   r*   r+   r,   rX   r[   rb   rh   r-   r.   rO   s   @r   rQ   rQ   P   s#     7
"/3 3r    rQ   c                   L   a  ] tR t^t o Rt]! ]]4      '       g   RtR t	Rt
V tR# )TCPPortTestsz)
Tests for L{twisted.internet.tcp.Port}.
zNon-posixbase reactorc                    \        R\        4       4      pRVn        R Vn        V P	                  VP                  4       \        4      # )zk
L{Port.stopListening} returns a L{Deferred} which errbacks if
L{Port.connectionLost} raises an exception.
i90  Tc                     ^^ ,          # )   r'   )reasons   &r   <lambda>8TCPPortTests.test_connectionLostFailed.<locals>.<lambda>   s    Q!Vr    )r   r   	connectedconnectionLostassertFailurestopListeningZeroDivisionError)r   ports   & r   test_connectionLostFailed&TCPPortTests.test_connectionLostFailed   s>    
 E=?+3!!$"4"4"68IJJr    r'   N)r(   r)   r*   r+   r,   
isinstancer   r   skiprx   r-   r.   rO   s   @r   rk   rk      s+      g/00&K Kr    rk   c                   `   a  ] tR t^t o RtR tV 3R lR ltV 3R lR ltR tR t	R	 t
R
tV tR# )TimeoutReportReactorz
A reactor which is just barely runnable and which cannot monitor any
readers or writers, and which fires a L{Deferred} with the timeout
passed to its C{doIteration} method as soon as that method is invoked.
c                ^    \         P                  ! V 4       \        4       V n        ^dV n        R# )d   N)r   r7   r   iterationTimeoutnowr8   s   &r   r7   TimeoutReportReactor.__init__   s!    !!$' (
r    c                $   < V ^8  d   QhRS[ RR/#    r>   returnNr   )formatr0   s   "r   __annotate__!TimeoutReportReactor.__annotate__   s       D r    c                    R# )z
Ignore the reader.  This is necessary because the waker will be
added.  However, we won't actually monitor it for any events.
Nr'   r=   s   &&r   r?   TimeoutReportReactor.addReader       r    c                $   < V ^8  d   QhRS[ RR/# r   r   )r   r0   s   "r   r   r      s      ? t r    c                    R# )z
See L{addReader}.
Nr'   r=   s   &&r   rC   !TimeoutReportReactor.removeReader   r   r    c                    . # )z
There are no readers or writers, so there is nothing to remove.
This will be called when the reactor stops, though, so it must be
implemented.
r'   r8   s   &r   	removeAllTimeoutReportReactor.removeAll   s	     	r    c                    V P                   # )z`
Override the real clock with a deterministic one that can be easily
controlled in a unit test.
)r   r8   s   &r   secondsTimeoutReportReactor.seconds   s    
 xxr    c                Z    V P                   pVe   R V n         VP                  V4       R # R # r4   )r   callback)r   timeoutds   && r   doIteration TimeoutReportReactor.doIteration   s+    !!=$(D!JJw r    )r   r   N)r(   r)   r*   r+   r,   r7   r?   rC   r   r   r   r-   r.   rO   s   @r   r}   r}      s7     
  
   r    r}   c                   T   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V tR# )IterationTimeoutTestsz
Tests for the timeout argument L{PosixReactorBase.run} calls
L{PosixReactorBase.doIteration} with in the presence of various delayed
calls.
c                   a . pSP                   P                  VP                  4       SP                   P                  V3R  l4       SP                  ! 4        V^ ,          # )c                 &   < SP                   ! 4       # r4   )stop)ignoredr   s   &r   rp   >IterationTimeoutTests._checkIterationTimeout.<locals>.<lambda>   s    W\\^r    )r   addCallbackappendrunr   r   r   s   &f r   _checkIterationTimeout,IterationTimeoutTests._checkIterationTimeout   sH      ,,W^^<  ,,-KLqzr    c                ^    \        4       pV P                  V4      pV P                  V4       R# )zT
If there are no delayed calls, C{doIteration} is called with a
timeout of L{None}.
N)r}   r   assertIsNoner   s   &  r   test_noCalls"IterationTimeoutTests.test_noCalls   s*    
 '(--g6'"r    c                    \        4       pVP                  ! ^dR 4       V P                  V4      pV P                  V^d4       R# )z
If there is a delayed call, C{doIteration} is called with a timeout
which is the difference between the current time and the time at
which that call is to run.
c                      R # r4   r'   r'   r    r   rp   8IterationTimeoutTests.test_delayedCall.<locals>.<lambda>       tr    Nr}   	callLaterr   r#   r   s   &  r   test_delayedCall&IterationTimeoutTests.test_delayedCall   s<     '(#|,--g6#&r    c                    \        4       pVP                  ! ^dR 4       V;P                  ^,          un        V P                  V4      pV P	                  V^K4       R# )z
If a delayed call is scheduled and then some time passes, the
timeout passed to C{doIteration} is reduced by the amount of time
which passed.
c                      R # r4   r'   r'   r    r   rp   7IterationTimeoutTests.test_timePasses.<locals>.<lambda>   r   r    N)r}   r   r   r   r#   r   s   &  r   test_timePasses%IterationTimeoutTests.test_timePasses   sJ     '(#|,r--g6"%r    c                    \        4       pVP                  ! ^2R 4       VP                  ! ^
R 4       VP                  ! ^dR 4       V P                  V4      pV P                  V^
4       R# )z
If there are several delayed calls, C{doIteration} is called with a
timeout which is the difference between the current time and the
time at which the earlier of the two calls is to run.
c                      R # r4   r'   r'   r    r   rp   AIterationTimeoutTests.test_multipleDelayedCalls.<locals>.<lambda>       dr    c                      R # r4   r'   r'   r    r   rp   r      r   r    c                      R # r4   r'   r'   r    r   rp   r      r   r    Nr   r   s   &  r   test_multipleDelayedCalls/IterationTimeoutTests.test_multipleDelayedCalls   s\     '("l+"l+#|,--g6"%r    c                    \        4       pVP                  ! ^2R 4      pV;P                  ^,          un        VP                  ^4       V P	                  V4      pV P                  V^4       R# )z
If a delayed call is reset, the timeout passed to C{doIteration} is
based on the interval between the time when reset is called and the
new delay of the call.
c                      R # r4   r'   r'   r    r   rp   =IterationTimeoutTests.test_resetDelayedCall.<locals>.<lambda>      Tr    N)r}   r   r   resetr   r#   r   r   callr   s   &   r   test_resetDelayedCall+IterationTimeoutTests.test_resetDelayedCall   sW     '(  \2r

2--g6"%r    c                    \        4       pVP                  ! ^2R 4      pV;P                  ^
,          un        VP                  ^4       V P	                  V4      pV P                  V^<4       R# )z
If a delayed call is re-delayed, the timeout passed to
C{doIteration} is based on the remaining time before the call would
have been made and the additional amount of time passed to the delay
method.
c                      R # r4   r'   r'   r    r   rp   =IterationTimeoutTests.test_delayDelayedCall.<locals>.<lambda>  r   r    N)r}   r   r   delayr   r#   r   s   &   r   test_delayDelayedCall+IterationTimeoutTests.test_delayDelayedCall  sW     '(  \2r

2--g6"%r    c                    \        4       pVP                  ! ^2R 4      pVP                  4        V P                  V4      pV P	                  V4       R# )zX
If the only delayed call is canceled, L{None} is the timeout passed
to C{doIteration}.
c                      R # r4   r'   r'   r    r   rp   >IterationTimeoutTests.test_cancelDelayedCall.<locals>.<lambda>  r   r    N)r}   r   cancelr   r   r   s   &   r   test_cancelDelayedCall,IterationTimeoutTests.test_cancelDelayedCall  sE    
 '(  \2--g6'"r    r'   N)r(   r)   r*   r+   r,   r   r   r   r   r   r   r   r   r-   r.   rO   s   @r   r   r      s7     #	'
&&&&	# 	#r    r   c                   <   a  ] tR tRt o Rt]e   ]tR tR tRt	V t
R# )ConnectedDatagramPortTestsi"  z'
Test connected datagram UNIX sockets.
Nc                   a  V 3R lp\         P                  ! R\        4       4      pWn        VP	                  R4       R# )zw
L{ConnectedDatagramPort} does not call the deprecated C{loseConnection}
in L{ConnectedDatagramPort.connectionFailed}.
c                 *   < S P                  R4       R# )z\
Dummy C{loseConnection} method. C{loseConnection} is deprecated and
should not get called.
z7loseConnection is deprecated and should not get called.N)failr8   s   r   loseConnection`ConnectedDatagramPortTests.test_connectionFailedDoesntCallLoseConnection.<locals>.loseConnection0  s    
 IIOPr    Ngoodbye)r
   ConnectedDatagramPortr   r   connectionFailed)r   r   rw   s   f  r   -test_connectionFailedDoesntCallLoseConnectionHConnectedDatagramPortTests.test_connectionFailedDoesntCallLoseConnection*  s3    	Q ))$>,i(r    c                   a  RS n         V 3R lp\        P                  ! R\        4       4      pWn        VP                  R4       S P                  S P                   4       R# )z
L{ConnectedDatagramPort} calls L{ConnectedDatagramPort.stopListening}
instead of the deprecated C{loseConnection} in
L{ConnectedDatagramPort.connectionFailed}.
Fc                    < RS n         R# )z 
Dummy C{stopListening} method.
TNcalledr8   s   r   ru   YConnectedDatagramPortTests.test_connectionFailedCallsStopListening.<locals>.stopListeningC  s     DKr    Nr   )r   r
   r   r   ru   r   
assertTrue)r   ru   rw   s   f  r   'test_connectionFailedCallsStopListeningBConnectedDatagramPortTests.test_connectionFailedCallsStopListening;  sK     	 ))$>*i($r    r   )r(   r)   r*   r+   r,   skipSocketsr{   r   r   r-   r.   rO   s   @r   r   r   "  s&      )"% %r    r   c                   &   a  ] tR tRt o R tRtV tR# )
WakerTestsiO  c                    \        4       pV P                  4       pV P                  \        V4      ^ V4       VP	                  R4       V P                  4       pV P                  \        V4      ^ V4       R# )z8
No warnings are generated when constructing the waker.
N)r   r   r#   r$   rs   )r   rT   r%   s   &  r    test_noWakerConstructionWarnings+WakerTests.test_noWakerConstructionWarningsP  sc     %%'X84 	T"%%'X84r    r'   N)r(   r)   r*   r+   r   r-   r.   rO   s   @r   r   r   O  s     5 5r    r   ) r,   r   twisted.internet.deferr   twisted.internet.interfacesr   twisted.internet.posixbaser   r   twisted.internet.protocolr   twisted.python.runtimer   twisted.trial.unittestr	   r   twisted.internetr
   twisted.test.test_unixr   ImportErrorr   twisted.internet.tcpr   r   r2   rQ   rk   r}   r   r   r   r'   r    r   <module>r      s    
 + 7 ? 3 + +>%2 % %X D"% "&-32 -3`K) K&* + * Z_#2 _#D*%!7 *%Z5' 5w	  >=K>s   B" "	B.-B.