+
    Dfj                        R t ^ RIt^ RIt^ RIHt ^ RIHtHtHt ^ RI	H
t
 ^ RIHtHt ^ RIHt ^ RIHt ^ RIHt ^ R	IHt ^ R
IHt ^ RIHt ^ RIHt  ! R R]P8                  4      t ! R R]P8                  4      t ! R R]P>                  4      t  ! R R]PB                  4      t" ! R R]P8                  4      t# ! R R]PB                  4      t$ ! R R]PB                  4      t% ! R R4      t& ! R R]&]PN                  4      t( ! R R 4      t) ! R! R"]PB                  ])4      t* ! R# R$])4      t+ ! R% R&4      t, ! R' R(]&]PZ                  4      t. ! R) R*]PB                  ]+],4      t/ ! R+ R,]&]P`                  4      t1 ! R- R.]PB                  ]+],4      t2 ! R/ R0]&]Pf                  4      t4 ! R1 R2]PB                  ]+],4      t5 ! R3 R44      t6 ! R5 R6]P8                  4      t7 ! R7 R8]PB                  4      t8 ! R9 R:]Pr                  4      t:R# );z,
Test cases for L{twisted.protocols.basic}.
N)BytesIO)ListOptionalType)verifyObject)protocoltask)	IProducer)connectionDone)basic)	iterbytesFailure)proto_helpers)unittestc                   :   a  ] tR t^t o RtRtR tR tR tRt	V t
R# )FlippingLineTesterzL
A line receiver that flips between line and raw data modes after one byte.
   
c                    . V n         R # Nlinesselfs   &C/usr/lib/python3/dist-packages/twisted/protocols/test/test_basic.py__init__FlippingLineTester.__init__!   s	    
    c                \    V P                   P                  V4       V P                  4        R# )z
Set the mode to raw.
N)r   append
setRawModer   lines   &&r   lineReceivedFlippingLineTester.lineReceived$   s      	

$r   c                6    V P                  VR,          4       R# )z
Set the mode back to line.
:   NNN)setLineModer   datas   &&r   rawDataReceived"FlippingLineTester.rawDataReceived+   s     	b"r   r   N)__name__
__module____qualname____firstlineno____doc__	delimiterr   r#   r*   __static_attributes____classdictcell____classdict__s   @r   r   r      s%      I# #r   r   c                   N   a  ] tR t^2t o RtRt^@tR
R ltR tR t	R t
R tR	tV tR# )
LineTestera  
A line receiver that parses data received and make actions on some tokens.

@type delimiter: C{bytes}
@ivar delimiter: character used between received lines.
@type MAX_LENGTH: C{int}
@ivar MAX_LENGTH: size of a line when C{lineLengthExceeded} will be called.
@type clock: L{twisted.internet.task.Clock}
@ivar clock: clock simulating reactor callLater. Pass it to constructor if
    you want to use the pause/rawpause functionalities.
r   Nc                    Wn         R# )z0
If given, use a clock to make callLater calls.
N)clock)r   r9   s   &&r   r   LineTester.__init__B   s	     
r   c                    . V n         R# z+
Create/clean data received on connection.
Nreceivedr   s   &r   connectionMadeLineTester.connectionMadeH        r   c                   V P                   P                  V4       VR8X  d   V P                  4        R# VR8X  d9   V P                  4        V P                  P                  ^ V P                  4       R# VR8X  dd   V P                  4        V P                  4        V P                   P                  R4       V P                  P                  ^ V P                  4       R# VR8X  d   V P                  4        R# VR,          R8X  d   \        VR,          4      V n	        R# VP                  R4      '       d   V P                  P                  V R	4       R# VP                  R
4      '       d   V P                  P                  4        R# R# )zd
Receive line and make some action for some tokens: pause, rawpause,
stop, len, produce, unproduce.
r      pause   rawpause   stop:N   Ns   len :rF   NN   produceF	   unproduceN)r>   r   r    pauseProducingr9   	callLaterresumeProducingstopProducingintlength
startswith	transportregisterProducerunregisterProducerr!   s   &&r   r#   LineTester.lineReceivedN   s   
 	T"3;OOX!JJ  D$8$89[ !OOMM  %JJ  D$8$89W_ "X d2h-DK__Z((NN++D%8__\**NN--/ +r   c                   VRV P                    WP                   R r!V P                   \        V4      ,
          V n         V P                  R,          V,           V P                  R&   V P                   ^ 8X  d   V P                  V4       R# R# )zR
Read raw data, until the quantity specified by a previous 'len' line is
reached.
N)rN   lenr>   r'   )r   r)   rests   && r   r*   LineTester.rawDataReceivedg   sn    
 -DKK(${{}*=dkkCI- MM"-4b;;!T" r   c                    \        V4      V P                  ^,           8  d'   V P                  WP                  ^,           R 4       R# R# )z,
Adjust line mode when long lines received.
N)rV   
MAX_LENGTHr'   r!   s   &&r   lineLengthExceededLineTester.lineLengthExceededr   s;     t9t**T//A"5"789 +r   )r9   rN   r>   r   )r,   r-   r.   r/   r0   r1   rZ   r   r?   r#   r*   r[   r2   r3   r4   s   @r   r7   r7   2   s4     
 IJ02	#: :r   r7   c                   8   a  ] tR t^zt o RtRt^@tR tR tRt	V t
R# )LineOnlyTesterz!
A buffering line only receiver.
r   c                    . V n         R# r<   r=   r   s   &r   r?   LineOnlyTester.connectionMade   rA   r   c                <    V P                   P                  V4       R# )z
Save received data.
Nr>   r   r!   s   &&r   r#   LineOnlyTester.lineReceived   s     	T"r   r=   N)r,   r-   r.   r/   r0   r1   rZ   r?   r#   r2   r3   r4   s   @r   r^   r^   z   s%      IJ# #r   r^   c                      a  ] tR t^t o RtRt. ROtR tRt. ROt	]	R.,           t
R tRt. ROt. ROtR tR	t. RO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# )LineReceiverTestszP
Test L{twisted.protocols.basic.LineReceiver}, using the C{LineTester}
wrapper.
s   len 10

0123456789len 5

1234
len 20
foo 123

0123456789
012345678len 0
foo 5

1234567890123456789012345678901234567890123456789012345678901234567890
len 1

ac                   \        ^^
4       F  p\        P                  ! 4       p\        4       pVP	                  \
        P                  ! V4      4       \        \        V P                  4      V,          ^,           4       F7  pV P                  WA,          V^,           V,           pVP                  V4       K9  	  V P                  V P                  VP                  4       K  	  R# )zT
Test buffering for different packet size, checking received matches
expected data.
N)ranger   StringIOWithoutClosingr7   makeConnectionr   FileWrapperrV   bufferdataReceivedassertEqualoutputr>   r   packet_sizetaiss   &     r   test_bufferLineReceiverTests.test_buffer   s    
 !B<K446AAX11!453t{{+{:Q>?KK1q5K2GHq! @ T[[!**5 (r   s!   twiddle1
twiddle2
pause
twiddle3
   twiddle3c                l   \        ^^
4       EF"  p\        P                  ! 4       p\        P                  ! 4       p\        V4      pVP                  \        P                  ! V4      4       \        \        V P                  4      V,          ^,           4       F7  pV P                  WQ,          V^,           V,           pVP                  V4       K9  	  V P                  V P                  VP                  4       VP                  ^ 4       V P                  V P                   VP                  4       EK%  	  R# )zW
Test pause inside data receiving. It uses fake clock to see if
pausing/resuming work.
N)rg   r   rh   r   Clockr7   ri   r   rj   rV   pauseBufrl   rm   pauseOutput1r>   advancepauseOutput2r   rp   rq   r9   rr   rs   rt   s   &      r   test_pausingLineReceiverTests.test_pausing   s    
 !B<K446AJJLE5!AX11!453t}}-<q@AMM!/QUk4IJq! B T..

;MM!T..

; (r   s/   twiddle1
twiddle2
len 5
rawpause
12345twiddle3
c                l   \        ^^
4       EF"  p\        P                  ! 4       p\        P                  ! 4       p\        V4      pVP                  \        P                  ! V4      4       \        \        V P                  4      V,          ^,           4       F7  pV P                  WQ,          V^,           V,           pVP                  V4       K9  	  V P                  V P                  VP                  4       VP                  ^ 4       V P                  V P                   VP                  4       EK%  	  R# )z'
Test pause inside raw date receiving.
N)rg   r   rh   r   ry   r7   ri   r   rj   rV   rawpauseBufrl   rm   rawpauseOutput1r>   r|   rawpauseOutput2r~   s   &      r   test_rawPausing!LineReceiverTests.test_rawPausing   s     !B<K446AJJLE5!AX11!453t//0K?!CD$$Q_A7LMq! E T111::>MM!T111::> (r   s"   twiddle1
twiddle2
stop
more
stuff
c                   \        ^^
4       F  p\        P                  ! 4       p\        4       pVP	                  \
        P                  ! V4      4       \        \        V P                  4      V,          ^,           4       F7  pV P                  WA,          V^,           V,           pVP                  V4       K9  	  V P                  V P                  VP                  4       K  	  R# )z
Test stop inside producing.
N)rg   r   rh   r7   ri   r   rj   rV   stop_bufrl   rm   stop_outputr>   ro   s   &     r   test_stopProducing$LineReceiverTests.test_stopProducing   s     !B<K446AAX11!453t}}-<q@AMM!/QUk4IJq! B T--qzz: (r   c                    \        4       p\        P                  ! 4       pVP                  \        P
                  ! V4      4       VP                  R4       V P                  VP                  . RO4       R# )z&
Test produce/unproduce in receiving.
s&   produce
hello world
unproduce
goodbye
N)rG   s   hello worldrH      goodbye)	r7   r   rh   ri   r   rj   rl   rm   r>   )r   rr   rq   s   &  r   test_lineReceiverAsProducer-LineReceiverTests.test_lineReceiverAsProducer  sW     L002	--a01	DEJJN	
r   c                n    ! R R\         P                  4      pV! 4       pVP                  ! R4       V P                  VP                  R4       V P                  VP
                  R4       VP                  ! R4       V P                  VP                  R4       V P                  VP
                  R4       R	# )
