
    hN                        S r SSKrSSKJr  SSKJr  SSKJr  SSKJ	r	  SSK
JrJr  SSKJrJr  SS	KJrJrJr  SS
KJr  SSKJrJr  SSKJr  SSKJrJrJr  SSKJ r   SSK!J"r"  SSK#J$r$  S\RJ                  \RL                  4S jr' " S S\5      r( " S S5      r) " S S\5      r*S r+S r, " S S\5      r- " S S5      r. " S S \5      r/ " S! S"\(5      r0 " S# S$5      r1 " S% S&5      r2 " S' S(5      r3 " S) S*5      r4g)+z?
Various helpers for tests for connection-oriented transports.
    N)collect)Optional)ref)verifyObject)DeferredgatherResults)
IConnectorIReactorFDSet)ClientFactoryProtocolServerFactory)needsRunningReactor)contextlog)Failure)ILogContexterrmsg)platform)ClosingProtocol)SkipTestz	127.0.0.1c                    [         R                  " U S5      S   S   n[         R                   " X5      n UR                  U5        U[         R                  :X  a_  UR	                  5       n[         R
                  " U[         R                  [         R                  -  5      S   nXeS   4UR                  5         $ UR	                  5       UR                  5         $ ! UR                  5         f = f)a  
Ask the platform to allocate a free port on the specified interface, then
release the socket and return the address which was allocated.

@param interface: The local address to try to bind the port on.
@type interface: C{str}

@param type: The socket type which will use the resulting port.

@return: A two-tuple of address and port, like that returned by
    L{socket.getsockname}.
r         )	socketgetaddrinfobindAF_INET6getsocknamegetnameinfoNI_NUMERICHOSTNI_NUMERICSERVclose)	interfacefamilytypeaddrprobesocknamehostnames          m/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/internet/test/connectionmixins.pyfindFreePortr,      s     i+A.q1DMM&'E

4V__$((*H))&//&2G2GGH qk* 	 $$&s   A3C 9C C+c                   (    \ rS rSrSrSrS rS rSrg)ConnectableProtocol:   aF  
A protocol to be used with L{runProtocolsWithReactor}.

The protocol and its pair should eventually disconnect from each other.

@ivar reactor: The reactor used in this test.

@ivar disconnectReason: The L{Failure} passed to C{connectionLost}.

@ivar _done: A L{Deferred} which will be fired when the connection is
    lost.
Nc                     Xl         X l        g)a  
Set attributes on the protocol that are known only externally; this
will be called by L{runProtocolsWithReactor} when this protocol is
instantiated.

@param reactor: The reactor used in this test.

@param done: A L{Deferred} which will be fired when the connection is
   lost.
N)reactor_done)selfr1   dones      r+   _setAttributes"ConnectableProtocol._setAttributesJ   s     
    c                 J    Xl         U R                  R                  S 5        U ?g N)disconnectReasonr2   callbackr3   reasons     r+   connectionLost"ConnectableProtocol.connectionLostX   s     &

D!Jr7   )r2   r:   r1   )	__name__
__module____qualname____firstlineno____doc__r:   r5   r>   __static_attributes__ r7   r+   r.   r.   :   s     r7   r.   c                   $    \ rS rSrSrS rS rSrg)EndpointCreator^   zL
Create client and server endpoints that know how to connect to each other.
c                     [        5       e)z
Return an object providing C{IStreamServerEndpoint} for use in creating
a server to use to establish the connection type to be tested.
NotImplementedErrorr3   r1   s     r+   serverEndpointCreator.serverc       
 "##r7   c                     [        5       e)z
Return an object providing C{IStreamClientEndpoint} for use in creating
a client to use to establish the connection type to be tested.
rK   )r3   r1   serverAddresss      r+   clientEndpointCreator.clientj   rP   r7   rF   N)r@   rA   rB   rC   rD   rN   rS   rE   rF   r7   r+   rH   rH   ^   s    $$r7   rH   c                   $    \ rS rSrSrS rS rSrg)_SingleProtocolFactoryr   z
Factory to be used by L{runProtocolsWithReactor}.

