+
    Dfj                     B   R t ^ RIt^ RIHt ^ RIHtHtHt ^ RIH	t	H
t
HtHtHt ^ RIHtHt ^ RIHt ^ RIHt  ! R R	]P*                  4      t ! R
 R]P.                  4      t ! R R]P*                  4      t ! R R]P4                  4      t ! R R]P8                  4      t ! R R]P<                  4      t ! R R]P@                  4      t! ! R R]PD                  4      t" ! R R]P@                  4      t# ! R R]P@                  4      t$ ! R R]P@                  4      t% ! R R]P*                  ]PL                  4      t' ! R  R!]P@                  4      t( ! R" R#]P@                  4      t) ! R$ R%]4      t* ! R& R']PV                  4      t, ! R( R)]P@                  4      t-R# )*z
Test code for policies.
N)StringIO)	InterfaceimplementedByimplementer)addressdeferprotocolreactortask)StringTransport StringTransportWithDisconnection)policies)unittestc                   D   a  ] tR t^t o ^ ;ttRtR tR tR t	R t
RtV tR# )SimpleProtocol    c                n    \         P                  ! 4       V n        \         P                  ! 4       V n        R # N)r   Deferred
dConnecteddDisconnectedselfs   &</usr/lib/python3/dist-packages/twisted/test/test_policies.py__init__SimpleProtocol.__init__   s    ..*"^^-r   c                J    ^V n         V P                  P                  R4       R#     N)	connectedr   callbackr   s   &r   connectionMadeSimpleProtocol.connectionMade   s      $r   c                J    ^V n         V P                  P                  R4       R# r   )disconnectedr   r!   r   reasons   &&r   connectionLostSimpleProtocol.connectionLost    s    ##B'r   c                8    V ;P                   V,          un         R # r   )bufferr   datas   &&r   dataReceivedSimpleProtocol.dataReceived$   s    tr   )r    r   r   r%   N)__name__
__module____qualname____firstlineno__r    r%   r+   r   r"   r(   r.   __static_attributes____classdictcell____classdict__s   @r   r   r      s-       IF.%( r   r   c                   ,   a  ] tR t^(t o R tR tRtV tR# )SillyFactoryc                    Wn         R # r   p)r   r<   s   &&r   r   SillyFactory.__init__)   s    r   c                    V P                   # r   r;   )r   addrs   &&r   buildProtocolSillyFactory.buildProtocol,   s    vvr   r;   N)r0   r1   r2   r3   r   r@   r4   r5   r6   s   @r   r9   r9   (   s      r   r9   c                   <   a  ] tR t^0t o RtR tR tR tR tRt	V t
R# )EchoProtocolFc                    R V n         R# TNpausedr   s   &r   pauseProducingEchoProtocol.pauseProducing3   s	    r   c                    R V n         R# )FNrF   r   s   &r   resumeProducingEchoProtocol.resumeProducing6   s	    r   c                    R # r    r   s   &r   stopProducingEchoProtocol.stopProducing9   s    r   c                <    V P                   P                  V4       R # r   )	transportwriter,   s   &&r   r.   EchoProtocol.dataReceived<   s    T"r   rF   N)r0   r1   r2   r3   rG   rH   rK   rO   r.   r4   r5   r6   s   @r   rC   rC   0   s#     F# #r   rC   c                       ] tR t^@tRt]tRtR# )Serverz0
A simple server factory using L{EchoProtocol}.
rN   N)r0   r1   r2   r3   __doc__rC   r   r4   rN   r   r   rV   rV   @   s     Hr   rV   c                   0   a  ] tR t^Ht o RtR tR tRtV tR# )TestableThrottlingFactoryz@
L{policies.ThrottlingFactory} using a L{task.Clock} for tests.
c                Z    \         P                  P                  ! V .VO5/ VB  Wn        R# zx
@param clock: object providing a callLater method that can be used
    for tests.
@type clock: C{task.Clock} or alike.
N)r   ThrottlingFactoryr   clockr   r]   argskwargss   &&*,r   r   "TestableThrottlingFactory.__init__M   s'     	""++DB4B6B
r   c                8    V P                   P                  W4      # z 
Forward to the testable clock.
r]   	callLaterr   periodfuncs   &&&r   re   #TestableThrottlingFactory.callLaterV        zz##F11r   r]   N	r0   r1   r2   r3   rW   r   re   r4   r5   r6   s   @r   rY   rY   H        2 2r   rY   c                   0   a  ] tR t^]t o RtR tR tRtV tR# )TestableTimeoutFactoryz=
L{policies.TimeoutFactory} using a L{task.Clock} for tests.
c                Z    \         P                  P                  ! V .VO5/ VB  Wn        R# r[   )r   TimeoutFactoryr   r]   r^   s   &&*,r   r   TestableTimeoutFactory.__init__b   s'     	((???
r   c                8    V P                   P                  W4      # rc   rd   rf   s   &&&r   re    TestableTimeoutFactory.callLaterk   rj   r   rk   Nrl   r6   s   @r   ro   ro   ]   rm   r   ro   c                      a  ] tR t^rt 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R tR tR tR tR tRtV tR# )WrapperTestsz6
Tests for L{WrappingFactory} and L{ProtocolWrapper}.
c                    \        4       p\        P                  ! V4      pVP                  \        P
                  ! RR^#4      4      pV P                  VP                  P                  V4       R# )zN