z
L{LineReceiver.clearLineBuffer} removes all buffered data and returns
it as a C{bytes} and can be called from beneath C{dataReceived}.
c                   &   a  ] tR tRt o R tRtV tR# )@LineReceiverTests.test_clearLineBuffer.<locals>.ClearingReceiveri  c                <    Wn         V P                  4       V n        R # r   )r"   clearLineBufferrW   r!   s   &&r   r#   MLineReceiverTests.test_clearLineBuffer.<locals>.ClearingReceiver.lineReceived  s     	 002	r   )r"   rW   N)r,   r-   r.   r/   r#   r2   r3   r4   s   @r   ClearingReceiverr     s     3 3r   r   s   foo
bar
baz   foos   bar
bazs   quux
s   quuxr   N)r   LineReceiverrl   rm   r"   rW   )r   r   r   s   &  r   test_clearLineBuffer&LineReceiverTests.test_clearLineBuffer  s    	3u11 	3
 $%23/6 	k*0,r   c                L   \        4       p\        P                  ! 4       pVP                  \        P
                  ! V4      4       \        P                  ! 4       pVP                  RV,          4       V P                  RV,          RP                  VP                  4      4       R# )z3
Test switching modes many times on the same data.
s   x
x   xr   N)r   r   rh   ri   r   rj   sysgetrecursionlimitrl   rm   joinr   )r   protorP   limits   &   r   test_stackRecursion%LineReceiverTests.test_stackRecursion*  st     #$!88:	X11)<=%%'7U?+sxx'<=r   c                   \         P                  ! 4       p\        P                  ! 4       pVP	                  V4       VP                  RVP                  ^,           ,          R,           4       V P                  VP                  4       R# z`
C{LineReceiver} disconnects the transport if it receives a line longer
than its C{MAX_LENGTH}.
r      
rN	r   r   r   StringTransportri   rl   rZ   
assertTruedisconnectingr   r   rP   s   &  r   test_maximumLineLength(LineReceiverTests.test_maximumLineLength5  c    
 ""$!113	Y'45#3#3a#788CD	//0r   c                   \        4       p^Vn        \        P                  ! 4       pVP	                  V4       RVP                  ^,
          ,          pVP                  V4       VP                  VP                  RR 4       VP                  VP                  RR V,           4       V P                  VP                  4       V P                  \        VP                  4      ^4       V P                  W1P                  ^ ,          4       R# )aF  
C{LineReceiver} doesn't disconnect the transport when it
receives a finished line as long as its C{MAX_LENGTH}, when
the second-to-last packet ended with a pattern that could have
been -- and turns out to have been -- the start of a
delimiter, and that packet causes the total input to exceed
C{MAX_LENGTH} + len(delimiter).
r   NrU   )r7   rZ   r   r   ri   rl   r1   assertFalser   rm   rV   r>   )r   r   rq   r"   s   &   r   &test_maximumLineLengthPartialDelimiter8LineReceiverTests.test_maximumLineLengthPartialDelimiter@  s     ))+Qu''!+,4 5??3B/05??23/$67)U^^,a0~~a01r   c                `   \         P                  ! 4       pRVn        \        P                  ! 4       pVP                  V4       VP                  RVP                  ,          VP                  R\        VP                  4      ^,
           ,           4       V P                  VP                  4       R# )a  