It always returns the same protocol (i.e. is intended for only a single
connection).
c                     Xl         g r9   	_protocol)r3   protocols     r+   __init___SingleProtocolFactory.__init__z   s    !r7   c                     U R                   $ r9   rY   )r3   r'   s     r+   buildProtocol$_SingleProtocolFactory.buildProtocol}   s    ~~r7   rY   Nr@   rA   rB   rC   rD   r\   r_   rE   rF   r7   r+   rV   rV   r   s    "r7   rV   c                   ^^	^
^ U R                  5       mUR                  T[        5       5        UR                  T[        5       5        [        U5      n[        U5      m	TR	                  T5      nUR                  U5      nU	UU4S jnUR                  U5        S n[        UR                  UR                  /5      m
UR                  U
4S j5        UR                  U5        UR                  U4S j5        U R                  T5        T$ )a  
Connect two protocols using endpoints and a new reactor instance.

A new reactor will be created and run, with the client and server protocol
instances connected to each other using the given endpoint creator. The
protocols should run through some set of tests, then disconnect; when both
have disconnected the reactor will be stopped and the function will
return.

@param reactorBuilder: A L{ReactorBuilder} instance.

@param serverProtocol: A L{ConnectableProtocol} that will be the server.

@param clientProtocol: A L{ConnectableProtocol} that will be the client.

@param endpointCreator: An instance of L{EndpointCreator}.

@return: The reactor run by this test.
c                 f   > TR                  TU R                  5       5      nUR                  T5      $ r9   )rS   getHostconnect)pclientEndpointclientFactoryendpointCreatorr1   s     r+   gotPort(runProtocolsWithReactor.<locals>.gotPort   s,    (//E%%m44r7   c                 2    [         R                  " U S5        g )NzConnection setup failed.)r   r   )results    r+   failed'runProtocolsWithReactor.<locals>.failed   s    23r7   c                    > T$ r9   rF   )_disconnecteds    r+   <lambda>)runProtocolsWithReactor.<locals>.<lambda>   s    Lr7   c                 0   > [        TTR                  5      $ r9   )r   stop)rq   r1   s    r+   rs   rt      s    /Fr7   )buildReactorr5   r   rV   rN   listenaddCallbackr   r2   
addErrback
runReactor)reactorBuilderserverProtocolclientProtocolri   serverFactoryserverEndpointdrj   rn   rh   rr   r1   s      `     @@@r+   runProtocolsWithReactorr      s    , ))+G!!'8:6!!'8:6*>:M*>:M %++G4Nm,A5 MM'4 !."6"68L8L!MNLMM()LLMMFGg&Nr7   c                     [         R                  " U 5      (       a  U R                  5       $ SU R                  R                  ;   a  U R
                  $ [        SU < 35      e)zN
Like L{IReactorFDSet.getWriters}, but with support for IOCP reactor as
well.
IOCPzCannot find writers on )r
   
providedBy
getWriters	__class__r@   handles	Exceptionr1   s    r+   _getWritersr      sW    
 ((!!##	7$$--	- 1'=>>r7   c                   $    \ rS rSrSrS rS rSrg)_AcceptOneClient   a6  
This factory fires a L{Deferred} with a protocol instance shortly after it
is constructed (hopefully long enough afterwards so that it has been
connected to a transport).

@ivar reactor: The reactor used to schedule the I{shortly}.

@ivar result: A L{Deferred} which will be fired with the protocol instance.
c                     Xl         X l        g r9   r1   rm   )r3   r1   rm   s      r+   r\   _AcceptOneClient.__init__   s    r7   c                     [         R                  " X5      nU R                  R                  SU R                  R
                  U5        U$ )Nr   )r   r_   r1   	callLaterrm   r;   )r3   r'   r[   s      r+   r_   _AcceptOneClient.buildProtocol   s7     ..t:q$++"6"6Ar7   r   Nra   rF   r7   r+   r   r      s    r7   r   c                   *    \ rS rSrSrS rS rS rSrg)_SimplePullProducer   zv
A pull producer which writes one byte whenever it is resumed.  For use by
C{test_unregisterProducerAfterDisconnect}.
c                     Xl         g r9   consumer)r3   r   s     r+   r\   _SimplePullProducer.__init__   s     r7   c                     g r9   rF   r3   s    r+   stopProducing!_SimplePullProducer.stopProducing   s    r7   c                 f    [         R                  " S5        U R                  R                  S5        g )NProducer.resumeProducing   x)r   r   r   writer   s    r+   resumeProducing#_SimplePullProducer.resumeProducing   s!    *+D!r7   r   N)	r@   rA   rB   rC   rD   r\   r   r   rE   rF   r7   r+   r   r      s    
!"r7   r   c                   (    \ rS rSrSrSrS rS rSrg)Stop   zI
A client factory which stops a reactor when a connection attempt fails.
Nc                     Xl         g r9   r   rM   s     r+   r\   Stop.__init__   s    r7   c                 |    X l         [        SUR                  5        35        U R                  R	                  5         g )NzStop(CF) cCFailed: )
failReasonr   getErrorMessager1   rv   )r3   	connectorr=   s      r+   clientConnectionFailedStop.clientConnectionFailed   s1     !&"8"8":!;<=r7   )r   r1   )	r@   rA   rB   rC   rD   r   r\   r   rE   rF   r7   r+   r   r      s     Jr7   r   c                   0    \ rS rSrSrS rS rS rS rSr	g)	ClosingLaterProtocol   z
ClosingLaterProtocol exchanges one byte with its peer and then disconnects
itself.  This is mostly a work-around for the fact that connectionMade is
called before the SSL handshake has completed.
c                     S U l         Xl        g r9   lostConnectionReasononConnectionLost)r3   r   s     r+   r\   ClosingLaterProtocol.__init__   s    $(! 0r7   c                     [        S5        g )Nz#ClosingLaterProtocol.connectionMade)r   r   s    r+   connectionMade#ClosingLaterProtocol.connectionMade  s    12r7   c                 V    [        SU< 35        U R                  R                  5         g )Nz"ClosingLaterProtocol.dataReceived r   	transportloseConnectionr3   bytess     r+   dataReceived!ClosingLaterProtocol.dataReceived  s"    0	:;%%'r7   c                 \    [        S5        Xl        U R                  R                  U 5        g )Nz#ClosingLaterProtocol.connectionLost)r   r   r   r;   r<   s     r+   r>   #ClosingLaterProtocol.connectionLost  s%    12$*!&&t,r7   r   N)
r@   rA   rB   rC   rD   r\   r   r   r>   rE   rF   r7   r+   r   r      s    13(-r7   r   c                   @    \ rS rSr% SrSr\\   \S'   S r	S r
S rSrg)	ConnectionTestsMixini  z[
This mixin defines test methods which should apply to most L{ITransport}
implementations.
N	endpointsc                      " S S[         5      nU" S5      nU" S5      n[        XX R                  5        U R                  SUR                  5        U R                  SUR                  5        g)z
Client and server transports implement L{ILoggingContext.logPrefix} to
return a message reflecting the protocol they are running.
c                   ,    \ rS rSrS rS rS rS rSrg)DConnectionTestsMixin.test_logPrefix.<locals>.CustomLogPrefixProtocoli  c                     Xl         S U l        g r9   _prefixsystem)r3   prefixs     r+   r\   MConnectionTestsMixin.test_logPrefix.<locals>.CustomLogPrefixProtocol.__init__   s    %"r7   c                 :    U R                   R                  S5        g )N   a)r   r   r   s    r+   r   SConnectionTestsMixin.test_logPrefix.<locals>.CustomLogPrefixProtocol.connectionMade$  s    $$T*r7   c                     U R                   $ r9   )r   r   s    r+   	logPrefixNConnectionTestsMixin.test_logPrefix.<locals>.CustomLogPrefixProtocol.logPrefix'  s    ||#r7   c                     [         R                  " [        5      S   U l        U R                  R                  S5        SU;   a  U R                  R                  5         g g )Nr      b)r   getr   r   r   r   r   r   s     r+   r   QConnectionTestsMixin.test_logPrefix.<locals>.CustomLogPrefixProtocol.dataReceived*  sG    %kk+6x@$$T* 5=NN113 !r7   r   N)	r@   rA   rB   rC   r\   r   r   r   rE   rF   r7   r+   CustomLogPrefixProtocolr     s    #+$4r7   r   zCustom ClientzCustom ServerN)r.   r   r   assertInr   )r3   r   rS   rN   s       r+   test_logPrefix#ConnectionTestsMixin.test_logPrefix  sW    	4&9 	4& )9(9fnnEov}}5ov}}5r7   c                 T  ^ ^^^^^ T R                  5       m/ m[        5       mU4S jnT R                  R                  T5      R	                  [
        R                  " U5      5      mUUU U4S jmUUU4S jn[        TU5        T R                  T5        T R                  TSS/5        g)ze
After a connection is disconnected, L{ITransport.write} and
L{ITransport.writeSequence} are no-ops.
c                     > [        T 5      $ r9   r   )serverConnectionLostDeferreds   r+   rs   @ConnectionTestsMixin.test_writeAfterDisconnect.<locals>.<lambda>B  s    /0LMr7   c                   >^ [        SU R                  5       < 35        T	R                  R                  TU R                  5       5      n[	        5       mU4S jnUR                  [        R                  " U5      5      nS nUR                  UTR                  5        U4S jnTR                  U5        T
R                  U5        [        TT
/5      $ )NListening on c                     > [        T 5      $ r9   r   )lostConnectionDeferreds   r+   rs   SConnectionTestsMixin.test_writeAfterDisconnect.<locals>.listening.<locals>.<lambda>L  s    34JKr7   c                 X    [        SU < 35        U R                  R                  S5        g )NzAbout to write to r   )r   r   r   protos    r+   r   PConnectionTestsMixin.test_writeAfterDisconnect.<locals>.listening.<locals>.writeO  s$    (	23%%d+r7   c                    > [        U < S35        U R                  R                  S5        U R                  R                  SS/5        TR	                  S5        g )Nz disconnecteds   some bytes to get losts   somes   moreT)r   r   r   writeSequenceappend)r   finisheds    r+   rr   WConnectionTestsMixin.test_writeAfterDisconnect.<locals>.listening.<locals>.disconnectedU  sH    ui}-.%%&?@--w.@A%r7   )r   rd   r   rS   r   re   r   forProtocoladdCallbackserrbackry   r   )portendpointr[   rS   r   rr   r   r   r1   r3   r   s         @r+   	listeningAConnectionTestsMixin.test_writeAfterDisconnect.<locals>.listeningG  s    -123~~,,WdllnEH%-Z"KH%%m&?&?&IJF, '='E'EF& #..|<(44\B "8:V!WXXr7   c                  |   > TR                  T 5        TR                  [        5        TR                  U4S j5        g )Nc                 $   > TR                  5       $ r9   rv   ignoredr1   s    r+   rs   RConnectionTestsMixin.test_writeAfterDisconnect.<locals>.onListen.<locals>.<lambda>b  s    W\\^r7   )ry   rz   r   r   portDeferredr1   s   r+   onListen@ConnectionTestsMixin.test_writeAfterDisconnect.<locals>.onListen_  s.    $$Y/##C($$%CDr7   TN)
rw   r   r   rN   rx   r   r   r   r{   assertEqual)r3   r[   r  r   r   r  r1   r   s   `  @@@@@r+   test_writeAfterDisconnect.ConnectionTestsMixin.test_writeAfterDisconnect8  s    
 ##%'/z$M~~,,W5<<%%h/
	Y 	Y0	E
 	GX. D$<0r7   c                   ^ ^^^^^ [        5       m[        T5      m[        T5      nT R                  5       mT R                  R                  T5      R                  [        R                  " [        5      5      mUUUU 4S jmUUU4S jn[        TU5        T R                  T5        Sm[        5         T R                  U" 5       5        g)zz
After the connection a protocol is being used for is closed, the
reactor discards all of its references to the protocol.
c                 F  > [        SU R                  5       < 35        TR                  R                  TU R                  5       5      nUR	                  [
        R                  " U4S j5      5      nS nUR                  U5        UR                  TR                  5        T$ )Nr   c                     > T $ r9   rF   )r~   s   r+   rs   aConnectionTestsMixin.test_protocolGarbageAfterLostConnection.<locals>.listening.<locals>.<lambda>{  s    r7   c                 V    [        SU < 35        U R                  R                  5         g )NzAbout to disconnect r   r   s    r+   
disconnectcConnectionTestsMixin.test_protocolGarbageAfterLostConnection.<locals>.listening.<locals>.disconnect}  s"    *5)45..0r7   )
r   rd   r   rS   re   r   r   ry   rz   r   )r   r   rS   r  r~   r   r1   r3   s       r+   r   OConnectionTestsMixin.test_protocolGarbageAfterLostConnection.<locals>.listeningw  s    -123~~,,WdllnEH%%m&?&?@V&WXF1 z*4<<=))r7   c                  |   > TR                  T 5        TR                  [        5        TR                  U4S j5        g )Nc                 $   > TR                  5       $ r9   r   r   s    r+   rs   cConnectionTestsMixin.test_protocolGarbageAfterLostConnection.<locals>.onListening.<locals>.<lambda>  s    r7   )ry   rz   r   addBothr   s   r+   onListeningQConnectionTestsMixin.test_protocolGarbageAfterLostConnection.<locals>.onListening  s.    $$Y/##C(  !?@r7   N)r   r   r   rw   r   rN   rx   r   r   r   r   r{   r   assertIsNone)r3   	clientRefr  r~   r   r   r  r1   s   `  @@@@@r+   'test_protocolGarbageAfterLostConnection<ConnectionTestsMixin.test_protocolGarbageAfterLostConnectioni  s    
 "*-.DE'	##%~~,,W5<<%%h/
	* 	*	A
 	G[1  	)+&r7   rF   )r@   rA   rB   rC   rD   r   r   rH   __annotations__r   r  r  rE   rF   r7   r+   r   r     s(    
 ,0Ix(/6>/1b)'r7   r   c                       \ rS rSrSrS rSrg)LogObserverMixini  zD
Mixin for L{TestCase} subclasses which want to observe log events.
c                     / n[         R                  " UR                  5        U R                  [         R                  UR                  5        U$ r9   )r   addObserverr   
addCleanupremoveObserver)r3   loggedMessagess     r+   observeLogObserverMixin.observe  s9    --.**N,A,ABr7   rF   N)r@   rA   rB   rC   rD   r!  rE   rF   r7   r+   r  r    s    r7   r  c                   "    \ rS rSrSrSrS rSrg)BrokenContextFactoryi  zj
A context factory with a broken C{getContext} method, for exercising the
error handling for such a case.
zSome path was wrong maybec                 ,    [        U R                  5      er9   )
ValueErrormessager   s    r+   
getContextBrokenContextFactory.getContext  s    &&r7   rF   N)r@   rA   rB   rC   rD   r'  r(  rE   rF   r7   r+   r$  r$    s    
 *G'r7   r$  c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
StreamClientTestsMixini  aY  
This mixin defines tests applicable to SOCK_STREAM client implementations.

This must be mixed in to a L{ReactorBuilder
<twisted.internet.test.reactormixins.ReactorBuilder>} subclass, as it
depends on several of its methods.

Then the methods C{connect} and C{listen} must defined, defining a client
and a server communicating with each other.
c                     U R                  5       nU R                  U[        5       5      nU R                  [	        [
        U5      5        g)zB
The C{connect} method returns an object providing L{IConnector}.
N)rw   re   r   
assertTruer   r	   )r3   r1   r   s      r+   test_interface%StreamClientTestsMixin.test_interface  s7     ##%LL-/:	Z;<r7   c                 l   ^ ^ T R                  5       m[        TUU 4S j5        T R                  T5        g)zT
The reactor can be stopped by a client factory's
C{clientConnectionFailed} method.
c                  :   > TR                  T [        T 5      5      $ r9   )re   r   )r1   r3   s   r+   rs   PStreamClientTestsMixin.test_clientConnectionFailedStopsReactor.<locals>.<lambda>  s    T\\'4=-Qr7   N)rw   r   r{   rM   s   `@r+   'test_clientConnectionFailedStopsReactor>StreamClientTestsMixin.test_clientConnectionFailedStopsReactor  s*    
 ##%G%QR r7   c                 4  ^ ^^^ T R                  5       mT R                  T[        R                  " [        5      5        / m " UU4S jS[        5      n[        T5      mUTl        [        TUUU 4S j5        TR                  5         T R                  T5        g)z