Make sure protocol.factory is the wrapped factory, not the wrapping
factory.
TCP	127.0.0.1N)	rV   r   WrappingFactoryr@   r   IPv4AddressassertIswrappedProtocolfactory)r   fwfr<   s   &   r   test_protocolFactoryAttribute*WrapperTests.test_protocolFactoryAttributew   sT    
 H%%a(W00RHIa''//3r   c                    ! R R\         4      p\        V4       ! R R4      4       p\        \        P                  4       \
        P                  ! 4       p\        P                  ! \        P                  ! R4      V4      pVP                  V! 4       4       V P                  VP                  VP                  4      4       R# )z
The transport wrapper passed to the wrapped protocol's
C{makeConnection} provides the same interfaces as are provided by the
original transport.
c                       ] tR t^tRtR# )=WrapperTests.test_transportInterfaces.<locals>.IStubTransportrN   Nr0   r1   r2   r3   r4   rN   r   r   IStubTransportr          r   r   c                       ] tR t^tRtR# )<WrapperTests.test_transportInterfaces.<locals>.StubTransportrN   Nr   rN   r   r   StubTransportr      s    r   r   N)r   r   r   r   ProtocolWrapperr   Protocolrz   makeConnection
assertTrue
providedByrR   )r   r   r   protowrappers   &    r   test_transportInterfaces%WrapperTests.test_transportInterfaces   s    	Y 	 
^	$	 	 
%	 	h../!!#**8+C+CD+I5Q}/11%//BCr   c                    \        4       p\        P                  ! V4      pV P                  RVP	                  4       4       R# )zk
L{WrappingFactory.logPrefix} is customized to mention both the original
factory and the wrapping factory.
zServer (WrappingFactory)N)rV   r   rz   assertEqual	logPrefix)r   serverr~   s   &  r   test_factoryLogPrefix"WrapperTests.test_factoryLogPrefix   s5    
 **623W5F5F5HIr   c                     ! R R4      pV! 4       p\         P                  ! V4      pV P                  RVP                  4       4       R# )z
If the wrapped factory doesn't have a L{logPrefix} method,
L{WrappingFactory.logPrefix} falls back to the factory class name.
c                       ] tR t^tRtR# )=WrapperTests.test_factoryLogPrefixFallback.<locals>.NoFactoryrN   Nr   rN   r   r   	NoFactoryr      r   r   r   zNoFactory (WrappingFactory)N)r   rz   r   r   )r   r   r   r~   s   &   r   test_factoryLogPrefixFallback*WrapperTests.test_factoryLogPrefixFallback   s?    	 	 **6268I8I8KLr   c                    \        4       p\        P                  ! V4      pVP                  \        P
                  ! RR^#4      4      pV P                  RVP                  ! 4       4       R# )zc
L{ProtocolWrapper.logPrefix} is customized to mention both the original
protocol and the wrapper.
rx   ry   zEchoProtocol (ProtocolWrapper)N)rV   r   rz   r@   r   r{   r   r   )r   r   r~   r   s   &   r   test_protocolLogPrefix#WrapperTests.test_protocolLogPrefix   sU    
 **62(()<)<UKQS)TU98;M;M;OPr   c                     ! R R4      p\        4       pWn        \        P                  ! V4      pVP	                  \
        P                  ! RR^#4      4      pV P                  RVP                  ! 4       4       R# )z
If the wrapped protocol doesn't have a L{logPrefix} method,
L{ProtocolWrapper.logPrefix} falls back to the protocol class name.
c                       ] tR t^tRtR# )?WrapperTests.test_protocolLogPrefixFallback.<locals>.NoProtocolrN   Nr   rN   r   r   
NoProtocolr      r   r   r   rx   ry   zNoProtocol (ProtocolWrapper)N)	rV   r   r   rz   r@   r   r{   r   r   )r   r   r   r~   r   s   &    r   test_protocolLogPrefixFallback+WrapperTests.test_protocolLogPrefixFallback   sd    	 	 $**62(()<)<UKQS)TU79K9K9MNr   c                    \         P                  ! \         P                  ! \        4       4      \        P
                  ! 4       4      p\        4       pVP                  V4       V# )zU
Return L{policies.ProtocolWrapper} that has been connected to a
L{StringTransport}.
)r   r   rz   rV   r   r   r   r   r   r   rR   s   &  r   _getWrapperWrapperTests._getWrapper   sL    
 **$$VX.0A0A0C
 $%	y)r   c                    V P                  4       pV P                  VP                  4       VP                  P                  4       4       R# )zS
L{policies.ProtocolWrapper.getHost} calls C{getHost} on the underlying
transport.
N)r   r   getHostrR   r   r   s   & r   test_getHostWrapperTests.test_getHost   8    
 ""$*G,=,=,E,E,GHr   c                    V P                  4       pV P                  VP                  4       VP                  P                  4       4       R# )zS
L{policies.ProtocolWrapper.getPeer} calls C{getPeer} on the underlying
transport.
N)r   r   getPeerrR   r   s   & r   test_getPeerWrapperTests.test_getPeer   r   r   c                    V P                  4       p\        4       pVP                  VR4       V P                  VP                  P
                  V4       V P                  VP                  P                  4       R# )ze