C{LineReceiver} doesn't disconnect the transport it if
receives a non-finished line whose length, counting the
delimiter, is longer than its C{MAX_LENGTH} but shorter than
its C{MAX_LENGTH} + len(delimiter). (When the first part that
exceeds the max is the beginning of the delimiter.)
s   
r   N)r   r   r1   r   r   ri   rl   rZ   rV   r   r   r   s   &  r   (test_notQuiteMaximumLineLengthUnfinished:LineReceiverTests.test_notQuiteMaximumLineLengthUnfinishedV  s     ""$ "!113	Y'E$$$8R#eoo:NQR:R(SS	
 	001r   c                    \         P                  ! 4       pR Vn        \        P                  ! 4       pVP                  V4       VP                  4        VP                  R4      pV P                  V\        4       R# )zN
C{LineReceiver.dataReceived} forwards errors returned by
C{rawDataReceived}.
c                     \        R 4      # )oops)RuntimeErrorr)   s   &r   <lambda>5LineReceiverTests.test_rawDataError.<locals>.<lambda>o  s	    \&-Ar   s   dataN)
r   r   r*   r   r   ri   r    rl   assertIsInstancer   )r   r   rP   whys   &   r   test_rawDataError#LineReceiverTests.test_rawDataErrori  sb    
 ""$ A!113	Y'  )c<0r   c                r    \         P                  ! 4       pV P                  \        VP                  R4       R# )zq
When L{LineReceiver.rawDataReceived} is not overridden in a
subclass, calling it raises C{NotImplementedError}.
fooN)r   r   assertRaisesNotImplementedErrorr*   r   r   s   & r   "test_rawDataReceivedNotImplemented4LineReceiverTests.test_rawDataReceivedNotImplementedv  s+    
 ""$-u/D/DeLr   c                r    \         P                  ! 4       pV P                  \        VP                  R4       R# )zn
When L{LineReceiver.lineReceived} is not overridden in a subclass,
calling it raises C{NotImplementedError}.
r   N)r   r   r   r   r#   r   s   & r   test_lineReceivedNotImplemented1LineReceiverTests.test_lineReceivedNotImplemented~  s+    
 ""$-u/A/A5Ir    N)s   len 10
   0123456789   len 5s   1234
s   len 20s   foo 123s   0123456789
012345678s   len 0s   foo 5r   s   67890s   len 1   a)   twiddle1   twiddle2rC   )r   r   r   rD   r   )r   r   r   rD   s   12345rw   )r   r   rE   )r,   r-   r.   r/   r0   rk   rn   ru   rz   r{   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r2   r3   r4   s   @r   re   re      s     
F$F 6 8H7L;-/L<" JKLOO?  :H5K;

-,	>	12,2&1MJ Jr   re   c                   6   a  ] tR tRt o RtR tR tR tRtV t	R# )ExcessivelyLargeLineCatcheri  z
Helper for L{LineReceiverLineLengthExceededTests}.

@ivar longLines: A L{list} of L{bytes} giving the values
    C{lineLengthExceeded} has been called with.
c                    . V n         R # r   	longLinesr   s   &r   r?   *ExcessivelyLargeLineCatcher.connectionMade  s	    r   c                    R# )z
Disregard any received lines.
Nr   r!   s   &&r   r#   (ExcessivelyLargeLineCatcher.lineReceived  s    r   c                <    V P                   P                  V4       R# )z6
Record any data that exceeds the line length limits.
N)r   r   r(   s   &&r   r[   .ExcessivelyLargeLineCatcher.lineLengthExceeded  s     	d#r   r   N)
r,   r-   r.   r/   r0   r?   r#   r[   r2   r3   r4   s   @r   r   r     s     
$ $r   r   c                   N   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V tR# )#LineReceiverLineLengthExceededTestsi  zG
Tests for L{twisted.protocols.basic.LineReceiver.lineLengthExceeded}.
c                    \        4       V n        ^V P                  n        \        P                  ! 4       V n        V P                  P                  V P
                  4       R# )   N)r   r   rZ   r   r   rP   ri   r   s   &r   setUp)LineReceiverLineLengthExceededTests.setUp  s>    02
 !

&668

!!$..1r   c                    RV P                   P                  ^,          ^,           ,          pV P                   P                  V4       V P                  V.V P                   P                  4       R# )z
If more bytes than C{LineReceiver.MAX_LENGTH} arrive containing no line
delimiter, all of the bytes are passed as a single string to
L{LineReceiver.lineLengthExceeded}.
r   N)r   rZ   rl   rm   r   r   	excessives   & r   test_longUnendedLine8LineReceiverLineLengthExceededTests.test_longUnendedLine  sP     DJJ11A59:	

	*)djj&:&:;r   c                $   RV P                   P                  ^,          ^,           ,          pV P                   P                  RV P                   P                  ,           V,           4       V P	                  V.V P                   P
                  4       R# )a  
If L{LineReceiver.dataReceived} is called with bytes representing a
short line followed by bytes that exceed the length limit without a
line delimiter, L{LineReceiver.lineLengthExceeded} is called with all
of the bytes following the short line's delimiter.
r   N)r   rZ   rl   r1   rm   r   r   s   & r   test_longLineAfterShortLine?LineReceiverLineLengthExceededTests.test_longLineAfterShortLine  sd     DJJ11A59:	

tzz';'; ;i GH)djj&:&:;r   c                6   V P                   P                  P                  RV P                   P                  ^,          ^,           ,          .^,          4      pV P                   P	                  V4       V P                  V.V P                   P                  4       R# )z
If L{LineReceiver.dataReceived} is called with more than
C{LineReceiver.MAX_LENGTH} bytes containing a line delimiter somewhere
not in the first C{MAX_LENGTH} bytes, the entire byte string is passed
to L{LineReceiver.lineLengthExceeded}.
r   N)r   r1   r   rZ   rl   rm   r   r   s   & r   test_longLineWithDelimiter>LineReceiverLineLengthExceededTests.test_longLineWithDelimiter  sr     JJ((--TZZ**Q.234q8
	 	

	*)djj&:&:;r   c                $   RV P                   P                  ^,          ^,           ,          V P                   P                  ,           ^,          pV P                   P                  V4       V P	                  V.V P                   P
                  4       R# )z
If L{LineReceiver.dataReceived} is called with more than
C{LineReceiver.MAX_LENGTH} bytes containing multiple line delimiters
somewhere not in the first C{MAX_LENGTH} bytes, the entire byte string
is passed to L{LineReceiver.lineLengthExceeded}.
r   N)r   rZ   r1   rl   rm   r   r   s   & r   test_multipleLongLines:LineReceiverLineLengthExceededTests.test_multipleLongLines  se     TZZ22Q6:;djj>R>RRVWW	

	*)djj&:&:;r   c                   \         P                  ! 4       p\        P                  ! 4       pVP	                  V4       VP                  RVP                  ^,           ,          R,           4       V P                  VP                  4       R# r   r   r   s   &  r   r   :LineReceiverLineLengthExceededTests.test_maximumLineLength  r   r   c                *   \         P                  ! 4       p\        P                  ! 4       pVP	                  V4       VP                  RVP                  \        VP                  4      ,           ,          4       V P                  VP                  4       R# )zm