This test checks that we correctly get notifications event for a
client.  This ought to prevent a regression under Windows using the
GTK2 reactor.  See #3925.
c                   $   > \ rS rSrU U4S jrSrg)AStreamClientTestsMixin.test_connectEvent.<locals>.CheckConnectioni  c                 H   > TR                  U 5        TR                  5         g r9   )r   rv   )r3   	connectedr1   s    r+   r   PStreamClientTestsMixin.test_connectEvent.<locals>.CheckConnection.connectionMade  s      &r7   rF   N)r@   rA   rB   rC   r   rE   )r9  r1   s   r+   CheckConnectionr7    s     r7   r;  c                  (   > TR                  TT 5      $ r9   )re   )rh   r1   r3   s   r+   rs   :StreamClientTestsMixin.test_connectEvent.<locals>.<lambda>  s    T\\'=-Qr7   N)
rw   rx   r   r   r   r   r[   r   runr-  )r3   r;  rh   r9  r1   s   ` @@@r+   test_connectEvent(StreamClientTestsMixin.test_connectEvent  su     ##%G]66x@A		 	h 	
 W!0G%QR	"r7   c                   ^^^ U R                  5       mU R                  T[        R                  " [        5      5        [        5       mTR                  [        R                  5        TR                  U4S j5        / m " UUU4S jS[        5      n[        5       nXl        U R                  TU5        U R                  T5        U R                  TS   S5        g)a  
If a producer is unregistered from a transport after the transport has
been disconnected (by the peer) and after C{loseConnection} has been
called, the transport is not re-added to the reactor as a writer as
would be necessary if the transport were still connected.
c                 $   > TR                  5       $ r9   r   ignr1   s    r+   rs   OStreamClientTestsMixin.test_unregisterProducerAfterDisconnect.<locals>.<lambda>      r7   c                   6   > \ rS rSrSrS rU UU4S jrS rSrg)UStreamClientTestsMixin.test_unregisterProducerAfterDisconnect.<locals>.ClientProtocoli  z
Protocol to connect, register a producer, try to lose the
connection, wait for the server to disconnect from us, and then
unregister the producer.
c                     [         R                  " S5        U R                  R                  [	        U R                  5      S5        U R                  R                  5         g )NClientProtocol.connectionMadeF)r   r   r   registerProducerr   r   r   s    r+   r   dStreamClientTestsMixin.test_unregisterProducerAfterDisconnect.<locals>.ClientProtocol.connectionMade  sA    78//'7 --/r7   c                    > [         R                  " S5        U R                  5         TR                  U R                  [        T5      ;   5        TR                  S 5        g NzClientProtocol.connectionLost)r   r   
unregisterr   r   r   r;   )r3   r=   r   r1   writings     r+   r>   dStreamClientTestsMixin.test_unregisterProducerAfterDisconnect.<locals>.ClientProtocol.connectionLost  sB    78!t~~W1EEF!!$'r7   c                 d    [         R                  " S5        U R                  R                  5         g )NClientProtocol unregister)r   r   r   unregisterProducerr   s    r+   rO  `StreamClientTestsMixin.test_unregisterProducerAfterDisconnect.<locals>.ClientProtocol.unregister  s    34113r7   rF   N)	r@   rA   rB   rC   rD   r   r>   rO  rE   )r   r1   rP  s   r+   ClientProtocolrH    s    0(4r7   rV  r   z/Transport was writing after unregisterProducer.N)rw   rx   r   r   r   r   rz   r   r   ry   r   r   r[   re   r{   assertFalse)r3   rV  rh   r   r1   rP  s      @@@r+   &test_unregisterProducerAfterDisconnect=StreamClientTestsMixin.test_unregisterProducerAfterDisconnect  s     ##%G]66GH:CGG$78	4 	4X 	40 &!/Wm, %VWr7   c                 $  ^^^ U R                  5       mSS/nTR                  R                  nX!;   a%  [        R                  " 5       (       a  [        S5      e " S S5      mU R                  T[        R                  " [        5      5        [        5       mTR                  [        R                  5        TR                  U4S j5         " UUU4S jS[        5      n[        5       nX4l        U R#                  TU5        U R%                  T5        g	)
z
If C{loseConnection} is called while a producer is registered with the
transport, the connection is closed after the producer is unregistered.
Glib2ReactorGtk2Reactorz=A pygobject/pygtk bug disables this functionality on Windows.c                       \ rS rSrS rSrg)FStreamClientTestsMixin.test_disconnectWhileProducing.<locals>.Produceri$  c                 0    [         R                  " S5        g )Nr   )r   r   r   s    r+   r   VStreamClientTestsMixin.test_disconnectWhileProducing.<locals>.Producer.resumeProducing%  s    23r7   rF   N)r@   rA   rB   rC   r   rE   rF   r7   r+   Producerr^  $  s    4r7   ra  c                 $   > TR                  5       $ r9   r   rC  s    r+   rs   FStreamClientTestsMixin.test_disconnectWhileProducing.<locals>.<lambda>,  rF  r7   c                   B   > \ rS rSrSrU U4S jrUU4S jrU4S jrSrg)LStreamClientTestsMixin.test_disconnectWhileProducing.<locals>.ClientProtocoli.  z
Protocol to connect, register a producer, try to lose the
connection, unregister the producer, and wait for the connection to
actually be lost.
c                    > [         R                  " S5        U R                  R                  T" 5       S5        U R                  R	                  5         TR                  STR
                  SU R                  5        g )NrJ  Fr   )r   r   r   rK  r   r   rO  )r3   ra  r1   s    r+   r   [StreamClientTestsMixin.test_disconnectWhileProducing.<locals>.ClientProtocol.connectionMade5  sV    78//
EB--/
 !!!W%6%64??Kr7   c           	         > [         R                  " S5        U R                  R                  5         TR	                  STR
                  [        [        S5      5      5        g )NrS  g      ?zConnection was not lost)r   r   r   rT  r   r   r   r   )r3   r   r1   s    r+   rO  WStreamClientTestsMixin.test_disconnectWhileProducing.<locals>.ClientProtocol.unregister?  sH    34113 !!))79=V3W+Xr7   c                 T   > [         R                  " S5        TR                  S 5        g rN  )r   r   r;   )r3   r=   r   s     r+   r>   [StreamClientTestsMixin.test_disconnectWhileProducing.<locals>.ClientProtocol.connectionLostI  s    78!!$'r7   rF   N)	r@   rA   rB   rC   rD   r   rO  r>   rE   )ra  r   r1   s   r+   rV  re  .  s    L( (r7   rV  N)rw   r   r@   r   	isWindowsr   rx   r   r   r   r   rz   r   r   ry   r   r[   re   r{   )r3   skippedReactorsreactorClassNamerV  rh   ra  r   r1   s        @@@r+   test_disconnectWhileProducing4StreamClientTestsMixin.test_disconnectWhileProducing  s    
 ##% *=9",,55.83E3E3G3GR 	4 	4 	G]66x@A:CGG$78	( 	(X 	(> &!/Wm, r7   rF   N)r@   rA   rB   rC   rD   r.  r3  r?  rX  ro  rE   rF   r7   r+   r+  r+    s"    	=!#2,X\?!r7   r+  )5rD   r   gcr   typingr   weakrefr   zope.interface.verifyr   twisted.internet.deferr   r   twisted.internet.interfacesr	   r
   twisted.internet.protocolr   r   r   #twisted.internet.test.reactormixinsr   twisted.pythonr   r   twisted.python.failurer   twisted.python.logr   r   r   twisted.python.runtimer   twisted.test.test_tcpr   twisted.trial.unittestr   AF_INETSOCK_STREAMr,   r.   rH   rV   r   r   r   r   r   r   r   r  r$  r+  rF   r7   r+   <module>r     s   

     . : A L L C ' * 4 4 + 1 + 'v~~FDVDV :!( !H$ $(] 1h?} *" ""=  -. -0A' A'H	 		' 	'c! c!r7   