L{policies.ProtocolWrapper.registerProducer} calls C{registerProducer}
on the underlying transport.
TN)r   objectregisterProducerr|   rR   producerr   	streamingr   r   r   s   &  r   test_registerProducer"WrapperTests.test_registerProducer   s[    
 ""$8  40g''00(;))334r   c                   V P                  4       p\        4       pVP                  VR4       VP                  4        V P	                  VP
                  P                  4       V P	                  VP
                  P                  4       R# )zi
L{policies.ProtocolWrapper.unregisterProducer} calls
C{unregisterProducer} on the underlying transport.
TN)r   r   r   unregisterProducerassertIsNonerR   r   r   r   s   &  r   test_unregisterProducer$WrapperTests.test_unregisterProducer   si    
 ""$8  40""$'++445'++556r   c                   a V P                  4       p. oV3R lVP                  n        VP                  4        V P                  SR.4       R# )z_
L{policies.ProtocolWrapper.stopConsuming} calls C{stopConsuming} on
the underlying transport.
c                  &   < S P                  R 4      # )Tappend)results   r   <lambda>1WrapperTests.test_stopConsuming.<locals>.<lambda>  s    &--2Er   TN)r   rR   stopConsumingr   )r   r   r   s   & @r   test_stopConsumingWrapperTests.test_stopConsuming   sD    
 ""$*E'$(r   c                   a . o ! V3R lR4      p\         P                  ! V! 4       4      p\        4       pVP                  V4       V P	                  SV.4       R# )ze
L{policies.WrappingFactory.startedConnecting} calls
C{startedConnecting} on the underlying factory.
c                   .   <a  ] tR tRt o V3R ltRtV tR# )4WrapperTests.test_startedConnecting.<locals>.Factoryi  c                *   < SP                  V4       R # r   r   )r   	connectorr   s   &&r   startedConnectingFWrapperTests.test_startedConnecting.<locals>.Factory.startedConnecting  s    i(r   rN   N)r0   r1   r2   r3   r   r4   r5   r7   r   s   @r   Factoryr     s     ) )r   r   N)r   rz   r   r   r   )r   r   r   r   r   s   &   @r   test_startedConnecting#WrapperTests.test_startedConnecting  sO    
 	) 	) **795H	!!),)-r   c                   a . o ! V3R lR4      p\         P                  ! V! 4       4      p\        4       p\        4       pVP                  W44       V P	                  SW43.4       R# )zk
L{policies.WrappingFactory.clientConnectionLost} calls
C{clientConnectionLost} on the underlying factory.
c                   .   <a  ] tR tRt o V3R ltRtV tR# )7WrapperTests.test_clientConnectionLost.<locals>.Factoryi"  c                ,   < SP                  W34       R # r   r   r   r   r'   r   s   &&&r   clientConnectionLostLWrapperTests.test_clientConnectionLost.<locals>.Factory.clientConnectionLost#      y12r   rN   N)r0   r1   r2   r3   r   r4   r5   r   s   @r   r   r   "       3 3r   r   N)r   rz   r   r   r   r   r   r   r   r'   r   s   &    @r   test_clientConnectionLost&WrapperTests.test_clientConnectionLost  sZ    
 	3 	3 **795H	$$Y79"5!67r   c                   a . o ! V3R lR4      p\         P                  ! V! 4       4      p\        4       p\        4       pVP                  W44       V P	                  SW43.4       R# )zo
L{policies.WrappingFactory.clientConnectionFailed} calls
C{clientConnectionFailed} on the underlying factory.
c                   .   <a  ] tR tRt o V3R ltRtV tR# )9WrapperTests.test_clientConnectionFailed.<locals>.Factoryi3  c                ,   < SP                  W34       R # r   r   r   s   &&&r   clientConnectionFailedPWrapperTests.test_clientConnectionFailed.<locals>.Factory.clientConnectionFailed4  r   r   rN   N)r0   r1   r2   r3   r   r4   r5   r   s   @r   r   r   3  r   r   r   N)r   rz   r   r   r   r   s   &    @r   test_clientConnectionFailed(WrapperTests.test_clientConnectionFailed,  sZ    
 	3 	3 **795H	&&y99"5!67r   c                `   \         P                  ! \         P                  ! \        4       4      \        P
                  ! 4       4      p\        4       pWn        VP                  V4       V P                  VP                  4       VP                  4        V P                  VP                  4       R# )z
L{policies.ProtocolWrapper.connectionLost} sets C{wrappedProtocol} to
C{None} in order to break reference cycle between wrapper and wrapped
protocols.
N)r   r   rz   rV   r   r   r   r   assertIsNotNoner}   loseConnectionr   r   s   &  r   test_breakReferenceCycle%WrapperTests.test_breakReferenceCycle=  s     **$$VX.0A0A0C
 56	$y)W445  "'112r   rN   N)r0   r1   r2   r3   rW   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r4   r5   r6   s   @r   rv   rv   r   sf     4D:JMQO
II	5
7	). 8"8"3 3r   rv   c                   ,   a  ] tR tRt o R tR tRtV tR# )rz   iO  c                    V# r   rN   )r   r   r<   s   &&&r   r   WrappingFactory.protocolP  s    r   c                z    \         P                  P                  V 4       V P                  P	                  R 4       R # r   )r   rz   startFactorydeferredr!   r   s   &r   r   WrappingFactory.startFactoryS  s(      --d3t$r   rN   N)r0   r1   r2   r3   r   r   r4   r5   r6   s   @r   rz   rz   O  s     % %r   rz   c                   <   a  ] tR tRt o RtR tR tR tR tRt	V t
R# )	ThrottlingTestsiX  z*
Tests for L{policies.ThrottlingFactory}.
c                  a a	a
aaaaa \        4       pR \        ^4       4       w  o	o
oo\        P                  ! V^4      o\	        S4      p\
        P                  ! 4       Vn        \        P                  ! ^ VRR7      oSP                  4       P                  oV	V
