+
    Dfj4                     D   R t ^ RIt^ RIt^ RIt^ RIHt ^ RIHt ^ RIH	t	 ^ RI
Ht ^ RIHtHt ^ RIHtHt ^ RIHt ^ R	IHt ^ R
IHtHt ]'       d   ]tM]tR t ! R R]]4      t]	! ]4       ! R R4      4       t]! 4       P?                  ]PA                  4       4       R# )z0
Tests for implementations of L{IReactorFDSet}.
N)TYPE_CHECKING)skipIf)implementer)FileDescriptor)IReactorFDSetIReadDescriptor)EINPROGRESSEWOULDBLOCK)ReactorBuilder)platform)SkipTestSynchronousTestCasec                  >   \         P                   ! 4       p V P                  R4       V P                  ^4        \         P                   ! 4       p VP                  R4        VP	                  R V P                  4       ^,          34       V P                  4       w  r4 T P                  4        Y3#   \         d.   pTP                  ^ ,          \        \        39  d   h  Rp?LYRp?ii ; i  \         d    TP                  4        h i ; i  T P                  4        i ; i)	127.0.0.1FN)r       )socketbindlistensetblockingconnectgetsocknameOSErrorargsr   r	   acceptBaseExceptionclose)serverSocketclienteserveraddrs        B/usr/lib/python3/dist-packages/twisted/internet/test/test_fdset.py
socketpairr"      s    ==?L&'
	u%\-E-E-G-JKL (..0LFD
 	>  66!9[+$>> ?  	LLN	 	sG   D
 C* !(B/ 	C* /C':#C"C* "C''C* *DD
 
Dc                      a  ] tR t^4t o Rt].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*                  ! 4       R4      R 4       tR tRtV tR# )ReactorFDSetTestsBuilderz6
Builder defining tests relating to L{IReactorFDSet}.
c                    \        4       w  rV P                  VP                  4       V P                  VP                  4       W3# )z<
Return the two sockets which make up a new TCP connection.
)r"   
addCleanupr   selfr   r   s   &  r!   _connectedPair'ReactorFDSetTestsBuilder._connectedPair;   s5     $%%~    c                    V P                  4       pV P                  4       w  r#\        V4      pVP                  Vn        WV3# N)buildReactorr)   r   fileno)r(   reactorr   r   fds   &    r!   _simpleSetup%ReactorFDSetTestsBuilder._simpleSetupD   s@    ##%,,.G$MM	F""r+   c                   aa V P                  4       w  oopVV3R lpVSn        SP                  S4       VP                  R4       V P	                  S4       R# )z
C{reactor.addReader()} accepts an L{IReadDescriptor} provider and calls
its C{doRead} method when there may be data available on its C{fileno}.
c                  J   < SP                  S 4       SP                  4        R # r-   )removeReaderstopr1   r0   s   r!   removeAndStop>ReactorFDSetTestsBuilder.test_addReader.<locals>.removeAndStopU         $LLNr+      xN)r2   doRead	addReadersendall
runReactorr(   r   r9   r1   r0   s   &  @@r!   test_addReader'ReactorFDSetTestsBuilder.test_addReaderN   sP    
 #//1V	 "	"t 	 r+   c                  a  S P                  4       w  rpV 3R lpWBn        VP                  V4       VP                  V4       VP	                  R4       VP                  ^ VP
                  ^ VP                  4       S P                  V4       R# )z
L{reactor.removeReader()} accepts an L{IReadDescriptor} provider
previously passed to C{reactor.addReader()} and causes it to no longer
be monitored for input events.
c                  *   < S P                  R 4       R# )doRead should not be calledNfailr(   s   r!   rH   8ReactorFDSetTestsBuilder.test_removeReader.<locals>.faili   s    II34r+   r<   N)r2   r=   r>   r6   r?   	callLaterr7   r@   r(   r0   r1   r   rH   s   f    r!   test_removeReader*ReactorFDSetTestsBuilder.test_removeReadera   sx     #//1V	5 	"R t 	!W..7<<@ r+   c                   aa V P                  4       w  oopVV3R lpVSn        SP                  S4       V P                  S4       R# )z
C{reactor.addWriter()} accepts an L{IWriteDescriptor} provider and
calls its C{doWrite} method when it may be possible to write to its
C{fileno}.
c                  J   < SP                  S 4       SP                  4        R # r-   )removeWriterr7   r8   s   r!   r9   >ReactorFDSetTestsBuilder.test_addWriter.<locals>.removeAndStop   r;   r+   N)r2   doWrite	addWriterr@   rA   s   &  @@r!   test_addWriter'ReactorFDSetTestsBuilder.test_addWritery   sB     #//1V	 #
" r+   c                   V P                  4       p\        VRV,           R,           4      p\        VRV,           4      p\        VRV,           4      pV P                  4       w  rgV P                  Wc! 4       4       V P                  Ws! 4       4       V! V4       V P	                  Wc! 4       4       V P                  Ws! 4       4       V! V4       V P                  Wc! 4       4       V P                  Ws! 4       4       R# )z-
Helper for getReaders and getWriters tests.
getsaddremoveN)r.   getattrr)   assertNotInassertIn)r(   kindr0   rX   rZ   r[   r   r   s   &&      r!   
_getFDTest#ReactorFDSetTestsBuilder._getFDTest   s     ##%gut|c12gut|,(T/2,,.''Ffce$'v''r+   c                (    V P                  R4       R# )z
L{IReactorFDSet.getReaders} reflects the additions and removals made
with L{IReactorFDSet.addReader} and L{IReactorFDSet.removeReader}.
ReaderNr`   rI   s   &r!   test_getReaders(ReactorFDSetTestsBuilder.test_getReaders       
 	!r+   c                   a  S P                  4       w  rpV 3R lpWBn        VP                  V4       VP                  V4       VP	                  ^ VP                  ^ VP
                  4       S P                  V4       R# )z
L{reactor.removeWriter()} accepts an L{IWriteDescriptor} provider
previously passed to C{reactor.addWriter()} and causes it to no longer
be monitored for outputability.
c                  *   < S P                  R 4       R# )doWrite should not be calledNrG   rI   s   r!   rH   8ReactorFDSetTestsBuilder.test_removeWriter.<locals>.fail   s    II45r+   N)r2   rS   rT   rQ   rK   r7   r@   rL   s   f    r!   test_removeWriter*ReactorFDSetTestsBuilder.test_removeWriter   sl     #//1V	6 
"R  	!W..7<<@ r+   c                (    V P                  R4       R# )z
L{IReactorFDSet.getWriters} reflects the additions and removals made
with L{IReactorFDSet.addWriter} and L{IReactorFDSet.removeWriter}.
WriterNrd   rI   s   &r!   test_getWriters(ReactorFDSetTestsBuilder.test_getWriters   rg   r+   c                  a  S P                  4       pS P                  4       w  rpV 3R lVn        V 3R lVn        VP	                  R4       VP                  V4       VP                  V4       VP                  4       pVP                  ^ VP                  ^ VP                  4       S P                  V4       S P                  WB.4       R# )z
C{reactor.removeAll()} removes all registered L{IReadDescriptor}
providers and all registered L{IWriteDescriptor} providers and returns
them.
c                  &   < S P                  R 4      # )rF   rG   rI   s   r!   <lambda>9ReactorFDSetTestsBuilder.test_removeAll.<locals>.<lambda>   s    DII&CDr+   c                  &   < S P                  R 4      # )rj   rG   rI   s   r!   rt   ru      s    TYY'EFr+   r<   N)r.   r2   r=   rS   r?   r>   rT   	removeAllrK   r7   r@   assertEqual)r(   r0   r1   r   removeds   f    r!   test_removeAll'ReactorFDSetTestsBuilder.test_removeAll   s     ##%"//1VD	F
t""##% 	!W..7<<@  	$'r+   c                    V P                  4       p\        V4      pVP                  VP                  4       V P	                  V4       V P                  VP                  . 4       R# )zn
A descriptor's C{fileno} method should not be called after the
descriptor has been removed from the reactor.
N)r.   RemovingDescriptorcallWhenRunningstartr@   rx   calls)r(   r0   
descriptors   &  r!   test_removedFromReactor0ReactorFDSetTestsBuilder.test_removedFromReactor   sR    
 ##%'0

 0 01 ))2.r+   c                (  aaa V P                  4       oV P                  4       w  oo ! VVV3R lR\        4      pV! S4      pSP                  V4       SP	                  R4       V P                  S4       V P                  VP                  R4       R# )zX
If L{FileDescriptor.fileno} returns C{-1}, the descriptor is removed
from the reactor.
c                   h   <a  ] tR t^t o  ZP	                  4       tRtR tVV3R ltV3R ltRt	V t
R# )WReactorFDSetTestsBuilder.test_negativeOneFileDescriptor.<locals>.DisappearingDescriptorr+   c                    V P                   # r-   _filenorI   s   &r!   r/   ^ReactorFDSetTestsBuilder.test_negativeOneFileDescriptor.<locals>.DisappearingDescriptor.fileno   s    ||#r+   c                   < RV n         V ;P                  SP                  ^4      ,          un        SP                  R4       R# )      yN)r   	_receivedrecvsendr'   s   &r!   r=   ^ReactorFDSetTestsBuilder.test_negativeOneFileDescriptor.<locals>.DisappearingDescriptor.doRead   s,    !&++a.0D!r+   c                (   < SP                  4        R # r-   r7   r(   reasonr0   s   &&r!   connectionLostfReactorFDSetTestsBuilder.test_negativeOneFileDescriptor.<locals>.DisappearingDescriptor.connectionLost  s    r+   r   N)__name__
__module____qualname____firstlineno__r/   r   r   r=   r   __static_attributes____classdictcell__)__classdict__r   r0   r   s   @r!   DisappearingDescriptorr      s)     mmoGI$"
 r+   r   r<   N)r.   r)   r   r>   r   r@   rx   r   )r(   r   r   r   r0   r   s   &  @@@r!   test_negativeOneFileDescriptor7ReactorFDSetTestsBuilder.test_negativeOneFileDescriptor   s~    
 ##%,,.	 	^ 	  ,G4
*%D --t4r+   z*Cannot duplicate socket filenos on Windowsc                  a aa S P                  4       oSP                  P                  pVR9   d   \        V: R24      hS P	                  4       w  po ! VV3R lR\
        4      pSP                  V! 4       4       V V3R lpSP                  ^ V4       S P                  S4       S P                  \        P                  4       R# )a  
The file descriptor underlying a FileDescriptor may be closed and
replaced by another at some point.  Bytes which arrive on the new
descriptor must not be delivered to the FileDescriptor which was
originally registered with the original descriptor of the same number.

Practically speaking, this is difficult or impossible to detect.  The
implementation relies on C{fileno} raising an exception if the original
descriptor has gone away.  If C{fileno} continues to return the original
file descriptor value, the reactor may deliver events from that
descriptor.  This is a best effort attempt to ease certain debugging
situations.  Applications should not rely on it intentionally.
z$ cannot detect lost file descriptorsc                   D   <a  ] tR tRt o RtV3R ltR tV3R ltRtV t	R# )@ReactorFDSetTestsBuilder.test_lostFileDescriptor.<locals>.Victimi-  aB  
This L{FileDescriptor} will have its socket closed out from under it
and another socket will take its place.  It will raise a
socket.error from C{fileno} after this happens (because socket
objects remember whether they have been closed), so as long as the
reactor calls the C{fileno} method the problem will be detected.
c                $   < SP                  4       # r-   )r/   )r(   r   s   &r!   r/   GReactorFDSetTestsBuilder.test_lostFileDescriptor.<locals>.Victim.fileno6  s    }}&r+   c                    \        R 4      h)z$Victim.doRead should never be called)	ExceptionrI   s   &r!   r=   GReactorFDSetTestsBuilder.test_lostFileDescriptor.<locals>.Victim.doRead9  s     FGGr+   c                (   < SP                  4        R# )z
When the problem is detected, the reactor should disconnect this
file descriptor.  When that happens, stop the reactor so the
test ends.
Nr   r   s   &&r!   r   OReactorFDSetTestsBuilder.test_lostFileDescriptor.<locals>.Victim.connectionLost<  s     r+    N)
r   r   r   r   __doc__r/   r=   r   r   r   )r   r0   r   s   @r!   Victimr   -  s     'H r+   r   c                     < SP                  4       w  rSP                  4       pSP                  4        \        P                  ! VP                  4       V4       V P                  R 4       R# )r<   N)r)   r/   r   osdup2r   )newCnewSr/   r(   r   s      r!   messItUpBReactorFDSetTestsBuilder.test_lostFileDescriptor.<locals>.messItUpK  sF    ,,.JD]]_FLLNGGDKKM6*IIdOr+   N)EPollReactorKQueueReactor	CFReactorAsyncioSelectorReactor)r.   	__class__r   r   r)   r   r>   rK   r@   flushLoggedErrorsr   error)r(   namer   r   r   r0   r   s   f    @@r!   test_lostFileDescriptor0ReactorFDSetTestsBuilder.test_lostFileDescriptor  s     ##%  )) 
 
 dX%IJKK,,.	 	^ 	. 	&(#	 	!X&  	v||,r+   c                   V P                  4       p ! R R\        4      pV P                  4       w  r4V! V4      pVP                  Vn        V! V4      pVP                  Vn        VP	                  V4       VP                  V4       VP                  VP                  4       V P                  V4       V P                  VP                  4       V P                  VP                  4       R# )zo
Any file descriptors added to the reactor have their C{connectionLost}
called when C{reactor.stop} is called.
c                   ,   a  ] tR tRt o R tR tRtV tR# )SReactorFDSetTestsBuilder.test_connectionLostOnShutdown.<locals>.DoNothingDescriptoria  c                    R # r-   r   rI   s   &r!   r=   ZReactorFDSetTestsBuilder.test_connectionLostOnShutdown.<locals>.DoNothingDescriptor.doReadb      r+   c                    R # r-   r   rI   s   &r!   rS   [ReactorFDSetTestsBuilder.test_connectionLostOnShutdown.<locals>.DoNothingDescriptor.doWritee  r   r+   r   N)r   r   r   r   r=   rS   r   r   r   s   @r!   DoNothingDescriptorr   a  s      r+   r   N)r.   r   r)   r/   r>   rT   r~   r7   r@   
assertTruedisconnected)r(   r0   r   r   r   fd1fd2s   &      r!   test_connectionLostOnShutdown6ReactorFDSetTestsBuilder.test_connectionLostOnShutdownZ  s    
 ##%	. 	 ,,.!'*]]
!'*]]
##- (()(()r+   r   N)r   r   r   r   r   r   requiredInterfacesr)   r2   rB   rM   rU   r`   re   rl   rp   rz   r   r   r   r   	isWindowsr   r   r   r   r   s   @r!   r$   r$   4   s      (#!&!0!$(,"!."(:	/5> H "NOJ- PJ-X* *r+   r$   c                   H   a  ] tR tRt o RtR tR tR tR tR t	R t
R	tV tR
# )r}   iw  ax  
A read descriptor which removes itself from the reactor as soon as it
gets a chance to do a read and keeps track of when its own C{fileno}
method is called.

@ivar insideReactor: A flag which is true as long as the reactor has
    this descriptor as a reader.

@ivar calls: A list of the bottom of the call stack for any call to
    C{fileno} when C{insideReactor} is false.
c                \    Wn         R V n        . V n        \        4       w  V n        V n        R# FN)r0   insideReactorr   r"   readwrite)r(   r0   s   &&r!   __init__RemovingDescriptor.__init__  s&    "
 *	4:r+   c                    R V n         V P                  P                  V 4       V P                  P	                  R4       R# )T   aN)r   r0   r>   r   r   rI   s   &r!   r   RemovingDescriptor.start  s,    !t$

r+   c                    R # )foor   rI   s   &r!   	logPrefixRemovingDescriptor.logPrefix  s    r+   c                    V P                   P                  V 4       R V n        V P                   P                  4        V P                  P                  4        V P                  P                  4        R# r   )r0   r6   r   r7   r   r   r   rI   s   &r!   r=   RemovingDescriptor.doRead  sJ    !!$'"		

r+   c                    V P                   '       g4   V P                  P                  \        P                  ! ^R7      RR 4       V P
                  P                  4       # )   )limitNr   )r   r   append	tracebackextract_stackr   r/   rI   s   &r!   r/   RemovingDescriptor.fileno  sE    !!!JJi55A>sCDyy!!r+   c                    R # r-   r   )r(   r   s   &&r!   r   !RemovingDescriptor.connectionLost  s     	r+   )r   r   r0   r   r   N)r   r   r   r   r   r   r   r   r=   r/   r   r   r   r   s   @r!   r}   r}   w  s-     
-
"
 r+   r}   )!r   r   r   r   typingr   unittestr   zope.interfacer   twisted.internet.abstractr   twisted.internet.interfacesr   r   twisted.internet.tcpr   r	   #twisted.internet.test.reactormixinsr
   twisted.python.runtimer   twisted.trial.unittestr   r   PretendTestCaseobjectr"   r$   r}   globalsupdatemakeTestCaseClassesr   r+   r!   <module>r      s    
      & 4 F 9 > + @)OO.@*~ @*F
 _+ + +\ 	  )==? @r+   