C{LineReceiver} disconnects the transport it if receives a non-finished
line longer than its C{MAX_LENGTH}.
r   N)r   r   r   r   ri   rl   rZ   rV   r1   r   r   r   s   &  r   test_maximumLineLengthRemainingCLineReceiverLineLengthExceededTests.test_maximumLineLengthRemaining  sg    
 ""$!113	Y'45#3#3c%//6J#JKL	//0r   )r   rP   N)r,   r-   r.   r/   r0   r   r   r   r   r   r   r   r2   r3   r4   s   @r   r   r     s2     2<	<<	<	1	1 	1r   r   c                   :   a  ] tR tRt o RtRtR tR tR tRt	V t
R# )	LineOnlyReceiverTestsi  z8
Tests for L{twisted.protocols.basic.LineOnlyReceiver}.
s7   foo
    bleakness
    desolation
    plastic forks
    c                0   \         P                  ! 4       p\        4       pVP                  V4       \	        V P
                  4       F  pVP                  V4       K  	  V P                  VP                  V P
                  P                  R4      RR 4       R# )zG
Test buffering over line protocol: data received should match buffer.
r   NrU   )
r   r   r^   ri   r   rk   rl   rm   r>   split)r   rq   rr   cs   &   r   ru   !LineOnlyReceiverTests.test_buffer  sq     ))+	4;;'ANN1 (T[[%6%6u%=cr%BCr   c                0   \        4       p\        P                  ! 4       pVP                  V4       VP	                  RVP
                  \        VP                  4      ,           ^,           ,          R,           4       V P                  VP                  4       R# )zu
C{LineOnlyReceiver} disconnects the transport if it receives a
line longer than its C{MAX_LENGTH} + len(delimiter).
r   r   N)
r^   r   r   ri   rl   rZ   rV   r1   r   r   r   s   &  r   !test_greaterThanMaximumLineLength7LineOnlyReceiverTests.test_greaterThanMaximumLineLength  sp    
  !113	Y'E$$s5??';;a?@8K	
 		//0r   c                r    \         P                  ! 4       pV P                  \        VP                  R4       R# )zr
When L{LineOnlyReceiver.lineReceived} is not overridden in a subclass,
calling it raises C{NotImplementedError}.
r   N)r   LineOnlyReceiverr   r   r#   r   s   & r   r   5LineOnlyReceiverTests.test_lineReceivedNotImplemented  s+    
 &&(-u/A/A5Ir   r   N)r,   r-   r.   r/   r0   rk   ru   r   r   r2   r3   r4   s   @r   r   r     s(     F	D1J Jr   r   c                   L   a  ] tR tRt o R tR t^2t^ t]3V 3R lR llt	Rt
V tR# )	TestMixini  c                    . V n         R # r   r=   r   s   &r   r?   TestMixin.connectionMade  s	    r   c                <    V P                   P                  V4       R # r   rb   r   rt   s   &&r   stringReceivedTestMixin.stringReceived  s    Qr   c                $   < V ^8  d   QhRS[ RR/# )   reasonreturnNr   )formatr5   s   "r   __annotate__TestMixin.__annotate__#  s      W $ r   c                    ^V n         R# )r&   N)closed)r   r
  s   &&r   connectionLostTestMixin.connectionLost#  s	    r   )r  r>   N)r,   r-   r.   r/   r?   r  rZ   r  r
   r  r2   r3   r4   s   @r   r  r    s-       JF/=   r   r  c                   &   a  ] tR tRt o R tRtV tR# )TestNetstringi'  c                r    V P                   P                  V4       V P                  P                  V4       R # r   )r>   r   rP   writer  s   &&r   r  TestNetstring.stringReceived(  s&    QQr   r   N)r,   r-   r.   r/   r  r2   r3   r4   s   @r   r  r  '  s        r   r  c                   @   a  ] tR tRt o . tRtR tR tV 3R ltRt	V t
R# )LPTestCaseMixini-  Nc                r    \         P                  ! 4       pV P                  4       pVP                  V4       V# )zl
Return a new instance of C{self.protocol} connected to a new instance
of L{proto_helpers.StringTransport}.
)r   r   r   ri   )r   rq   rr   s   &  r   getProtocolLPTestCaseMixin.getProtocol1  s0    
 ))+MMO	r   c                    V P                    F[  pV P                  4       p\        V4       F  pVP                  V4       K  	  V P	                  VP
                  P                  4       K]  	  R# )z?