VV3R lpV	V
VV V3R lpV	3R lpVV3R lpVV 3R lpV
VV3R	 lpVP                  P                  V4       VP                  P                  V4       VP                  P                  V4       VP                  P                  V4       VP                  P                  V4       VP                  P                  V4       VP                  # )
z
Full test using a custom server limiting number of connections.

FIXME: https://twistedmatrix.com/trac/ticket/10012
This is a flaky test.
c              3   6   "   T F  p\        4       x  K  	  R # 5ir   )r   ).0is   & r   	<genexpr>-ThrottlingTests.test_limit.<locals>.<genexpr>e  s     =Hq.**Hs   ry   )	interfacec                    < \         P                  ! R S\        S4      4       SP                  P	                  VV3R l4       SP                  P	                  VV3R l4       SP
                  # )ry   c                 F   < \         P                  ! R S\        S4      4      # ry   r	   
connectTCPr9   )rc2ns   &r   r   AThrottlingTests.test_limit.<locals>._connect123.<locals>.<lambda>q      ',,[!\"=MNr   c                 F   < \         P                  ! R S\        S4      4      # r  r  )r  c3r
  s   &r   r   r  t  r  r   )r	   r  r9   r   addCallbackr   )resultsc1r	  r  r
  s   &r   _connect123/ThrottlingTests.test_limit.<locals>._connect123n  sT    {A|B/?@MM%%N MM%%N ###r   c                 B  < SP                  SSS3 Uu. uF  qP                  NK  	  up. RO4       SP                  SSS3 Uu. uF  qP                  NK  	  up. RO4       SP                  \        SP                  P                  4       4      ^4       V # u upi u upi )r   )r   r   r   )    r  r   )r   r    r%   len	protocolskeys)r  cr  r	  r  r   tServers   & r   	_check123-ThrottlingTests.test_limit.<locals>._check123x  s    BB<@<akk<@)Lr2rlClnnlCYOS!2!2!7!7!9:A>N ACs   BBc                 P   < SP                   P                  4        SP                  # r   )rR   r   r   )r  r  s   &r   _lose1*ThrottlingTests.test_limit.<locals>._lose1~  s    LL'')###r   c                 ^   < \         P                  ! R S\        S4      4       SP                  # r  )r	   r  r9   r   )r  c4r
  s   &r   	_connect4-ThrottlingTests.test_limit.<locals>._connect4  s$    {A|B/?@== r   c                 x   < SP                  SP                  ^4       SP                  SP                  ^ 4       V # )r   )r   r    r%   )r  r!  r   s   &r   _check4+ThrottlingTests.test_limit.<locals>._check4  s0    R\\1-R__a0Nr   c                    < SS3 F  pVP                   P                  4        K  	  \        P                  ! \        P                  ! SP
                  4      SP                  SP                  .4      # r   )rR   r   r   DeferredListmaybeDeferredstopListeningr   )r  r  r	  r!  r<   s   & r   _cleanup,ThrottlingTests.test_limit.<locals>._cleanup  s]    V**, %%''8$$$$ r   )rV   ranger   r\   rz   r   r   r   r	   	listenTCPr   portr  )r   r   wrapTServerr  r  r  r"  r%  r+  r  r	  r  r!  r
  r<   r  s   f        @@@@@@@r   
test_limitThrottlingTests.test_limit]  s"    =E!H=BB,,VQ7%g.$~~/ aDIIK	$ 	$	 		$
	!	
		 	((5((3((0((3((1((2###r   c                   \        4       p\        \        P                  ! 4       V4      pVP	                  \
        P                  ! RR^ 4      4      p\        4       pW4n        VP                  ! V4       VP                  ! R.^,          4       V P                  VP                  4       R4       V P                  VP                  ^4       R# )zJ
L{ThrottlingProtocol.writeSequence} is called on the underlying factory.
rx   ry      bytess   bytesbytesbytesbytesN)rV   rY   r
   Clockr@   r   r{   r   r   r   writeSequencer   valuewrittenThisSecond)r   r   r  r   rR   s   &    r   test_writeSequence"ThrottlingTests.test_writeSequence  s     +DJJL&A(()<)<UKQR)ST46	%	*zA~.*,CD22B7r   c                   \        4       p\        \        P                  ! 4       V^
R7      pVP	                  \
        P                  ! RR^ 4      4      p\        4       pW4n        VP                  V4       VP                  Vn        VP                  R4       VP                  R4       V P                  VP                  4       R4       V P                  VP                  ^4       V P!                  VP                  P"                  4       VP$                  P'                  R4       V P                  VP                  ^ 4       V P)                  VP                  P"                  4       VP$                  P'                  R4       V P                  VP                  ^ 4       V P!                  VP                  P"                  4       R# )	zM
Check the writeLimit parameter: write data, and check for the pause
status.
)
writeLimitrx   ry   
   0123456789
   abcdefghij   0123456789abcdefghij?N)rV   rY   r
   r5  r@   r   r{   r   r   r   r}   r   r.   r   r7  r8  assertFalserG   r]   advancer   r   r   r  r/  trs   &    r   test_writeLimitThrottlingTests.test_writeLimit  sM   
 +DJJL&RP$$W%8%8Q%OP-/B,,-(-(%<=22B7--445
 	d#22A6,,334d#22A6--445r   c                   \        4       p\        \        P                  ! 4       V^
R7      pVP	                  \
        P                  ! RR^ 4      4      p\        4       pW4n        VP                  V4       VP                  R4       VP                  R4       V P                  VP                  4       R4       V P                  VP                  ^4       VP                  P                  R4       V P                  VP                  ^ 4       V P                  VP                   R4       VP                  P                  R4       V P                  VP                  ^ 4       V P                  VP                   R	4       VP#                  4        VP                  R4       VP                  R4       V P                  VP                  4       R4       V P                  VP                  ^4       VP                  P                  R4       V P                  VP                  ^ 4       V P                  VP                   R4       VP                  P                  R4       V P                  VP                  ^ 4       V P                  VP                   R	4       R
# )zJ
Check the readLimit parameter: read data and check for the pause
status.
)	readLimitrx   ry   r=  r>  r?  r@  rG   	producingN)rV   rY   r
   r5  r@   r   r{   r   r   r   r.   r   r7  readThisSecondr]   rB  producerStateclearrC  s   &    r   test_readLimitThrottlingTests.test_readLimit  s   
 +DJJL&BO$$W%8%8Q%OP-/B-(-(%<=//4d#//3))84d#//3));7

-(-(%<=//4d#//3))84d#//3));7r   rN   N)r0   r1   r2   r3   rW   r1  r9  rE  rM  r4   r5   r6   s   @r   r   r   X  s%     @$D86<%8 %8r   r   c                   B   a  ] tR tRt o RtR tR tR tR tR t	Rt
V tR	# )
TimeoutProtocolTestsi  z(
Tests for L{policies.TimeoutProtocol}.
c                   \         P                  ! 4       p\        P                  ! 4       p\        Vn        \        WR4      pVP                  \        P                  ! RRR4      4      p\        4       pWEn        VP                  V4       WA3# )z
Helper to set up an already connected protocol to be tested.

@return: A new protocol with its attached clock.
@rtype: Tuple of (L{policies.TimeoutProtocol}, L{task.Clock})
Nrx   ry   90  )r
   r5  r   ServerFactoryr   ro   r@   r   r{   r   r   )r   r]   wrappedFactoryr~   r   rR   s   &     r   getProtocolAndClock(TimeoutProtocolTests.getProtocolAndClock  st     

!//1"0(E%%g&9&9%e&TU46	"Y'~r   c                   V P                  4       w  rVP                  ^4       V P                  VP                  4       V P	                  VP
                  P                  4       VP                  ^4       VP                  4        V P                  VP                  4       VP                  ^4       V P	                  VP
                  P                  4       R# )z"
Will cancel the ongoing timeout.
N)
rU  
setTimeoutr   timeoutCallrA  r}   r%   rB  cancelTimeoutr   r   sutr]   s   &  r   test_cancelTimeout'TimeoutProtocolTests.test_cancelTimeout  s     --/
qS__-,,99:a#//* 	a,,99:r   c                    V P                  4       w  rV P                  VP                  4       VP                  4        V P	                  VP
                  P                  4       R# )z,
Does nothing if no timeout is already set.
N)rU  r   rY  rZ  rA  r}   r%   r[  s   &  r   test_cancelTimeoutNoTimeout0TimeoutProtocolTests.test_cancelTimeoutNoTimeout"  sN     --/
#//* 	,,99:r   c                    V P                  4       w  rVP                  pVP                  ^4       VP                  ^4       V P	                  VP
                  4       VP                  4        R# )z0
Does nothing if no timeout is already reached.
N)rU  r}   rX  rB  r   r%   rZ  )r   r\  r]   wrappedProtos   &   r   test_cancelTimeoutAlreadyCalled4TimeoutProtocolTests.test_cancelTimeoutAlreadyCalled.  sW     --/
**qa112 	r   c                    V P                  4       w  rVP                  ^4       VP                  P                  4        VP	                  4        V P                  VP                  P                  4       R# )zU
Does nothing if the timeout is cancelled from another part.
Ex from another thread.
N)rU  rX  rY  cancelrZ  rA  r}   r%   r[  s   &  r   "test_cancelTimeoutAlreadyCancelled7TimeoutProtocolTests.test_cancelTimeoutAlreadyCancelled<  sX    
 --/
q  	,,99:r   rN   N)r0   r1   r2   r3   rW   rU  r]  r`  rd  rh  r4   r5   r6   s   @r   rP  rP    s(     ,;&
;; ;r   rP  c                   <   a  ] tR tRt o RtR tR tR tR tRt	V t
R# )	TimeoutFactoryTestsiL  z'
Tests for L{policies.TimeoutFactory}.
c                   \         P                  ! 4       V n        \        P                  ! 4       p\
        Vn        \        V P                  V^4      V n        V P                  P                  \        P                  ! RRR4      4      V n        \        4       V n        V P                  V P                  n        V P                  P                  V P                  4       V P                  P                  V n        R# )zY
Create a testable, deterministic clock, and a set of
server factory/protocol/transport.
rx   ry   rR  N)r
   r5  r]   r   rS  r   ro   r~   r@   r   r{   r   r   rR   r   r}   rc  )r   rT  s   & r   setUpTimeoutFactoryTests.setUpQ  s    
 ZZ\
!//1"0-djj.!L\\//{E:

 :;"&**

!!$..1 JJ66r   c                   V P                   P                  . RO4       V P                  V P                  P                  4       V P                   P                  RR.4       V P                  V P                  P                  4       R# )z
Make sure that when a TimeoutFactory accepts a connection, it will
time out that connection if no data is read or written within the
timeout period.
        皙?N)rp        ?      ?rs  g?)r]   pumprA  rc  r%   r   r   s   &r   test_timeout TimeoutFactoryTests.test_timeoutb  s]     	

12**778 	

c
#))667r   c                   V P                   P                  . RO4       V P                  V P                  P                  4       V P
                  P                  R4       V P                   P                  . RO4       V P                  V P                  P                  4       V P
                  P                  R.^,          4       V P                   P                  . RO4       V P                  V P                  P                  4       V P                   P                  RR.4       V P                  V P                  P                  4       R# )zz
Make sure that writing data to a transport from a protocol
constructed by a TimeoutFactory resets the timeout countdown.
rp     bytes bytes bytesr4  g       @N)rp  rr  rs  rp  rs  rs  )	r]   rt  rA  rc  r%   r   rS   r6  r   r   s   &r   test_sendAvoidsTimeout*TimeoutFactoryTests.test_sendAvoidsTimeoutp  s     	

(**778 	

-. 	

(**778 	

  (a0 	

(**778 	

c
#))667r   c                   V P                   P                  . RO4       V P                  V P                  P                  4       V P
                  P                  R4       V P                   P                  . RO4       V P                  V P                  P                  4       V P                   P                  . RO4       V P                  V P                  P                  4       R# )zB
Make sure that receiving data also resets the timeout countdown.
rx  N)rp  rs  rr  ry  )r]   rt  rA  rc  r%   r   r.   r   r   s   &r   test_receiveAvoidsTimeout-TimeoutFactoryTests.test_receiveAvoidsTimeout  s    
 	

(**778 	

 45 	

(**778 	

())667r   )r]   r~   r   rR   rc  N)r0   r1   r2   r3   rW   rm  ru  rz  r}  r4   r5   r6   s   @r   rk  rk  L  s#     7"8888 8r   rk  c                   T   a  ] tR tRt o Rt^tRtR tR tR t	RR lt
R	 tR
 tRtV tR# )TimeoutTesteri  z
A testable protocol with timeout facility.

@ivar timedOut: set to C{True} if a timeout has been detected.
@type timedOut: C{bool}
Fc                    Wn         R# )z6
Initialize the protocol with a C{task.Clock} object.
Nrk   )r   r]   s   &&r   r   TimeoutTester.__init__  s	     
r   c                <    V P                  V P                  4       R# )z#
Upon connection, set the timeout.
N)rX  timeOutr   s   &r   r"   TimeoutTester.connectionMade  s     	%r   c                d    V P                  4        \        P                  P                  W4       R# )z
Reset the timeout on data.
N)resetTimeoutr   r   r.   r,   s   &&r   r.   TimeoutTester.dataReceived  s$     	&&t2r   Nc                (    V P                  R4       R# )z4
On connection lost, cancel all timeout operations.
N)rX  r&   s   &&r   r(   TimeoutTester.connectionLost  s     	r   c                    RV n         R# )zH
Flags the timedOut variable to indicate the timeout of the connection.
TN)timedOutr   s   &r   timeoutConnectionTimeoutTester.timeoutConnection  s     r   c                B    V P                   P                  ! W.VO5/ VB # )z4
Override callLater to use the deterministic clock.
rd   )r   timeoutrh   r_   r`   s   &&&*,r   re   TimeoutTester.callLater  s#     zz##GCDCFCCr   )r]   r  r   )r0   r1   r2   r3   rW   r  r  r   r"   r.   r(   r  re   r4   r5   r6   s   @r   r  r    s;      GH&3D Dr   r  c                   T   a  ] tR tR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# )TimeoutMixinTestsi  z%
Tests for L{policies.TimeoutMixin}.
c                n    \         P                  ! 4       V n        \        V P                  4      V n        R# )zI
Create a testable, deterministic clock and a C{TimeoutTester} instance.
N)r
   r5  r]   r  r   r   s   &r   rm  TimeoutMixinTests.setUp  s!     ZZ\
