+
    Dfjb*                       R t ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RI	H
t
HtHt ^ RIHt ^ RIHt ^ RIHtHtHtHtHt ^ R	IHt  ! R
 R]4      t]! ]4       ! R R4      4       t ! R R]4      t ! R R]4      t ! R R]4      tR# )z"
Tests for L{twisted.test.iosim}.
)annotations)Literal)implementer)IPushProducer)ClientFactoryFactoryProtocol)Clock)MemoryReactor)ConnectionCompleterFakeTransportIOPumpconnectconnectedServerAndClient)TestCasec                  >    ] tR t^tRtR R ltR R ltR R ltRtR	# )
FakeTransportTestsz
Tests for L{FakeTransport}.
c                   V ^8  d   QhRR/#    returnNone )formats   "9/usr/lib/python3/dist-packages/twisted/test/test_iosim.py__annotate__FakeTransportTests.__annotate__    s     	0 	0t 	0    c                "   \        \        4       R4      p\        \        4       R4      pV P                  VP                  \        4       V P                  VP                  \        4       V P                  VP                  VP                  4       R# )zM
Each L{FakeTransport} receives a serial number that uniquely identifies
it.
TFN)r   objectassertIsInstanceserialintassertNotEqual)selfabs   &  r   test_connectionSerial(FakeTransportTests.test_connectionSerial    s`    
 &(D)&(E*ahh,ahh,AHHahh/r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r   +   s     
6 
6D 
6r   c                    \        \        4       R4      pVP                  R4       VP                  . RO4       V P	                  RP                  VP                  4      R4       R# )zT
L{FakeTransport.writeSequence} will write a sequence of L{bytes} to the
transport.
F   ar   s   abcdN)   b   c   d)r   r   writewriteSequenceassertEqualjoinstreamr$   r%   s   & r   test_writeSequence%FakeTransportTests.test_writeSequence+   sG    
 &(E*		*+!((+W5r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r   7   s     
8 
8d 
8r   c                    \        \        4       R4      pVP                  R4       VP                  4        VP                  R4       V P	                  RP                  VP                  4      R4       R# )zp
L{FakeTransport.write} will accept writes after transport was closed,
but the data will be silently discarded.
Fs   befores   afterr   N)r   r   r/   loseConnectionr1   r2   r3   r4   s   & r   test_writeAfterClose'FakeTransportTests.test_writeAfterClose7   sS    
 &(E*				!((+Y7r   r   N)	__name__
__module____qualname____firstlineno____doc__r'   r5   r:   __static_attributes__r   r   r   r   r      s    	0
6
8 
8r   r   c                  B    ] tR t^DtRtRtR R ltR R ltR R ltR	t	R
# )StrictPushProducerzw
An L{IPushProducer} implementation which produces nothing but enforces
preconditions on its state transition methods.
runningc                   V ^8  d   QhRR/# r   r   )r   s   "r   r   StrictPushProducer.__annotate__M   s        t  r   c                	L    V P                   R 8X  d   \        R4      hR V n         R# )stoppedz)Cannot stop already-stopped IPushProducerN_state
ValueErrorr$   s   &r   stopProducing StrictPushProducer.stopProducingM   s!    ;;)#HIIr   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   rF   R   s       r   c                	h    V P                   R 8w  d   \        RV P                    R24      hRV n         R# )rD   zCannot pause  IPushProducerpausedNrI   rL   s   &r   pauseProducing!StrictPushProducer.pauseProducingR   s-    ;;)#}T[[MHIIr   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   rF   W   s          r   c                	h    V P                   R 8w  d   \        RV P                    R24      hRV n         R# )rR   zCannot resume rQ   rD   NrI   rL   s   &r   resumeProducing"StrictPushProducer.resumeProducingW   s-    ;;("~dkk].IJJr   )rJ   N)
r<   r=   r>   r?   r@   rJ   rM   rS   rW   rA   r   r   r   rC   rC   D   s"    
 F 

   r   rC   c                      ] tR t^]tRtR R ltR R ltR R ltR R	 ltR
 R lt	R R lt
R R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR  R! ltR" R# ltR$ R% ltR& R' ltR(tR)# )*StrictPushProducerTestsz"
Tests for L{StrictPushProducer}.
c                   V ^8  d   QhRR/# r   r   rC   r   )r   s   "r   r   $StrictPushProducerTests.__annotate__b   s     $ $, $r   c                    \        4       # )zX
@return: A new L{StrictPushProducer} which has not been through any state
    changes.
)rC   rL   s   &r   _initial StrictPushProducerTests._initialb   s    
 "##r   c                   V ^8  d   QhRR/# r\   r   )r   s   "r   r   r]   i   s      , r   c                :    \        4       pVP                  4        V# )z0
@return: A new, stopped L{StrictPushProducer}.
)rC   rM   r$   producers   & r   _stopped StrictPushProducerTests._stoppedi   s     &' r   c                   V ^8  d   QhRR/# r\   r   )r   s   "r   r   r]   q   s      + r   c                :    \        4       pVP                  4        V# )z/
@return: A new, paused L{StrictPushProducer}.
)rC   rS   rc   s   & r   _pausedStrictPushProducerTests._pausedq   s     &'!r   c                   V ^8  d   QhRR/# r\   r   )r   s   "r   r   r]   y   s      , r   c                Z    \        4       pVP                  4        VP                  4        V# )zI
@return: A new L{StrictPushProducer} which has been paused and resumed.
)rC   rS   rW   rc   s   & r   _resumed StrictPushProducerTests._resumedy   s)     &'!  "r   c                    V ^8  d   QhRRRR/# r   rd   rC   r   r   r   )r   s   "r   r   r]           5 5&8 5T 5r   c                >    V P                  VP                  R4       R# )z
Assert that the given producer is in the stopped state.

@param producer: The producer to verify.
@type producer: L{StrictPushProducer}
rH   Nr1   rJ   rc   s   &&r   assertStopped%StrictPushProducerTests.assertStopped        	)4r   c                    V ^8  d   QhRRRR/# rp   r   )r   s   "r   r   r]      s     4 4%7 4D 4r   c                >    V P                  VP                  R4       R# )z
Assert that the given producer is in the paused state.

@param producer: The producer to verify.
@type producer: L{StrictPushProducer}
rR   Nrs   rc   s   &&r   assertPaused$StrictPushProducerTests.assertPaused   s     	(3r   c                    V ^8  d   QhRRRR/# rp   r   )r   s   "r   r   r]      rq   r   c                >    V P                  VP                  R4       R# )z
Assert that the given producer is in the running state.

@param producer: The producer to verify.
@type producer: L{StrictPushProducer}
rD   Nrs   rc   s   &&r   assertRunning%StrictPushProducerTests.assertRunning   rv   r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r]      s     E E4 Er   c                b    V P                  \        V P                  4       P                  4       R# )zb
L{StrictPushProducer.stopProducing} raises L{ValueError} if called when
the producer is stopped.
N)assertRaisesrK   re   rM   rL   s   &r   test_stopThenStop)StrictPushProducerTests.test_stopThenStop   s     
 	*dmmo&C&CDr   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r]      s     F FD Fr   c                b    V P                  \        V P                  4       P                  4       R# )zc
L{StrictPushProducer.pauseProducing} raises L{ValueError} if called when
the producer is stopped.
N)r   rK   re   rS   rL   s   &r   test_stopThenPause*StrictPushProducerTests.test_stopThenPause   s     
 	*dmmo&D&DEr   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r]      s     G GT Gr   c                b    V P                  \        V P                  4       P                  4       R# )zd
L{StrictPushProducer.resumeProducing} raises L{ValueError} if called when
the producer is stopped.
N)r   rK   re   rW   rL   s   &r   test_stopThenResume+StrictPushProducerTests.test_stopThenResume   s     
 	*dmmo&E&EFr   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r]      s     % %D %r   c                h    V P                  4       pVP                  4        V P                  V4       R# )zV
L{StrictPushProducer} is stopped if C{stopProducing} is called on a paused
producer.
N)ri   rM   rt   rc   s   & r   test_pauseThenStop*StrictPushProducerTests.test_pauseThenStop   s)    
 <<> 8$r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r]      s     ? ?T ?r   c                f    V P                  4       pV P                  \        VP                  4       R# )z[
L{StrictPushProducer.pauseProducing} raises L{ValueError} if called on a
paused producer.
N)ri   r   rK   rS   rc   s   & r   test_pauseThenPause+StrictPushProducerTests.test_pauseThenPause   s%    
 <<>*h&=&=>r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r]      s     % %d %r   c                h    V P                  4       pVP                  4        V P                  V4       R# )zX
L{StrictPushProducer} is resumed if C{resumeProducing} is called on a
paused producer.
N)ri   rW   r}   rc   s   & r   test_pauseThenResume,StrictPushProducerTests.test_pauseThenResume   s)    
 <<>  "8$r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r]      s     % %T %r   c                h    V P                  4       pVP                  4        V P                  V4       R# )zW
L{StrictPushProducer} is stopped if C{stopProducing} is called on a
resumed producer.
N)rm   rM   rt   rc   s   & r   test_resumeThenStop+StrictPushProducerTests.test_resumeThenStop   )    
 ==? 8$r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r]      s     $ $d $r   c                h    V P                  4       pVP                  4        V P                  V4       R# )zW
L{StrictPushProducer} is paused if C{pauseProducing} is called on a
resumed producer.
N)rm   rS   ry   rc   s   & r   test_resumeThenPause,StrictPushProducerTests.test_resumeThenPause   )    
 ==?!(#r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r]      s     @ @t @r   c                f    V P                  4       pV P                  \        VP                  4       R# )z]
L{StrictPushProducer.resumeProducing} raises L{ValueError} if called on a
resumed producer.
N)rm   r   rK   rW   rc   s   & r   test_resumeThenResume-StrictPushProducerTests.test_resumeThenResume   %    
 ==?*h&>&>?r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r]      s     % %4 %r   c                h    V P                  4       pVP                  4        V P                  V4       R# )zV
L{StrictPushProducer} is stopped if C{stopProducing} is called in the
initial state.
N)r_   rM   rt   rc   s   & r   	test_stop!StrictPushProducerTests.test_stop   r   r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r]      s     $ $D $r   c                h    V P                  4       pVP                  4        V P                  V4       R# )zV
L{StrictPushProducer} is paused if C{pauseProducing} is called in the
initial state.
N)r_   rS   ry   rc   s   & r   
test_pause"StrictPushProducerTests.test_pause   r   r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r]      s     @ @T @r   c                f    V P                  4       pV P                  \        VP                  4       R# )zb
L{StrictPushProducer} raises L{ValueError} if C{resumeProducing} is called
in the initial state.
N)r_   r   rK   rW   rc   s   & r   test_resume#StrictPushProducerTests.test_resume   r   r   r   N)r<   r=   r>   r?   r@   r_   re   ri   rm   rt   ry   r}   r   r   r   r   r   r   r   r   r   r   r   r   rA   r   r   r   rZ   rZ   ]   sq    $545EFG%?%%$@%$@ @r   rZ   c                  J    ] tR tRtRtR R ltR R ltR R ltR	 R
 ltRt	R# )IOPumpTestsi  z
Tests for L{IOPump}.
c                    V ^8  d   QhRRRR/# )r   modezLiteral['server', 'client']r   r   r   )r   s   "r   r   IOPumpTests.__annotate__  s     !5 !5+F !54 !5r   c                .   \        4       p\        VRR7      p\        4       p\        VRR7      p\        VVVVRR7      p\        4       pRVRV/V,          pVP	                  VRR7       VP                  4        V P                  RVP                  4       R	# )
a  
Connect a couple protocol/transport pairs to an L{IOPump} and then pump
it.  Verify that a streaming producer registered with one of the
transports does not receive invalid L{IPushProducer} method calls and
ends in the right state.

@param mode: C{u"server"} to test a producer registered with the
    server transport.  C{u"client"} to test a producer registered with
    the client transport.
T)isServerF)greetserverclient)	streamingrD   N)r   r   r   rC   registerProducerpumpr1   rJ   )	r$   r   serverProtoserverTransportclientProtoclientTransportr   rd   victims	   &&       r   _testStreamingProducer"IOPumpTests._testStreamingProducer  s     j'dCj'eD
 &'oo
  	D9		HOO4r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r   )       3 3d 3r   c                *    V P                  RR7       R# )z
L{IOPump.pump} does not call C{resumeProducing} on a L{IPushProducer}
(stream producer) registered with the server transport.
r   r   Nr   rL   s   &r   test_serverStreamingProducer(IOPumpTests.test_serverStreamingProducer)      
 	###2r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r   0  r   r   c                *    V P                  RR7       R# )z
L{IOPump.pump} does not call C{resumeProducing} on a L{IPushProducer}
(stream producer) registered with the client transport.
r   r   Nr   rL   s   &r   test_clientStreamingProducer(IOPumpTests.test_clientStreamingProducer0  r   r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r   7  s     
% 
%4 
%r   c                   a . o\        4       p\        \        \        VR7      w   r#VP                  ^ V3R l4       V P	                  S4       VP                  4        V P                  S4       R# )z5
L{IOPump.pump} advances time in the given L{Clock}.
)clockc                 &   < S P                  R 4      # )T)append)time_passeds   r   <lambda>/IOPumpTests.test_timeAdvances.<locals>.<lambda>>  s    ;#5#5d#;r   N)r	   r   r   	callLaterassertFalser   
assertTrue)r$   r   _r   r   s   &   @r   test_timeAdvancesIOPumpTests.test_timeAdvances7  sU     -hN
1;<%		$r   r   N)
r<   r=   r>   r?   r@   r   r   r   r   rA   r   r   r   r   r     s!    !5F33
% 
%r   r   c                  2    ] tR tRtRtR R ltR R ltRtR# )	ConnectionCompleterTestsiD  zf
L{ConnectionCompleter} can connect a connecting client and a listening
server in a L{MemoryReactor}.
c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   %ConnectionCompleterTests.__annotate__J  s     . .4 .r   c                l    \        \        4       4      pV P                  VP                  4       R4       R# )zd
When no connection for its reactor is pending,
L{ConnectionCompleter.succeedOnce} returns C{None}.
N)r   r
   assertIssucceedOnce)r$   ccs   & r   test_noConnection*ConnectionCompleterTests.test_noConnectionJ  s%    
 !1bnn&-r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r   R  s     	8 	8T 	8r   c                "   \        4       pVP                  ^P\        P                  ! \        4      4       VP                  R^P\        P                  ! \        4      4       \        V4      pV P                  VP                  4       \        4       R# )zw
When a connection to a matched host and port is pending,
L{ConnectionCompleter} returns an L{IOPump} connecting them.
z	127.0.0.1N)r
   	listenTCPr   forProtocolr   
connectTCPr   r   r    r   r   )r$   memr   s   &  r   test_someConnection,ConnectionCompleterTests.test_someConnectionR  s`    
 ob'--h78{B(A(A((KL %bnn.7r   r   N)r<   r=   r>   r?   r@   r   r   rA   r   r   r   r   r   D  s    
.	8 	8r   r   N)r@   
__future__r   typingr   zope.interfacer   twisted.internet.interfacesr   twisted.internet.protocolr   r   r   twisted.internet.taskr	   twisted.internet.testingr
   twisted.test.iosimr   r   r   r   r   twisted.trial.unittestr   r   rC   rZ   r   r   r   r   r   <module>r      s    #  & 5 F F ' 2  ,&8 &8R ]     0a@h a@H@%( @%F8x 8r   