Assert that illegal strings cause the transport to be closed.
N)illegalStringsr  r   rl   r   rP   r   r   rt   rr   s   &   r   test_illegalLPTestCaseMixin.test_illegal;  sR     $$A  "Aq\q! "OOAKK556	 %r   c                P   < V ^8  d   Qh/ S[ S[S[,          ,          ;R&   R;R&   # )r	  r  !Optional[Type[protocol.Protocol]]r   r   r   bytes)r  r5   s   "r   r  LPTestCaseMixin.__annotate__-  s$     T%[). 18 r   r   )r,   r-   r.   r/   r  r   r  r!  __annotate_func__r2   r3   r4   s   @r   r  r  -  s      ,.N48H7  r   r  c                      a  ] tR tRt o Rt. ROt. ROt]tR t	R t
R tR tR tR tR	 tR
 tR tR tR tR t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# )NetstringReceiverTestsiF  z9
Tests for L{twisted.protocols.basic.NetstringReceiver}.
c                    \         P                  ! 4       V n        \        4       V n        V P                  P                  V P                  4       R # r   )r   r   rP   r  netstringReceiverri   r   s   &r   r   NetstringReceiverTests.setUpV  s4    &668!.--dnn=r   c                   \        ^^
4       F  p\        P                  ! 4       p\        4       pRVn        VP                  V4       V P                   F  pVP                  V4       K  	  VP                  4       p\        \        V4      V,          ^,           4       F7  pWVV,          V^,           V,           pV'       g   K&  VP                  V4       K9  	  V P                  VP                  V P                  4       K  	  R# )z9
Strings can be received in chunks of different lengths.
i  N)rg   r   r   r  rZ   ri   strings
sendStringvaluerV   rl   rm   r>   )r   rp   rq   rr   rt   outrs   s   &      r   ru   "NetstringReceiverTests.test_buffer[  s     !B<K--/AAALQ\\Q "'')C3s8{2Q67K1q5K*?@1NN1% 8 QZZ6 (r   c                    V P                   P                  R4       V P                  V P                   P                  R.4       R# )z5
Empty netstrings (with length '0') can be received.
s   0:,r   Nr,  rl   rm   r>   r   s   &r   test_receiveEmptyNetstring1NetstringReceiverTests.test_receiveEmptyNetstringm  s6     	++F3//883%@r   c                    V P                   P                  R4       V P                  V P                   P                  R.4       R# )z+
One-character netstrings can be received.
   1:a,r   Nr5  r   s   &r   test_receiveOneCharacter/NetstringReceiverTests.test_receiveOneCharactert  s6     	++G4//884&Ar   c                    V P                   P                  R4       V P                  V P                   P                  R.4       R# )z+
Two-character netstrings can be received.
s   2:ab,   abNr5  r   s   &r   test_receiveTwoCharacters0NetstringReceiverTests.test_receiveTwoCharacters{  s6     	++H5//885'Br   c                    V P                   P                  R4       V P                  V P                   P                  R.4       R# )z
Netstrings with embedded netstrings. This test makes sure that
the parser does not become confused about the ',' and ':'
characters appearing inside the data portion of the netstring.
s   4:1:a,,r9  Nr5  r   s   &r   test_receiveNestedNetstring2NetstringReceiverTests.test_receiveNestedNetstring  s6     	++J7//887)Dr   c                    V P                   P                  R4       V P                  V P                  P                  4       R# )z<
Netstrings containing more data than expected are refused.
s   2:aaa,Nr,  rl   r   rP   r   r   s   &r   test_moreDataThanSpecified1NetstringReceiverTests.test_moreDataThanSpecified  s.     	++I6445r   c                    V P                   P                  R4       V P                  V P                  P                  4       R# )zk
Netstrings that should be empty according to their length
specification are refused if they contain data.
s   0:a,NrD  r   s   &r   $test_moreDataThanSpecifiedBorderCase;NetstringReceiverTests.test_moreDataThanSpecifiedBorderCase  .    
 	++G4445r   c                    V P                   P                  R4       V P                  V P                  P                  4       R# )zH
Netstrings without leading digits that specify the length
are refused.
s   :aaa,NrD  r   s   &r   test_missingNumber)NetstringReceiverTests.test_missingNumber  .    
 	++H5445r   c                    V P                   P                  R4       V P                  V P                  P                  4       R# )zO
Netstrings without a colon between length specification and
data are refused.
s   3aaa,NrD  r   s   &r   test_missingColon(NetstringReceiverTests.test_missingColon  rN  r   c                    V P                   P                  R4       V P                  V P                  P                  4       R# )zA
Netstrings that have no leading digits nor a colon are
refused.
s   aaa,NrD  r   s   &r   test_missingNumberAndColon1NetstringReceiverTests.test_missingNumberAndColon  rJ  r   c                    V P                   P                  R4       V P                  V P                  P                  4       R# )z1
Netstrings consisting only of data are refused.
s   aaaNrD  r   s   &r   test_onlyData$NetstringReceiverTests.test_onlyData  s.     	++F3445r   c                   V P                   P                  R4       V P                   P                  R4       V P                  V P                   P                  R.4       V P	                  V P                   P                  4       4       R# )z-
Netstrings can be received in two portions.
s   4:aas   aa,s   aaaaN)r,  rl   rm   r>   r   _payloadCompleter   s   &r   test_receiveNetstringPortions_16NetstringReceiverTests.test_receiveNetstringPortions_1  se     	++G4++F3//887)D..??ABr   c                    R F  pV P                   P                  V4       K   	  V P                  V P                   P                  R.4       R# )zv
Netstrings can be received in more than two portions, even if
the length specification is split across two portions.
r   N)   1s   0:01234s   56789   ,r5  r   parts   & r   test_receiveNetstringPortions_26NetstringReceiverTests.test_receiveNetstringPortions_2  s@    
 7D""//5 7//88=/Jr   c                    R F  pV P                   P                  V4       K   	  V P                  V P                   P                  R.4       R# )z5
Netstrings can be received one character at a time.
r=  N)   2   :r      br^  r5  r_  s   & r   test_receiveNetstringPortions_36NetstringReceiverTests.test_receiveNetstringPortions_3  s@     3D""//5 3//885'Br   c                b   V P                   P                  R4       V P                  V P                   P                  4       4       V P	                  V P                   P
                  R.4       V P                   P                  R4       V P	                  V P                   P
                  RR.4       R# )z
A stream of two netstrings can be received in two portions,
where the first portion contains the complete first netstring
and the length specification of the second netstring.
s   1:a,1r   s   :b,rf  N)r,  rl   r   rY  rm   r>   r   s   &r   test_receiveTwoNetstrings0NetstringReceiverTests.test_receiveTwoNetstrings  s     	++H5..??AB//884&A++F3//884,Gr   c                   V P                   P                  ^,           pV P                   P                  RP                  \	        V4      RRV,          34      4       V P                  V P                  P                  4       R# )z[
Netstrings with a length specification exceeding the specified
C{MAX_LENGTH} are refused.
r   re  r   N)r,  rZ   rl   r   r&  r   rP   r   )r   tooLongs   & r   test_maxReceiveLimit+NetstringReceiverTests.test_maxReceiveLimit  sa    
 ((33a7++HHeGndD7N;<	
 	445r   c                    RV P                   n        V P                   P                  4        V P                  V P                   P                  ^4       R# )z_
C{_consumeLength} returns the expected length of the
netstring, including the trailing comma.
   12:N)r,  _remainingData_consumeLengthrm   _expectedPayloadSizer   s   &r   test_consumeLength)NetstringReceiverTests.test_consumeLength  s@    
 17---///DDbIr   c                    RV P                   n        ^V P                   n        V P                   P                  4        V P	                  V P                   P
                  ^4       R# )zt
C{_consumeLength} works as expected if the length specification
contains the value of C{MAX_LENGTH} (border case).
rq  N)r,  rr  rZ   rs  rm   rt  r   s   &r   test_consumeLengthBorderCase14NetstringReceiverTests.test_consumeLengthBorderCase1  sN    
 17-,.)--///DDbIr   c                    RV P                   n        ^V P                   n        V P                  \        P
                  V P                   P                  4       R# )z
C{_consumeLength} raises a L{basic.NetstringParseError} if
the length specification exceeds the value of C{MAX_LENGTH}
by 1 (border case).
rq  Nr,  rr  rZ   r   r   NetstringParseErrorrs  r   s   &r   test_consumeLengthBorderCase24NetstringReceiverTests.test_consumeLengthBorderCase2  sE     17-,.)%%t'='='L'L	
r   c                    RV P                   n        ^V P                   n        V P                  \        P
                  V P                   P                  4       R# )z