"4::.
r   c                    V P                   P                  ^
4       V P                  \        V P                  P
                  4      ^4       R# )z
Test that the callLater of the clock is used instead of
L{reactor.callLater<twisted.internet.interfaces.IReactorTime.callLater>}
N)r   rX  r   r  r]   callsr   s   &r   test_overriddenCallLater*TimeoutMixinTests.test_overriddenCallLater  s5    
 	

b!TZZ--.2r   c                T   V P                   P                  \        4       4       V P                  P	                  . RO4       V P                  V P                   P                  4       V P                  P	                  ^ R.4       V P                  V P                   P                  4       R# )zY
Check that the protocol does timeout at the time specified by its
C{timeOut} attribute.
rs  Nr  rr  rs  rs  )r   r   r   r]   rt  rA  r  r   r   s   &r   ru  TimeoutMixinTests.test_timeout  sn    
 	

!!/"34 	

*+,,-

C!

++,r   c                   V P                   P                  \        4       4       V P                  P	                  . RO4       V P                  V P                   P                  4       V P                   P                  R4       V P                  P	                  . RO4       V P                  V P                   P                  4       V P                  P	                  ^ R.4       V P                  V P                   P                  4       R# )zF
Check that receiving data is delaying the timeout of the connection.
rs  s   hello thereNr  )r  rs  rs  rr  )	r   r   r   r]   rt  rA  r  r.   r   r   s   &r   test_noTimeout TimeoutMixinTests.test_noTimeout  s     	

!!/"34

*+,,-

/

*+,,-

C!

++,r   c                   RV P                   n        V P                   P                  \        4       4       V P                   P	                  ^4       V P                  V P                   P                  ^4       V P                  P                  ^ R.4       V P                  V P                   P                  4       V P                  P                  ^ R.4       V P                  V P                   P                  4       R# )za
Check that setting a new value for timeout cancel the previous value
and install a new timeout.
Ng?rq  )r   r  r   r   rX  r   r]   rt  rA  r  r   r   s   &r   test_resetTimeout#TimeoutMixinTests.test_resetTimeout  s    
 "



!!/"34

a ++Q/

C!,,-

C!

++,r   c                r   ^V P                   n        V P                   P                  \        4       4       V P                   P	                  R4       V P                  V P                   P                  4       V P                  P                  . RO4       V P                  V P                   P                  4       R# )z?
Setting the timeout to L{None} cancel any timeout operations.
N)r     r  r  )
r   r  r   r   rX  r   r]   rt  rA  r  r   s   &r   r]  $TimeoutMixinTests.test_cancelTimeout  sw     



!!/"34

d#$**,,-

%,,-r   c                   ^V P                   n        V P                  V P                   P                  ^
4      ^4       V P                  V P                   P                  R4      ^
4       V P	                  V P                   P                  ^4      4       V P                  V P                   P                  ^4       V P                   P                  R4       R# )z=
setTimeout should return the value of the previous timeout.
N)r   r  r   rX  r   r   s   &r   test_setTimeoutReturn'TimeoutMixinTests.test_setTimeoutReturn  s     