C{_consumeLength} raises a L{basic.NetstringParseError} if
the length specification exceeds the value of C{MAX_LENGTH}
by more than 1.
s   1000:Nr{  r   s   &r   test_consumeLengthBorderCase34NetstringReceiverTests.test_consumeLengthBorderCase3	  sE     19-,.)%%t'='='L'L	
r   c                r    \         P                  ! 4       pV P                  \        VP                  R4       R# )zu
When L{NetstringReceiver.stringReceived} is not overridden in a
subclass, calling it raises C{NotImplementedError}.
r   N)r   NetstringReceiverr   r   r  r   s   & r   !test_stringReceivedNotImplemented8NetstringReceiverTests.test_stringReceivedNotImplemented  s+    
 '')-u/C/CUKr   )r,  rP   N)   hello   worlds   hows   ares   you123s   :todays  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)s   9999999999999999999999s   abcs   4:abcdes7   51:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab,)!r,   r-   r.   r/   r0   r/  r  r  r   r   ru   r6  r:  r>  rA  rE  rH  rL  rP  rS  rV  rZ  ra  rg  rj  rn  ru  rx  r}  r  r  r2   r3   r4   s   @r   r*  r*  F  s      UGN H>
7$ABCE666666CKC
H	6JJ



L Lr   r*  c                   d   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R	 tV 3R
 ltRtV tR# )IntNTestCaseMixini  z,
TestCase mixin for int-prefixed protocols.
Nc           	     <   V P                  4       pV P                   FU  p\        \        P                  ! VP
                  \        V4      4      V,           4       F  pVP                  V4       K  	  KW  	  V P                  VP                  V P                  4       R# )z.