..r2A6..t4b9$**//23++Q/ 	

d#r   c                d   V P                   P                  ^4       V P                  P                  4       ^ ,          P	                  4        V P                  V P                   P                  4       V P                   P                  R4       V P                  V P                   P                  4       R# )z
When the timeout was already cancelled from an external place,
calling setTimeout with C{None} to explicitly cancel it will clean
up the timeout without raising any exception.
N)r   rX  r]   getDelayedCallsrg  r   r  r   r   s   &r   %test_setTimeoutCancleAlreadyCancelled7TimeoutMixinTests.test_setTimeoutCancleAlreadyCancelled,  sx     	

a  	

""$Q'..0TZZ//0

d#$**,,-r   )r]   r   N)r0   r1   r2   r3   rW   rm  r  ru  r  r  r]  r  r  r4   r5   r6   s   @r   r  r    s7     /3--- .$. .r   r  c                   0   a  ] tR tRt o RtR tR tRtV tR# )!LimitTotalConnectionsFactoryTestsi=  z/Tests for policies.LimitTotalConnectionsFactoryc                   \         P                  ! 4       p\        P                  Vn        V P	                  ^ VP
                  4       VP                  R4      pV P	                  ^VP
                  4       VP                  R4      pV P	                  ^VP
                  4       VP                  R4       V P	                  ^VP
                  4       VP                  R4       V P	                  ^ VP
                  4       R# )r  N)r   LimitTotalConnectionsFactoryr   r   r   connectionCountr@   r(   )r   r~   p1p2s   &   r   testConnectionCounting8LimitTotalConnectionsFactoryTests.testConnectionCounting@  s    779#,, 	G334 ""4(G334""4(G334 	$G334
$G334r   c                  a \         P                  ! 4       o\        P                  Sn        ^Sn        SP                  R4      pV P                  V4       V P                  ^SP                  4       V P                  SP                  R4      4       V P                  ^SP                  4        ! V3R lR\        P                  4      pVSn
        RSn        SP                  R4      pVP                  R4       V P                  SP                  4       V P                  ^SP                  4       VP                  R4       V P                  ^SP                  4       VP                  R4       V P                  ^ SP                  4       R# )r   Nc                   .   <a  ] tR tRt o V3R ltRtV tR# )RLimitTotalConnectionsFactoryTests.testConnectionLimiting.<locals>.OverflowProtocolie  c                   < R Sn         R# rE   )
overflowed)r   r~   s   &r   r"   aLimitTotalConnectionsFactoryTests.testConnectionLimiting.<locals>.OverflowProtocol.connectionMadef  s    %)"r   rN   N)r0   r1   r2   r3   r"   r4   r5   )r7   r~   s   @r   OverflowProtocolr  e  s     * *r   r  F)r   r  r   r   connectionLimitr@   r   r   r  r   overflowProtocolr  r   r   r(   )r   r<   r  opr~   s   &   @r   testConnectionLimiting8LimitTotalConnectionsFactoryTests.testConnectionLimitingT  sD   779#,,"# !!$'QG334 	'//56G334	*x00 	* $4 "
 ""4(
$**+G334 	
G334
$G334r   rN   N)	r0   r1   r2   r3   rW   r  r  r4   r5   r6   s   @r   r  r  =  s     95($5 $5r   r  c                   &   a  ] tR tRt o R tRtV tR# )WriteSequenceEchoProtocoli{  c                    VP                  R 4      R8w  d   V P                  P                  V.4       R# \        P	                  W4       R# )s   vector!N)findrR   r6  rC   r.   )r   bytess   &&r   r.   &WriteSequenceEchoProtocol.dataReceived|  s5    ::j!R'NN((%1%%d2r   rN   N)r0   r1   r2   r3   r.   r4   r5   r6   s   @r   r  r  {  s     3 3r   r  c                   *   a  ] tR tRt o RtR tRtV tR# )TestLoggingFactoryi  Nc                b    V P                   e   Q R4       h\        4       V n         V P                   # )Nzopen() called too many times)openFiler   )r   names   &&r   openTestLoggingFactory.open  s+    }}$D&DD$ 
}}r   )r  )r0   r1   r2   r3   r  r  r4   r5   r6   s   @r   r  r    s     H r   r  c                   6   a  ] tR tRt o RtR tR tR tRtV t	R# )LoggingFactoryTestsi  z.
Tests for L{policies.TrafficLoggingFactory}.
c                   \        4       p\        Vn        \        4       p\	        VR4      pVP                  R
4      pWBn        VP                  V4       VP                  P                  4       pV P                  RV4       V P                  VP                  4       4       VP                  R4       VP                  P                  4       pV P                  RP                  R4      V4       V P                  RP                  R4      V4       V P                  VP                  4       R4       VP                  4        VP                  R4       VP                  P                  4       pV P                  RP                  R.4      V4       V P                  VP                  4       R4       VP!                  4        VP                  P                  4       pV P                  RV4       R	# )zA
Check the output produced by L{policies.TrafficLoggingFactory}.
test*s   here are some bytesz	C 1: {!r}z	S 1: {!r}s"   prepare for vector! to the extremez
SV 1: {!r}ConnectionDoneN1.2.3.4i.  )rV   r  r   r   r  r@   r   r  getvalueassertInrA  r7  r.   formatr   rL  r   )r   rT  tr   r<   vs   &     r   test_thingsGetLogged(LoggingFactoryTests.test_thingsGetLogged  sq     ";,.~v6OO-.
	JJ!c1#	-.JJ!k(()?@!Dk(()?@!D$:;			<=JJ!l))+P*QRTUV$IJ	JJ!&*r   c                   \        4       p\        VR4      pV P                  VP                  ^ 4       VP	                  R4       V P                  VP                  ^4       RVn        VP	                  R4       V P                  VP                  ^4       VP                  4        V P                  VP                  ^ 4       R# )z7
Test counter management with the resetCounter method.
r  Nr  )r  i/  )rV   r  r   _counterr@   r  resetCounter)r   rT  r   s   &  r   test_counter LoggingFactoryTests.test_counter  s      ~v6Q'	)*Q'
	)*Q'	Q'r   c                  aa	 . o. o	VV	3R lpV P                  \        RV4       \        P                  ! 4       p\        Vn        \
        P                  ! VR4      pVP                  \        P                  ! RRR4      4      pVP                  \        P                  ! RRR4      4      pR	/ 3pR
/ 3pV P                  Wg.S4       V P                  VP                  VP                  .S	4       R# )z
When the L{policies.TrafficLoggingFactory} builds a protocol, it
automatically opens a unique log file for that protocol and attaches
the logfile to the built protocol.
c                 ~   < SP                  W34       \        4       pV ^ ,          Vn        SP                  V4       V# )z@
Mock for the open call to prevent actually opening a log file.
)r   r   r  )r_   r`   io
open_callsopen_rvaluess   *, r   mocked_openULoggingFactoryTests.test_loggingFactoryOpensLogfileAutomatically.<locals>.mocked_open  s:     tn-B1gBG#Ir   r  r  rx   ry   rR  i:0  N)ztest-1w)ztest-2r  )patchbuiltinsr   rS  r   r   TrafficLoggingFactoryr@   r   r{   r   logfile)
r   r  rT  r~   first_protosecond_proto
first_callsecond_callr  r  s
   &       @@r   ,test_loggingFactoryOpensLogfileAutomatically@LoggingFactoryTests.test_loggingFactoryOpensLogfileAutomatically  s     
	 	

8V[1!//1"000H++{E:
 ,,{E:
 &r*
&+*2J?+--|/C/CDlSr   rN   N)
r0   r1   r2   r3   rW   r  r  r  r4   r5   r6   s   @r   r  r    s!      +D("$T $Tr   r  ).rW   r  r  r   zope.interfacer   r   r   twisted.internetr   r   r   r	   r
   twisted.internet.testingr   r   twisted.protocolsr   twisted.trialr   r   r   ClientFactoryr9   rC   rS  rV   r\   rY   rq   ro   TestCaserv   rz   r   rP  rk  TimeoutMixinr  r  r  r  r  r  r  rN   r   r   <module>r     sr  
   @ @ D D V & "X&& (8)) #8$$ # X## 2 : : 2*2X44 2*Z38$$ Z3z%h.. %Y8h'' Y8xU;8,, U;pR8(++ R8j.DH%%x'<'< .Dbh.)) h.V;5(9(9 ;5|3 377 \T(++ \Tr   