Test receiving data find the same data send.
N)
r  r/  r   structpackstructFormatrV   rl   rm   r>   )r   r   rt   r   s   &   r   test_receiveIntNTestCaseMixin.test_receive(  sn     Av{{1>>3q6BQFGq! H  	T\\2r   c                    V P                    FR  pV P                  4       p\        V4       F  pVP                  V4       K  	  V P	                  VP
                  . 4       KT  	  R# )z;
Send partial data, nothing should be definitely received.
N)partialStringsr  r   rl   rm   r>   r  s   &   r   test_partialIntNTestCaseMixin.test_partial2  sP     $$A  "Aq\q! "QZZ,	 %r   c                    V P                  4       pVP                  R4       V P                  VP                  P	                  4       \
        P                  ! VP                  ^4      R,           4       R# )z"
Test sending data over protocol.
N   bbbbbbbbbbbbbbbb)r  r0  rm   rP   r1  r  r  r  r   r   s   & r   	test_sendIntNTestCaseMixin.test_send<  sR     	YKKQ^^R!@9!L	
r   c                    . pV P                  4       pVP                  Vn        ^
Vn        VP	                  \
        P                  ! VP                  ^4      4       V P                  V^.4       R# )z
When a length prefix is received which is greater than the protocol's
C{MAX_LENGTH} attribute, the C{lengthLimitExceeded} method is called
with the received length prefix.
N)	r  r   lengthLimitExceededrZ   rl   r  r  r  rm   )r   rN   r   s   &  r   test_lengthLimitExceeded*IntNTestCaseMixin.test_lengthLimitExceededF  sW      &	v{{1>>267"&r   c                    V P                  4       p^
Vn        VP                  \        P                  ! VP
                  ^4      R,           4       V P                  VP                  . 4       R# )z
If a length prefix for a string longer than C{MAX_LENGTH} is delivered
to C{dataReceived} at the same time as the entire string, the string is
not passed to C{stringReceived}.
Ns   xxxxxxxxxxx)r  rZ   rl   r  r  r  rm   r>   r  s   & r   test_longStringNotDelivered-IntNTestCaseMixin.test_longStringNotDeliveredS  sM     	v{{1>>26BCR(r   c                r    \         P                  ! 4       pV P                  \        VP                  R4       R# )zv
When L{IntNStringReceiver.stringReceived} is not overridden in a
subclass, calling it raises C{NotImplementedError}.
r   N)r   IntNStringReceiverr   r   r  r   s   & r   r  3IntNTestCaseMixin.test_stringReceivedNotImplemented^  s+    
 ((*-u/C/CUKr   c                   < V ^8  d   Qh/ R;R&   S[ S[S[,          ,          ;R&   S[ S[S[,          ,          ;R&   S[ S[S[,          ,          ;R&   # )r	  r$  r   r/  r  r  r%  )r  r5   s   "r   r  IntNTestCaseMixin.__annotate__  sT     
 28  d5k")  T%[)0  T%[)0 r   r   )r,   r-   r.   r/   r0   r   r/  r  r  r  r  r  r  r  r  r(  r2   r3   r4   s   @r   r  r    sG      59H%)G,0N,0N3-
'	)LA  r   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	# )
RecvdAttributeMixinig  z
Mixin defining tests for string receiving protocols with a C{recvd}
attribute which should be settable by application code, to be combined with
L{IntNTestCaseMixin} on a L{TestCase} subclass
c                d    \         P                  ! VP                  \        V4      4      V,           # )zO
Return C{data} prefixed with message length in C{protocol.structFormat}
form.
)r  r  r  rV   )r   r   r)   s   &&&r   makeMessageRecvdAttributeMixin.makeMessagen  s$    
 {{800#d)<tCCr   c                >  aa . oV P                  4       oVV3R lpVSn        \        P                  ! SP                  ^4      R,           p\        P                  ! SP                  ^4      R,           pSP                  W#,           4       V P                  SV.4       R# )z
In stringReceived, recvd contains the remaining data that was passed to
dataReceived that was not part of the current message.
c                 >   < SP                  SP                  4       R # r   r   recvd)receivedStringr   results   &r   r  KRecvdAttributeMixin.test_recvdContainsRemainingData.<locals>.stringReceived}  s    MM!''"r   N   aaaaas   bbbb)r  r  r  r  r  rl   rm   )r   r  completeMessageincompleteMessager   r  s   &   @@r   test_recvdContainsRemainingData3RecvdAttributeMixin.test_recvdContainsRemainingDatau  s}    
 	# * ++anna8HE"KK:hG	:;"3!45r   c                  aaa	 V P                  4       o. o	RpV P                  SV4      oVVV	3R lpVSn        RpRpV P                  SV4      pV P                  SV4      pSP                  WV,           4       V P	                  S	W1.4       R# )zr
In stringReceived, if recvd is changed, messages should be parsed from
it rather than the input to dataReceived.
c                 H   < S'       g   SSn         SP                  V 4       R # r   )r  r   )r  messageCr   r  s   &r   r  =RecvdAttributeMixin.test_recvdChanged.<locals>.stringReceived  s    "MM.)r   Ns   cccccr  s   bbbbb)r  r  r  rl   rm   )
r   payloadCr  payloadApayloadBmessageAmessageBr  r   r  s
   &      @@@r   test_recvdChanged%RecvdAttributeMixin.test_recvdChanged  s    
 ##Ax0	*
 *##Ax0##Ax0	x*+(!56r   c                  aaa V P                  4       o. pRoV P                   F5  pVP                  V P                  SV4      4       VP                  S4       K7  	  . oVVV3R lpVSn        SP                  RP                  V4      4       SP                  R4       V P                  SV P                  4       V P                  SP                  R4       R# )z
Data already parsed by L{IntNStringReceiver.dataReceived} is not
reparsed if C{stringReceived} consumes some of the
L{IntNStringReceiver.recvd} buffer.
s       c                 d   < SP                  V 4       SP                  \        S4      R  Sn        R # r   )r   r  rV   )r  SWITCHr   r  s   &r   r  :RecvdAttributeMixin.test_switching.<locals>.stringReceived  s%    MM.)++c&km4EKr   r      N)	r  r/  r   r  r  rl   r   rm   r  )r   mixrt   r  r  r   r  s   &   @@@r   test_switching"RecvdAttributeMixin.test_switching  s       "$AJJt''q12JJv  	5  .388C=) 	7#.g.r   c                8  aa V P                  4       oRp\        V4      ^,
          Sn        V P                  SV4      p. oVV3R lpVSn        SP                  V4       V P                  S^ ,          \        V4      4       V P                  S^,          V4       R# )z
The L{IntNStringReceiver.recvd} buffer contains all data not yet
processed by L{IntNStringReceiver.dataReceived} if the
C{lengthLimitExceeded} event occurs.
s   too longc                 `   < SP                  V 4       SP                  SP                  4       R # r   r  )rN   r   r  s   &r   r  PRecvdAttributeMixin.test_recvdInLengthLimitExceeded.<locals>.lengthLimitExceeded  s    MM&!MM%++&r   N)r  rV   rZ   r  r  rl   rm   )r   DATAmessager  r   r  s   &   @@r   test_recvdInLengthLimitExceeded3RecvdAttributeMixin.test_recvdInLengthLimitExceeded  s       "t9q=""5$/	' %8!7#CI.G,r   r   N)r,   r-   r.   r/   r0   r  r  r  r  r  r2   r3   r4   s   @r   r  r  g  s)     D6$7./8- -r   r  c                       ] tR tRtRtRtR# )	TestInt32i  zw
A L{basic.Int32StringReceiver} storing received strings in an array.

@ivar received: array holding received strings.
r   Nr,   r-   r.   r/   r0   r2   r   r   r   r  r        r   r  c                   D   a  ] tR tRt o Rt]tRR.tR.t. R	Ot	R t
RtV tR# )

Int32Testsi  z'
Test case for int32-prefixed protocol
r   s
      aaaaaac                    V P                  4       pVP                  R4       V P                  VP                  P	                  4       R4       VP                  R4       V P                  VP                  R.4       R# )z/
Test specific behavior of the 32-bits length.
r   s      foos      ubar   ubarNr  r0  rm   rP   r1  rl   r>   r  s   & r   	test_dataInt32Tests.test_data  s_     	V**,.DE	./gY/r   r   Nr  )s         hello therer   )r,   r-   r.   r/   r0   r  r   r/  r  r  r  r2   r3   r4   s   @r   r  r    s2      HYG/0N;N0 0r   r  c                       ] tR tRtRtRtR# )	TestInt16i  zw
A L{basic.Int16StringReceiver} storing received strings in an array.

@ivar received: array holding received strings.
r   Nr  r   r   r   r  r    r  r   r  c                   J   a  ] tR tRt o Rt]tRR	.tR.t. R
Ot	R t
R tRtV tR# )
Int16Testsi  z'
Test case for int16-prefixed protocol
r   s    aaaaaac                    V P                  4       pVP                  R4       V P                  VP                  P	                  4       R4       VP                  R4       V P                  VP                  R.4       R# )z/
Test specific behavior of the 16-bits length.
r   s    foos    ubarr  Nr  r  s   & r   r  Int16Tests.test_data   s]     	V**,n=	'gY/r   c                    V P                  4       pR^VP                  ^,          ,          ^,           ,          pV P                  \        VP                  V4       R# z1
Send too much data: that should cause an error.
rf  Nr  prefixLengthr   AssertionErrorr0  r   r   tooSends   &  r   test_tooLongSendInt16Tests.test_tooLongSend
  E     ! 23a78.!,,@r   r   Nr  )    r  r   )r,   r-   r.   r/   r0   r  r   r/  r  r  r  r  r2   r3   r4   s   @r   r  r    s9      HYG'(N3N0A Ar   r  c                       ] tR tRtRtRtR# )TestInt8i  zv
A L{basic.Int8StringReceiver} storing received strings in an array.

@ivar received: array holding received strings.
r   Nr  r   r   r   r  r    r  r   r  c                   J   a  ] tR tRt o Rt]tRR	.tR.t. R
Ot	R t
R tRtV tR# )	Int8Testsi  z&
Test case for int8-prefixed protocol
r   s     aaaaaac                    V P                  4       pVP                  R4       V P                  VP                  P	                  4       R4       VP                  R4       V P                  VP                  R.4       R# )z.
Test specific behavior of the 8-bits length.
r   s   foos   ubarr  Nr  r  s   & r   r  Int8Tests.test_data%  s]     	V**,j9	{#gY/r   c                    V P                  4       pR^VP                  ^,          ,          ^,           ,          pV P                  \        VP                  V4       R# r  r  r  s   &  r   r  Int8Tests.test_tooLongSend/  r  r   r   Nr  )   s   dzadzr   )r,   r-   r.   r/   r0   r  r   r/  r  r  r  r  r2   r3   r4   s   @r   r  r    s9      HYG'(N-N0A Ar   r  c                   D   a  ] tR tRt o RtRtRtR tR tR t	R t
RtV tR	# )
OnlyProducerTransporti8  za
Transport which isn't really a transport, just looks like one to
someone not looking very hard.
Fc                    . V n         R # r   r   r   s   &r   r   OnlyProducerTransport.__init__A  s	    	r   c                    R V n         R# )TNpausedr   s   &r   rI   $OnlyProducerTransport.pauseProducingD  s	    r   c                    R V n         R# )FNr  r   s   &r   rK   %OnlyProducerTransport.resumeProducingG  s	    r   c                <    V P                   P                  V4       R # r   )r)   r   )r   r&  s   &&r   r  OnlyProducerTransport.writeJ  s    		r   )r)   r  N)r,   r-   r.   r/   r0   r  r   r   rI   rK   r  r2   r3   r4   s   @r   r  r  8  s/     
 FM   r   r  c                   *   a  ] tR tRt o RtR tRtV tR# )ConsumingProtocoliN  z;
Protocol that really, really doesn't want any more bytes.
c                \    V P                   P                  V4       V P                  4        R # r   )rP   r  rI   r!   s   &&r   r#   ConsumingProtocol.lineReceivedS  s     T"r   r   N)r,   r-   r.   r/   r0   r#   r2   r3   r4   s   @r   r  r  N  s      r   r  c                   *   a  ] tR tRt o RtR tRtV tR# )ProducerTestsiX  zE
Tests for L{basic._PausableMixin} and L{basic.LineReceiver.paused}.
c                   \        4       p\        4       pVP                  V4       VP                  R4       V P	                  VP
                  . 4       V P                  VP                  4       V P                  VP                  4       VP                  R4       V P	                  VP
                  R.4       V P                  VP                  4       V P                  VP                  4       VP                  4        V P	                  VP
                  R.4       V P                  VP                  4       V P                  VP                  4       VP                  R4       V P	                  VP
                  RR.4       V P                  VP                  4       V P                  VP                  4       VP                  4        V P	                  VP
                  . RO4       V P                  VP                  4       V P                  VP                  4       VP                  R4       V P	                  VP
                  . RO4       V P                  VP                  4       V P                  VP                  4       VP                  4        V P	                  VP
                  . R	O4       V P                  VP                  4       V P                  VP                  4       VP                  4        V P	                  VP
                  . R	O4       V P                  VP                  4       V P                  VP                  4       R# )
a  
When L{basic.LineReceiver} is paused, it doesn't deliver lines to
L{basic.LineReceiver.lineReceived} and delivers them immediately upon
being resumed.

L{ConsumingProtocol} is a L{LineReceiver} that pauses itself after
every line, and writes that line to its transport.
s   hello, s   world
   hello, worlds   hello
world
r  s	   goodbye
N)r	  r  r  )r	  r  r  r   )
r  r  ri   rl   rm   r)   r   r  r   rK   )r   prq   s   &  r   test_pauseResumeProducerTests.test_pauseResume]  sN    !#	 	
z"$"" 	
|$/!23!! 	
/!23"" 	
,-/8!<=!! 	
!FG!! 	
~&!FG!! 	
!RS!! 	
!RS""r   r   N)r,   r-   r.   r/   r0   r  r2   r3   r4   s   @r   r  r  X  s     A# A#r   r  c                   H   a  ] tR tRt o RtR tR tR tR tR t	R t
R	tV tR
# )FileSenderTestsi  z 
Tests for L{basic.FileSender}.
c                n    \         P                  ! 4       pV P                  \        \        V4      4       R# )z@
L{basic.FileSender} implements the L{IPullProducer} interface.
N)r   
FileSenderr   r   r	   )r   senders   & r   test_interfaceFileSenderTests.test_interface  s%     !!#Y78r   c                    \        R4      p\        P                  ! 4       p\        P                  ! 4       pVP                  W4       V P                  VP                  V4       V P                  VP                  4       R# )z
When L{basic.FileSender.beginFileTransfer} is called, it registers
itself with provided consumer, as a non-streaming producer.
   Test contentN)
r   r   r   r   r  beginFileTransferrm   producerr   	streaming)r   sourceconsumerr  s   &   r   test_producerRegistered'FileSenderTests.test_producerRegistered  sb    
 ) 002!!#  2**F3++,r   c                   \        R4      p\        P                  ! 4       p\        P                  ! 4       pVP                  W4      pVP                  4        VP                  4        V P                  VP                  4       V P                  RV P                  V4      4       V P                  RVP                  4       4       R# )z
L{basic.FileSender} sends the content of the given file using a
C{IConsumer} interface via C{beginFileTransfer}. It returns a
L{Deferred} which fires with the last byte sent.
r     tN)r   r   r   r   r  r  rK   assertIsNoner  rm   successResultOfr1  r   r  r  r  ds   &    r   test_transferFileSenderTests.test_transfer  s     ) 002!!#$$V6  (++,t33A67(..*:;r   c                b   \        R4      p\        P                  ! 4       p\        P                  ! 4       p^Vn        VP                  W4      pVP                  4        V P                  RVP                  4       4       VP                  4        V P                  RVP                  4       4       VP                  4        V P                  RVP                  4       4       VP                  4        V P                  RV P                  V4      4       V P                  RVP                  4       4       R# )zR
L{basic.FileSender} reads at most C{CHUNK_SIZE} every time it resumes
producing.
r  s   Tests   Test conr  N)r   r   r   r   r  
CHUNK_SIZEr  rK   rm   r1  r   r!  s   &    r   test_transferMultipleChunks+FileSenderTests.test_transferMultipleChunks  s    
 ) 002!!#$$V6 (.."23 hnn&67 (..*:; t33A67(..*:;r   c                \   R p\        R4      p\        P                  ! 4       p\        P                  ! 4       pVP                  W#V4      pVP                  4        VP                  4        V P                  RV P                  V4      4       V P                  RVP                  4       4       R# )zu
L{basic.FileSender.beginFileTransfer} takes a C{transform} argument
which allows to manipulate the data on the fly.
c                 "    V P                  4       # r   )swapcase)chunks   &r   	transform=FileSenderTests.test_transferWithTransform.<locals>.transform  s    >>##r   r     Ts   tEST CONTENTN)
r   r   r   r   r  r  rK   rm   r   r1  )r   r-  r  r  r  r"  s   &     r   test_transferWithTransform*FileSenderTests.test_transferWithTransform  s    	$ ) 002!!#$$VyA  t33A67(..*:;r   c                H   \        R4      p\        P                  ! 4       p\        P                  ! 4       pVP                  W4      pVP                  4        V P                  V4      pVP                  \        4       V P                  R\        VP                  4      4       R# )z
The C{Deferred} returned by L{basic.FileSender.beginFileTransfer} fails
with an C{Exception} if C{stopProducing} when the transfer is not
complete.
r  z#Consumer asked us to stop producingN)r   r   r   r   r  r  rL   failureResultOftrap	Exceptionrm   strr1  )r   r  r  r  r"  failures   &     r   test_abortedTransfer$FileSenderTests.test_abortedTransfer  s|     ) 002!!#$$V6&&q)Y>GMM@RSr   r   N)r,   r-   r.   r/   r0   r  r  r#  r'  r0  r8  r2   r3   r4   s   @r   r  r    s/     9
-<$<.<(T Tr   r  );r0   r  r   ior   typingr   r   r   zope.interface.verifyr   twisted.internetr   r   twisted.internet.interfacesr	   twisted.internet.protocolr
   twisted.protocolsr   twisted.python.compatr   twisted.python.failurer   twisted.testr   twisted.trialr   r   r   r7   r   r^   SynchronousTestCasere   r   r   r   r  r  r  r  r*  r  r  Int32StringReceiverr  r  Int16StringReceiverr  r  Int8StringReceiverr  r  r  r  r  TestCaser  r   r   r   <module>rJ     s  
  
  ' ' . + 1 4 # + * & "#++ #0E:## E:P#U++ #*uJ44 uJp$%"4"4 $.L1(*F*F L1^)JH88 )JX  Iu66  7 72ULX99? ULpFL FLRg- g-T	544 0--/@BU 0*	544 A--/@BU A:y%22 A,,.?AT A:   ,** F#H00 F#RdTh'' dTr   