
    tf                        d Z ddlZddlZddlmZ ddlmZmZmZ ddl	m
Z
 ddlmZmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ  G d dej                  Z G d dej                  Z G d dej                  Z  G d dej!                  Z" G d dej                  Z# G d dej!                  Z$ G d dej!                  Z% G d d          Z& G d de&ej'                  Z( G d  d!          Z) G d" d#ej!        e)          Z* G d$ d%e)          Z+ G d& d'          Z, G d( d)e&ej-                  Z. G d* d+ej!        e+e,          Z/ G d, d-e&ej0                  Z1 G d. d/ej!        e+e,          Z2 G d0 d1e&ej3                  Z4 G d2 d3ej!        e+e,          Z5 G d4 d5          Z6 G d6 d7ej                  Z7 G d8 d9ej!                  Z8 G d: d;ej9                  Z:dS )<z,
Test cases for L{twisted.protocols.basic}.
    N)BytesIO)ListOptionalType)verifyObject)protocoltask)	IProducer)connectionDone)basic)	iterbytes)Failure)proto_helpers)unittestc                   (    e Zd ZdZdZd Zd Zd ZdS )FlippingLineTesterzT
    A line receiver that flips between line and raw data modes after one byte.
       
c                     g | _         d S N)linesselfs    `/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/protocols/test/test_basic.py__init__zFlippingLineTester.__init__!   s    


    c                 b    | j                             |           |                                  dS )z&
        Set the mode to raw.
        N)r   append
setRawModer   lines     r   lineReceivedzFlippingLineTester.lineReceived$   s0     	
$r   c                 @    |                      |dd                    dS )z,
        Set the mode back to line.
           N)setLineModer   datas     r   rawDataReceivedz"FlippingLineTester.rawDataReceived+   s&     	abb"""""r   N)__name__
__module____qualname____doc__	delimiterr   r!   r'    r   r   r   r      sR          I    # # # # #r   r   c                   :    e Zd ZdZdZdZd
dZd Zd Zd Z	d	 Z
dS )
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                     || _         dS )z@
        If given, use a clock to make callLater calls.
        N)clock)r   r2   s     r   r   zLineTester.__init__B   s     


r   c                     g | _         dS z;
        Create/clean data received on connection.
        Nreceivedr   s    r   connectionMadezLineTester.connectionMadeH        r   c                    | j                             |           |dk    r|                                  dS |dk    r6|                                  | j                            d| j                   dS |dk    rd|                                  |                                  | j                             d           | j                            d| j                   dS |dk    r|                                  dS |dd         dk    rt          |dd                   | _	        dS |
                    d	          r| j                            | d
           dS |
                    d          r| j                                         dS dS )z|
        Receive line and make some action for some tokens: pause, rawpause,
        stop, len, produce, unproduce.
        r      pauser      rawpause   stopN   s   len    produceF	   unproduce)r6   r   r   pauseProducingr2   	callLaterresumeProducingstopProducingintlength
startswith	transportregisterProducerunregisterProducerr   s     r   r!   zLineTester.lineReceivedN   s   
 	T"""3;;OOX!!!J  D$899999[  !!!OOM  %%%J  D$899999W__     "1"X  d122h--DKKK__Z(( 	0N++D%88888__\** 	0N--/////	0 	0r   c                     |d| j                  || j         d         }}| j         t          |          z
  | _         | j        d         |z   | j        d<   | j         dk    r|                     |           dS dS )zj
        Read raw data, until the quantity specified by a previous 'len' line is
        reached.
        Nr   )rE   lenr6   r$   )r   r&   rests      r   r'   zLineTester.rawDataReceivedg   s~    
 -DK-($t{}}*=dkCII- M"-4b;!T""""" r   c                     t          |          | j        dz   k    r'|                     || j        dz   d                    dS dS )z<
        Adjust line mode when long lines received.
        r#   N)rL   
MAX_LENGTHr$   r   s     r   lineLengthExceededzLineTester.lineLengthExceededr   sP     t99t***T$/A"5"7"7899999 +*r   r   )r(   r)   r*   r+   r,   rO   r   r7   r!   r'   rP   r-   r   r   r/   r/   2   sz        
 
 IJ     0 0 02	# 	# 	#: : : : :r   r/   c                   &    e Zd ZdZdZdZd Zd ZdS )LineOnlyTesterz)
    A buffering line only receiver.
    r   r0   c                     g | _         dS r4   r5   r   s    r   r7   zLineOnlyTester.connectionMade   r8   r   c                 :    | j                             |           dS )z%
        Save received data.
        Nr6   r   r   s     r   r!   zLineOnlyTester.lineReceived   s      	T"""""r   N)r(   r)   r*   r+   r,   rO   r7   r!   r-   r   r   rR   rR   z   sH          IJ  # # # # #r   rR   c                       e Zd ZdZdZg dZd ZdZg dZedgz   Z	d Z
d	Zg d
Zg dZd ZdZg dZd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdS )LineReceiverTestsz\
    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

a)s   len 10
   0123456789   len 5s   1234
s   len 20s   foo 123s   0123456789
012345678s   len 0s   foo 5r   s   67890s   len 1   ac                    t          dd          D ]}t          j                    }t                      }|                    t          j        |                     t          t          | j                  |z  dz             D ]/}| j        ||z  |dz   |z           }|	                    |           0| 
                    | j        |j                   dS )zl
        Test buffering for different packet size, checking received matches
        expected data.
        r#   
   N)ranger   StringIOWithoutClosingr/   makeConnectionr   FileWrapperrL   bufferdataReceivedassertEqualoutputr6   r   packet_sizetaiss         r   test_bufferzLineReceiverTests.test_buffer   s    
 !B<< 	6 	6K466AAX1!445553t{++{:Q>?? " "KK1q5K2G GHq!!!!T[!*5555	6 	6r   s!   twiddle1
twiddle2
pause
twiddle3
)   twiddle1   twiddle2r:      twiddle3c                 @   t          dd          D ]}t          j                    }t          j                    }t          |          }|                    t          j        |                     t          t          | j
                  |z  dz             D ]/}| j
        ||z  |dz   |z           }|                    |           0|                     | j        |j                   |                    d           |                     | j        |j                   dS )zo
        Test pause inside data receiving. It uses fake clock to see if
        pausing/resuming work.
        r#   r\   r   N)r]   r   r^   r	   Clockr/   r_   r   r`   rL   pauseBufrb   rc   pauseOutput1r6   advancepauseOutput2r   rf   rg   r2   rh   ri   rj   s          r   test_pausingzLineReceiverTests.test_pausing   s   
 !B<< 
	< 
	<K466AJLLE5!!AX1!445553t}--<q@AA " "M!k/QUk4I"IJq!!!!T.
;;;MM!T.
;;;;
	< 
	<r   s/   twiddle1
twiddle2
len 5
rawpause
12345twiddle3
)rl   rm   rY   r;   r   )rl   rm   rY   r;   s   12345rn   c                 @   t          dd          D ]}t          j                    }t          j                    }t          |          }|                    t          j        |                     t          t          | j
                  |z  dz             D ]/}| j
        ||z  |dz   |z           }|                    |           0|                     | j        |j                   |                    d           |                     | j        |j                   dS )z7
        Test pause inside raw date receiving.
        r#   r\   r   N)r]   r   r^   r	   rp   r/   r_   r   r`   rL   rawpauseBufrb   rc   rawpauseOutput1r6   rs   rawpauseOutput2ru   s          r   test_rawPausingz!LineReceiverTests.test_rawPausing   s    !B<< 
	? 
	?K466AJLLE5!!AX1!445553t/00K?!CDD " "$Q_A7L%LMq!!!!T11:>>>MM!T11:>>>>
	? 
	?r   s"   twiddle1
twiddle2
stop
more
stuff
)rl   rm   r<   c                    t          dd          D ]}t          j                    }t                      }|                    t          j        |                     t          t          | j                  |z  dz             D ]/}| j        ||z  |dz   |z           }|	                    |           0| 
                    | j        |j                   dS )z-
        Test stop inside producing.
        r#   r\   N)r]   r   r^   r/   r_   r   r`   rL   stop_bufrb   rc   stop_outputr6   re   s         r   test_stopProducingz$LineReceiverTests.test_stopProducing   s     !B<< 	; 	;K466AAX1!445553t}--<q@AA " "M!k/QUk4I"IJq!!!!T-qz::::	; 	;r   c                     t                      }t          j                    }|                    t	          j        |                     |                    d           |                     |j        g d           dS )z6
        Test produce/unproduce in receiving.
        s&   produce
hello world
unproduce
goodbye
)r>   s   hello worldr?      goodbyeN)	r/   r   r^   r_   r   r`   rb   rc   r6   )r   rh   rg   s      r   test_lineReceiverAsProducerz-LineReceiverTests.test_lineReceiverAsProducer  s}     LL022	-a00111	DEEEJNNN	
 	
 	
 	
 	
r   c                 b    G d dt           j                  } |            } |j        d           |                     |j        d           |                     |j        d            |j        d           |                     |j        d           |                     |j        d           d	S )
z
        L{LineReceiver.clearLineBuffer} removes all buffered data and returns
        it as a C{bytes} and can be called from beneath C{dataReceived}.
        c                       e Zd Zd ZdS )@LineReceiverTests.test_clearLineBuffer.<locals>.ClearingReceiverc                 F    || _         |                                 | _        d S r   )r    clearLineBufferrM   r   s     r   r!   zMLineReceiverTests.test_clearLineBuffer.<locals>.ClearingReceiver.lineReceived  s      	 0022			r   N)r(   r)   r*   r!   r-   r   r   ClearingReceiverr     s#        3 3 3 3 3r   r   s   foo
bar
baz   foos   bar
bazs   quux
s   quuxr   N)r   LineReceiverrb   rc   r    rM   )r   r   r   s      r   test_clearLineBufferz&LineReceiverTests.test_clearLineBuffer  s    	3 	3 	3 	3 	3u1 	3 	3 	3
 $#%%2333///666 	k***000,,,,,r   c                 N   t                      }t          j                    }|                    t	          j        |                     t          j                    }|                    d|z             | 	                    d|z  d
                    |j                             dS )zC
        Test switching modes many times on the same data.
        s   x
x   xr   N)r   r   r^   r_   r   r`   sysgetrecursionlimitrb   rc   joinr   )r   protorG   limits       r   test_stackRecursionz%LineReceiverTests.test_stackRecursion*  s     #$$!8::	X1)<<===%''7U?+++sxx'<'<=====r   c                     t          j                    }t          j                    }|                    |           |                    d|j        dz   z  dz              |                     |j                   dS zx
        C{LineReceiver} disconnects the transport if it receives a line longer
        than its C{MAX_LENGTH}.
        r   r#      
rN	r   r   r   StringTransportr_   rb   rO   
assertTruedisconnectingr   r   rG   s      r   test_maximumLineLengthz(LineReceiverTests.test_maximumLineLength5  u    
 "$$!133	Y'''45#3a#788CDDD	/00000r   c                    t                      }d|_        t          j                    }|                    |           d|j        dz
  z  }|                    |           |                    |j        dd                    |                    |j        dd         |z              |                     |j                   | 	                    t          |j                  d           | 	                    ||j        d                    dS )a~  
        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=   r   r#   NrK   r   )r/   rO   r   r   r_   rb   r,   assertFalser   rc   rL   r6   )r   r   rg   r    s       r   &test_maximumLineLengthPartialDelimiterz8LineReceiverTests.test_maximumLineLengthPartialDelimiter@  s     )++Qu'!+,4   5?3B3/0005?233/$6777)))U^,,a000u~a011111r   c                 B   t          j                    }d|_        t          j                    }|                    |           |                    d|j        z  |j        dt          |j                  dz
           z              | 	                    |j
                   dS )aO  
        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   Nr#   )r   r   r,   r   r   r_   rb   rO   rL   r   r   r   s      r   (test_notQuiteMaximumLineLengthUnfinishedz:LineReceiverTests.test_notQuiteMaximumLineLengthUnfinishedV  s     "$$ "!133	Y'''E$$8R#eo:N:NQR:R8R(SS	
 	
 	
 	011111r   c                    t          j                    }d |_        t          j                    }|                    |           |                                 |                    d          }|                     |t                     dS )zf
        C{LineReceiver.dataReceived} forwards errors returned by
        C{rawDataReceived}.
        c                      t          d          S )Noops)RuntimeErrorr&   s    r   <lambda>z5LineReceiverTests.test_rawDataError.<locals>.<lambda>o  s    \&-A-A r   s   dataN)
r   r   r'   r   r   r_   r   rb   assertIsInstancer   )r   r   rG   whys       r   test_rawDataErrorz#LineReceiverTests.test_rawDataErrori  s    
 "$$ A A!133	Y'''  ))c<00000r   c                 n    t          j                    }|                     t          |j        d           dS )z
        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_rawDataReceivedNotImplementedz4LineReceiverTests.test_rawDataReceivedNotImplementedv  s4    
 "$$-u/DeLLLLLr   c                 n    t          j                    }|                     t          |j        d           dS )z
        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_lineReceivedNotImplementedz1LineReceiverTests.test_lineReceivedNotImplemented~  s4    
 "$$-u/A5IIIIIr   N)r(   r)   r*   r+   ra   rd   rk   rq   rr   rt   rv   rx   ry   rz   r{   r}   r~   r   r   r   r   r   r   r   r   r   r   r-   r   r   rW   rW      sU        
F$  F 6 6 6 8H777L;-/L< < <" JKLLLO  O? ? ?  :H555K; ; ;

 

 

- - -,	> 	> 	>	1 	1 	12 2 2,2 2 2&1 1 1M M MJ J J J Jr   rW   c                   $    e Zd ZdZd Zd Zd ZdS )ExcessivelyLargeLineCatcherz
    Helper for L{LineReceiverLineLengthExceededTests}.

    @ivar longLines: A L{list} of L{bytes} giving the values
        C{lineLengthExceeded} has been called with.
    c                     g | _         d S r   )	longLinesr   s    r   r7   z*ExcessivelyLargeLineCatcher.connectionMade  s    r   c                     dS )z/
        Disregard any received lines.
        Nr-   r   s     r   r!   z(ExcessivelyLargeLineCatcher.lineReceived  s      r   c                 :    | j                             |           dS )zF
        Record any data that exceeds the line length limits.
        N)r   r   r%   s     r   rP   z.ExcessivelyLargeLineCatcher.lineLengthExceeded  s      	d#####r   N)r(   r)   r*   r+   r7   r!   rP   r-   r   r   r   r     sK             
$ $ $ $ $r   r   c                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )
#LineReceiverLineLengthExceededTestszO
    Tests for L{twisted.protocols.basic.LineReceiver.lineLengthExceeded}.
    c                     t                      | _        d| j        _        t          j                    | _        | j                            | j                   d S )N   )r   r   rO   r   r   rG   r_   r   s    r   setUpz)LineReceiverLineLengthExceededTests.setUp  sG    022
 !
&688
!!$.11111r   c                     d| j         j        dz  dz   z  }| j                             |           |                     |g| j         j                   dS )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   rO   rb   rc   r   r   	excessives     r   test_longUnendedLinez8LineReceiverLineLengthExceededTests.test_longUnendedLine  sV     DJ1A59:	
	***)dj&:;;;;;r   c                     d| j         j        dz  dz   z  }| j                             d| j         j        z   |z              |                     |g| j         j                   dS )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   r   N)r   rO   rb   r,   rc   r   r   s     r   test_longLineAfterShortLinez?LineReceiverLineLengthExceededTests.test_longLineAfterShortLine  se     DJ1A59:	
tz'; ;i GHHH)dj&:;;;;;r   c                     | j         j                            d| j         j        dz  dz   z  gdz            }| j                             |           |                     |g| j         j                   dS )a  
        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   r   N)r   r,   r   rO   rb   rc   r   r   s     r   test_longLineWithDelimiterz>LineReceiverLineLengthExceededTests.test_longLineWithDelimiter  sx     J(--TZ*Q.234q8
 
	 	
	***)dj&:;;;;;r   c                     d| j         j        dz  dz   z  | j         j        z   dz  }| j                             |           |                     |g| j         j                   dS )a  
        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   r   N)r   rO   r,   rb   rc   r   r   s     r   test_multipleLongLinesz:LineReceiverLineLengthExceededTests.test_multipleLongLines  sf     TZ2Q6:;dj>RRVWW	
	***)dj&:;;;;;r   c                     t          j                    }t          j                    }|                    |           |                    d|j        dz   z  dz              |                     |j                   dS r   r   r   s      r   r   z:LineReceiverLineLengthExceededTests.test_maximumLineLength  r   r   c                    t          j                    }t          j                    }|                    |           |                    d|j        t          |j                  z   z             | 	                    |j
                   dS )z
        C{LineReceiver} disconnects the transport it if receives a non-finished
        line longer than its C{MAX_LENGTH}.
        r   N)r   r   r   r   r_   rb   rO   rL   r,   r   r   r   s      r   test_maximumLineLengthRemainingzCLineReceiverLineLengthExceededTests.test_maximumLineLengthRemaining  sz    
 "$$!133	Y'''45#3c%/6J6J#JKLLL	/00000r   N)r(   r)   r*   r+   r   r   r   r   r   r   r   r-   r   r   r   r     s         2 2 2< < <	< 	< 	<< < <	< 	< 	<	1 	1 	1	1 	1 	1 	1 	1r   r   c                   (    e Zd ZdZdZd Zd Zd ZdS )LineOnlyReceiverTestsz@
    Tests for L{twisted.protocols.basic.LineOnlyReceiver}.
    s7   foo
    bleakness
    desolation
    plastic forks
    c                 @   t          j                    }t                      }|                    |           t	          | j                  D ]}|                    |           |                     |j        | j        	                    d          dd                    dS )zW
        Test buffering over line protocol: data received should match buffer.
        r   NrK   )
r   r   rR   r_   r   ra   rb   rc   r6   split)r   rg   rh   cs       r   rk   z!LineOnlyReceiverTests.test_buffer  s     )++	4;'' 	 	ANN1T[%6%6u%=%=crc%BCCCCCr   c                    t                      }t          j                    }|                    |           |                    d|j        t          |j                  z   dz   z  dz              |                     |j	                   dS )z
        C{LineOnlyReceiver} disconnects the transport if it receives a
        line longer than its C{MAX_LENGTH} + len(delimiter).
        r   r#   r   N)
rR   r   r   r_   rb   rO   rL   r,   r   r   r   s      r   !test_greaterThanMaximumLineLengthz7LineOnlyReceiverTests.test_greaterThanMaximumLineLength  s    
   !133	Y'''E$s5?';';;a?@8K	
 	
 	
 		/00000r   c                 n    t          j                    }|                     t          |j        d           dS )z
        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   z5LineOnlyReceiverTests.test_lineReceivedNotImplemented  s4    
 &((-u/A5IIIIIr   N)r(   r)   r*   r+   ra   rk   r   r   r-   r   r   r   r     sZ         F	D 	D 	D1 1 1J J J J Jr   r   c                   6    e Zd Zd Zd ZdZdZefdeddfdZ	dS )		TestMixinc                     g | _         d S r   r5   r   s    r   r7   zTestMixin.connectionMade  s    r   c                 :    | j                             |           d S r   rU   r   rj   s     r   stringReceivedzTestMixin.stringReceived  s    Qr   2   r   reasonreturnNc                     d| _         d S )Nr#   )closed)r   r   s     r   connectionLostzTestMixin.connectionLost#  s    r   )
r(   r)   r*   r7   r   rO   r   r   r   r   r-   r   r   r   r     sh                JF/=  W $      r   r   c                       e Zd Zd ZdS )TestNetstringc                 n    | j                             |           | j                            |           d S r   )r6   r   rG   writer   s     r   r   zTestNetstring.stringReceived(  s4    QQr   N)r(   r)   r*   r   r-   r   r   r   r   '  s#                 r   r   c                   P    e Zd ZU g Zeee                  ed<   dZded<   d Z	d Z
dS )LPTestCaseMixinillegalStringsN!Optional[Type[protocol.Protocol]]r   c                 ~    t          j                    }|                                 }|                    |           |S )z
        Return a new instance of C{self.protocol} connected to a new instance
        of L{proto_helpers.StringTransport}.
        )r   r   r   r_   )r   rg   rh   s      r   getProtocolzLPTestCaseMixin.getProtocol1  s8    
 )++MMOO	r   c                     | j         D ]\}|                                 }t          |          D ]}|                    |           |                     |j        j                   ]dS )zO
        Assert that illegal strings cause the transport to be closed.
        N)r   r   r   rb   r   rG   r   r   rj   rr   s       r   test_illegalzLPTestCaseMixin.test_illegal;  su     $ 	7 	7A  ""Aq\\ " "q!!!!OOAK56666		7 	7r   )r(   r)   r*   r   r   r   bytes__annotations__r   r   r   r-   r   r   r   r   -  s^         ,.NHT%[)...48H1888  7 7 7 7 7r   r   c                       e Zd ZdZg dZg dZeZd Zd Z	d Z
d Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdS )NetstringReceiverTestszA
    Tests for L{twisted.protocols.basic.NetstringReceiver}.
    )   hello   worlds   hows   ares   you123s   :todays  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)s   9999999999999999999999s   abcs   4:abcdes7   51:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab,c                     t          j                    | _        t                      | _        | j                            | j                   d S r   )r   r   rG   r   netstringReceiverr_   r   s    r   r   zNetstringReceiverTests.setUpV  s=    &688!.--dn=====r   c                    t          dd          D ]}t          j                    }t                      }d|_        |                    |           | j        D ]}|                    |           |                                }t          t          |          |z  dz             D ],}|||z  |dz   |z           }|r|
                    |           -|                     |j        | j                   dS )zI
        Strings can be received in chunks of different lengths.
        r#   r\   i  N)r]   r   r   r   rO   r_   strings
sendStringvaluerL   rb   rc   r6   )r   rf   rg   rh   rj   outri   s          r   rk   z"NetstringReceiverTests.test_buffer[  s    !B<< 	7 	7K-//AAALQ\    Q''))C3s88{2Q677 & &K1q5K*??@ &NN1%%%QZ6666	7 	7r   c                 |    | j                             d           |                     | j         j        dg           dS )zE
        Empty netstrings (with length '0') can be received.
        s   0:,r   Nr   rb   rc   r6   r   s    r   test_receiveEmptyNetstringz1NetstringReceiverTests.test_receiveEmptyNetstringm  s?     	++F333/83%@@@@@r   c                 |    | j                             d           |                     | j         j        dg           dS )z;
        One-character netstrings can be received.
           1:a,rZ   Nr   r   s    r   test_receiveOneCharacterz/NetstringReceiverTests.test_receiveOneCharactert  s?     	++G444/84&AAAAAr   c                 |    | j                             d           |                     | j         j        dg           dS )z;
        Two-character netstrings can be received.
        s   2:ab,   abNr   r   s    r   test_receiveTwoCharactersz0NetstringReceiverTests.test_receiveTwoCharacters{  s?     	++H555/85'BBBBBr   c                 |    | j                             d           |                     | j         j        dg           dS )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,,r  Nr   r   s    r   test_receiveNestedNetstringz2NetstringReceiverTests.test_receiveNestedNetstring  s?     	++J777/87)DDDDDr   c                 x    | j                             d           |                     | j        j                   dS )zL
        Netstrings containing more data than expected are refused.
        s   2:aaa,Nr   rb   r   rG   r   r   s    r   test_moreDataThanSpecifiedz1NetstringReceiverTests.test_moreDataThanSpecified  s8     	++I666455555r   c                 x    | j                             d           |                     | j        j                   dS )z
        Netstrings that should be empty according to their length
        specification are refused if they contain data.
        s   0:a,Nr	  r   s    r   $test_moreDataThanSpecifiedBorderCasez;NetstringReceiverTests.test_moreDataThanSpecifiedBorderCase  8    
 	++G444455555r   c                 x    | j                             d           |                     | j        j                   dS )z`
        Netstrings without leading digits that specify the length
        are refused.
        s   :aaa,Nr	  r   s    r   test_missingNumberz)NetstringReceiverTests.test_missingNumber  8    
 	++H555455555r   c                 x    | j                             d           |                     | j        j                   dS )zg
        Netstrings without a colon between length specification and
        data are refused.
        s   3aaa,Nr	  r   s    r   test_missingColonz(NetstringReceiverTests.test_missingColon  r  r   c                 x    | j                             d           |                     | j        j                   dS )zY
        Netstrings that have no leading digits nor a colon are
        refused.
        s   aaa,Nr	  r   s    r   test_missingNumberAndColonz1NetstringReceiverTests.test_missingNumberAndColon  r  r   c                 x    | j                             d           |                     | j        j                   dS )zA
        Netstrings consisting only of data are refused.
        s   aaaNr	  r   s    r   test_onlyDataz$NetstringReceiverTests.test_onlyData  s8     	++F333455555r   c                    | j                             d           | j                             d           |                     | j         j        dg           |                     | j                                                    dS )z=
        Netstrings can be received in two portions.
        s   4:aas   aa,s   aaaaN)r   rb   rc   r6   r   _payloadCompleter   s    r   test_receiveNetstringPortions_1z6NetstringReceiverTests.test_receiveNetstringPortions_1  sw     	++G444++F333/87)DDD.??AABBBBBr   c                     dD ]}| j                             |           |                     | j         j        dg           dS )z
        Netstrings can be received in more than two portions, even if
        the length specification is split across two portions.
        )   1s   0:01234s   56789   ,rX   Nr   r   parts     r   test_receiveNetstringPortions_2z6NetstringReceiverTests.test_receiveNetstringPortions_2  sQ    
 7 	6 	6D"//5555/8=/JJJJJr   c                     dD ]}| j                             |           |                     | j         j        dg           dS )zE
        Netstrings can be received one character at a time.
        )   2   :rZ      br  r  Nr   r  s     r   test_receiveNetstringPortions_3z6NetstringReceiverTests.test_receiveNetstringPortions_3  sQ     3 	6 	6D"//5555/85'BBBBBr   c                 L   | j                             d           |                     | j                                                    |                     | j         j        dg           | j                             d           |                     | j         j        ddg           dS )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,1rZ   s   :b,r#  N)r   rb   r   r  rc   r6   r   s    r   test_receiveTwoNetstringsz0NetstringReceiverTests.test_receiveTwoNetstrings  s     	++H555.??AABBB/84&AAA++F333/84,GGGGGr   c                     | j         j        dz   }| j                             d                    t	          |          dd|z  f                     |                     | j        j                   dS )zs
        Netstrings with a length specification exceeding the specified
        C{MAX_LENGTH} are refused.
        r#   r   r"  rZ   N)r   rO   rb   r   r   r   rG   r   )r   tooLongs     r   test_maxReceiveLimitz+NetstringReceiverTests.test_maxReceiveLimit  sn    
 (3a7++HHeGnndD7N;<<	
 	
 	
 	455555r   c                     d| j         _        | j                                          |                     | j         j        d           dS )zw
        C{_consumeLength} returns the expected length of the
        netstring, including the trailing comma.
           12:   N)r   _remainingData_consumeLengthrc   _expectedPayloadSizer   s    r   test_consumeLengthz)NetstringReceiverTests.test_consumeLength  sF    
 17---////DbIIIIIr   c                     d| j         _        d| j         _        | j                                          |                     | j         j        d           dS )z
        C{_consumeLength} works as expected if the length specification
        contains the value of C{MAX_LENGTH} (border case).
        r+     r,  N)r   r-  rO   r.  rc   r/  r   s    r   test_consumeLengthBorderCase1z4NetstringReceiverTests.test_consumeLengthBorderCase1  sQ    
 17-,.)--////DbIIIIIr   c                     d| j         _        d| j         _        |                     t          j        | j         j                   dS )z
        C{_consumeLength} raises a L{basic.NetstringParseError} if
        the length specification exceeds the value of C{MAX_LENGTH}
        by 1 (border case).
        r+     Nr   r-  rO   r   r   NetstringParseErrorr.  r   s    r   test_consumeLengthBorderCase2z4NetstringReceiverTests.test_consumeLengthBorderCase2  sJ     17-,.)%t'='L	
 	
 	
 	
 	
r   c                     d| j         _        d| j         _        |                     t          j        | j         j                   dS )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:r5  Nr6  r   s    r   test_consumeLengthBorderCase3z4NetstringReceiverTests.test_consumeLengthBorderCase3	  sJ     19-,.)%t'='L	
 	
 	
 	
 	
r   c                 n    t          j                    }|                     t          |j        d           dS )z
        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_stringReceivedNotImplementedz8NetstringReceiverTests.test_stringReceivedNotImplemented  s4    
 '))-u/CUKKKKKr   N)r(   r)   r*   r+   r   r   r   r   r   rk   r   r  r  r  r
  r  r  r  r  r  r  r  r$  r&  r)  r0  r3  r8  r:  r=  r-   r   r   r   r   F  s         UTTG  N H> > >
7 7 7$A A AB B BC C CE E E6 6 66 6 66 6 66 6 66 6 66 6 6C C CK K KC C C
H 
H 
H	6 	6 	6J J JJ J J

 

 



 

 

L L L L Lr   r   c                       e Zd ZU dZdZded<   dZeee	                  ed<   dZ
eee	                  ed<   dZeee	                  ed<   d Zd	 Zd
 Zd Zd Zd ZdS )IntNTestCaseMixinz4
    TestCase mixin for int-prefixed protocols.
    Nr   r   r   r   partialStringsc           	          |                                  }| j        D ]Q}t          t          j        |j        t          |                    |z             D ]}|                    |           R|                     |j	        | j                   dS )z>
        Test receiving data find the same data send.
        N)
r   r   r   structpackstructFormatrL   rb   rc   r6   )r   r   rj   r   s       r   test_receivezIntNTestCaseMixin.test_receive(  s      	" 	"Av{1>3q66BBQFGG " "q!!!!"T\22222r   c                     | j         D ]X}|                                 }t          |          D ]}|                    |           |                     |j        g            YdS )zK
        Send partial data, nothing should be definitely received.
        N)r@  r   r   rb   rc   r6   r   s       r   test_partialzIntNTestCaseMixin.test_partial2  sv     $ 	- 	-A  ""Aq\\ " "q!!!!QZ,,,,		- 	-r   c                     |                                  }|                    d           |                     |j                                        t          j        |j        d          dz              dS )z2
        Test sending data over protocol.
           bbbbbbbbbbbbbbbb   N)r   r   rc   rG   r   rB  rC  rD  r   r   s     r   	test_sendzIntNTestCaseMixin.test_send<  so     	YKQ^R!@!@9!L	
 	
 	
 	
 	
r   c                     g }|                                  }|j        |_        d|_        |                    t          j        |j        d                     |                     |dg           dS )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.
        r\   r5  N)	r   r   lengthLimitExceededrO   rb   rB  rC  rD  rc   )r   rE   r   s      r   test_lengthLimitExceededz*IntNTestCaseMixin.test_lengthLimitExceededF  si      &	v{1>266777"&&&&&r   c                     |                                  }d|_        |                    t          j        |j        d          dz              |                     |j        g            dS )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}.
        r\   r5  s   xxxxxxxxxxxN)r   rO   rb   rB  rC  rD  rc   r6   rK  s     r   test_longStringNotDeliveredz-IntNTestCaseMixin.test_longStringNotDeliveredS  s_     	v{1>266BCCCR(((((r   c                 n    t          j                    }|                     t          |j        d           dS )z
        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=  z3IntNTestCaseMixin.test_stringReceivedNotImplemented^  s4    
 (**-u/CUKKKKKr   )r(   r)   r*   r+   r   r   r   r   r   r   r   r@  rE  rG  rL  rO  rQ  r=  r-   r   r   r?  r?    s           59H1888%)GXd5k"))),0NHT%[)000,0NHT%[)0003 3 3- - -
 
 
' ' '	) 	) 	)L L L L Lr   r?  c                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )RecvdAttributeMixinz
    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                 V    t          j        |j        t          |                    |z   S )zg
        Return C{data} prefixed with message length in C{protocol.structFormat}
        form.
        )rB  rC  rD  rL   )r   r   r&   s      r   makeMessagezRecvdAttributeMixin.makeMessagen  s$    
 {80#d))<<tCCr   c                 "   g |                                  fd}|_        t          j        j        d          dz   }t          j        j        d          dz   }                    ||z              |                     |g           dS )z
        In stringReceived, recvd contains the remaining data that was passed to
        dataReceived that was not part of the current message.
        c                 <                         j                   d S r   r   recvd)receivedStringr   results    r   r   zKRecvdAttributeMixin.test_recvdContainsRemainingData.<locals>.stringReceived}  s    MM!'"""""r         aaaaas   bbbbN)r   r   rB  rC  rD  rb   rc   )r   r   completeMessageincompleteMessager   r]  s       @@r   test_recvdContainsRemainingDataz3RecvdAttributeMixin.test_recvdContainsRemainingDatau  s    
 	# 	# 	# 	# 	# 	# * +ana88HE"K::hG	)::;;;"3!455555r   c                 D  	 |                                  g 	d}|                     |          	fd}|_        d}d}|                     |          }|                     |          }                    ||z              |                     	||g           dS )z
        In stringReceived, if recvd is changed, messages should be parsed from
        it rather than the input to dataReceived.
        s   cccccc                 D    s_                             |            d S r   )r[  r   )r\  messageCr   r]  s    r   r   z=RecvdAttributeMixin.test_recvdChanged.<locals>.stringReceived  s*     #"MM.)))))r   r_  s   bbbbbN)r   rW  r   rb   rc   )
r   payloadCr   payloadApayloadBmessageAmessageBre  r   r]  s
          @@@r   test_recvdChangedz%RecvdAttributeMixin.test_recvdChanged  s    
 ##Ax00	* 	* 	* 	* 	* 	* 	*
 *##Ax00##Ax00	x(*+++(H!566666r   c                    |                                  g }d| j        D ]@}|                    |                     |                     |                               Ag fd}|_                            d                    |                                         d           |                     | j                   |                     j        d           dS )z
        Data already parsed by L{IntNStringReceiver.dataReceived} is not
        reparsed if C{stringReceived} consumes some of the
        L{IntNStringReceiver.recvd} buffer.
        s       c                 t                         |            j        t                    d          _        d S r   )r   r[  rL   )r\  SWITCHr   r]  s    r   r   z:RecvdAttributeMixin.test_switching.<locals>.stringReceived  s1    MM.)))+c&kkmm4EKKKr   r      N)	r   r   r   rW  r   rb   r   rc   r[  )r   mixrj   r   rn  r   r]  s       @@@r   test_switchingz"RecvdAttributeMixin.test_switching  s      ""$ 	 	AJJt''q11222JJv	5 	5 	5 	5 	5 	5 	5  .388C==))) 	7###...g.....r   c                 b   |                                  d}t          |          dz
  _        |                     |          }g fd}|_                            |           |                     d         t          |                     |                     d         |           dS )z
        The L{IntNStringReceiver.recvd} buffer contains all data not yet
        processed by L{IntNStringReceiver.dataReceived} if the
        C{lengthLimitExceeded} event occurs.
        s   too longr#   c                 f                         |                                 j                   d S r   rZ  )rE   r   r]  s    r   rN  zPRecvdAttributeMixin.test_recvdInLengthLimitExceeded.<locals>.lengthLimitExceeded  s/    MM&!!!MM%+&&&&&r   r   N)r   rL   rO   rW  rN  rb   rc   )r   DATAmessagerN  r   r]  s       @@r   test_recvdInLengthLimitExceededz3RecvdAttributeMixin.test_recvdInLengthLimitExceeded  s       ""t99q=""5$//	' 	' 	' 	' 	' 	' %8!7###CII...G,,,,,r   N)	r(   r)   r*   r+   rW  rb  rk  rq  rv  r-   r   r   rU  rU  g  sl         D D D6 6 6$7 7 7./ / /8- - - - -r   rU  c                       e Zd ZdZdS )	TestInt32z
    A L{basic.Int32StringReceiver} storing received strings in an array.

    @ivar received: array holding received strings.
    Nr(   r)   r*   r+   r-   r   r   rx  rx               r   rx  c                   2    e Zd ZdZeZddgZdgZg dZd Z	dS )
Int32Testsz/
    Test case for int32-prefixed protocol
    rZ   rI  s
      aaaaaa)s         hello therer   c                    |                                  }|                    d           |                     |j                                        d           |                    d           |                     |j        dg           dS )z?
        Test specific behavior of the 32-bits length.
        r   s      foos      ubar   ubarNr   r   rc   rG   r   rb   r6   rK  s     r   	test_datazInt32Tests.test_data  s     	V**,,.DEEE	.///gY/////r   N)
r(   r)   r*   r+   rx  r   r   r   r@  r  r-   r   r   r|  r|    sQ          HYG/0N;;;N0 0 0 0 0r   r|  c                       e Zd ZdZdS )	TestInt16z
    A L{basic.Int16StringReceiver} storing received strings in an array.

    @ivar received: array holding received strings.
    Nry  r-   r   r   r  r    rz  r   r  c                   8    e Zd ZdZeZddgZdgZg dZd Z	d Z
dS )	
Int16Testsz/
    Test case for int16-prefixed protocol
    rZ   rI  s    aaaaaa)    r}  r   c                    |                                  }|                    d           |                     |j                                        d           |                    d           |                     |j        dg           dS )z?
        Test specific behavior of the 16-bits length.
        r   s    foos    ubarr  Nr  rK  s     r   r  zInt16Tests.test_data   s}     	V**,,n===	'''gY/////r   c                     |                                  }dd|j        dz  z  dz   z  }|                     t          |j        |           dS zA
        Send too much data: that should cause an error.
        r#  r      r#   Nr   prefixLengthr   AssertionErrorr   r   r   tooSends      r   test_tooLongSendzInt16Tests.test_tooLongSend
  P     ! 23a78.!,@@@@@r   N)r(   r)   r*   r+   r  r   r   r   r@  r  r  r-   r   r   r  r    se          HYG'(N333N0 0 0A A A A Ar   r  c                       e Zd ZdZdS )TestInt8z
    A L{basic.Int8StringReceiver} storing received strings in an array.

    @ivar received: array holding received strings.
    Nry  r-   r   r   r  r    rz  r   r  c                   8    e Zd ZdZeZddgZdgZg dZd Z	d Z
dS )		Int8Testsz.
    Test case for int8-prefixed protocol
    rZ   rI  s     aaaaaa)   s   dzadzr   c                    |                                  }|                    d           |                     |j                                        d           |                    d           |                     |j        dg           dS )z>
        Test specific behavior of the 8-bits length.
        r   s   foos   ubarr  Nr  rK  s     r   r  zInt8Tests.test_data%  s}     	V**,,j999	{###gY/////r   c                     |                                  }dd|j        dz  z  dz   z  }|                     t          |j        |           dS r  r  r  s      r   r  zInt8Tests.test_tooLongSend/  r  r   N)r(   r)   r*   r+   r  r   r   r   r@  r  r  r-   r   r   r  r    se          HYG'(N---N0 0 0A A A A Ar   r  c                   2    e Zd ZdZdZdZd Zd Zd Zd Z	dS )OnlyProducerTransportzm
    Transport which isn't really a transport, just looks like one to
    someone not looking very hard.
    Fc                     g | _         d S r   r   r   s    r   r   zOnlyProducerTransport.__init__A  s    			r   c                     d| _         d S )NTpausedr   s    r   r@   z$OnlyProducerTransport.pauseProducingD  s    r   c                     d| _         d S )NFr  r   s    r   rB   z%OnlyProducerTransport.resumeProducingG  s    r   c                 :    | j                             |           d S r   )r&   r   )r   r   s     r   r   zOnlyProducerTransport.writeJ  s    	r   N)
r(   r)   r*   r+   r  r   r   r@   rB   r   r-   r   r   r  r  8  sf         
 FM               r   r  c                       e Zd ZdZd ZdS )ConsumingProtocolzC
    Protocol that really, really doesn't want any more bytes.
    c                 b    | j                             |           |                                  d S r   )rG   r   r@   r   s     r   r!   zConsumingProtocol.lineReceivedS  s0    T"""r   N)r(   r)   r*   r+   r!   r-   r   r   r  r  N  s-             r   r  c                       e Zd ZdZd ZdS )ProducerTestszM
    Tests for L{basic._PausableMixin} and L{basic.LineReceiver.paused}.
    c                    t                      }t                      }|                    |           |                    d           |                     |j        g            |                     |j                   |                     |j                   |                    d           |                     |j        dg           |                     |j                   |                     |j                   |	                                 |                     |j        dg           |                     |j                   |                     |j                   |                    d           |                     |j        ddg           |                     |j                   |                     |j                   |	                                 |                     |j        g d           |                     |j                   |                     |j                   |                    d           |                     |j        g d           |                     |j                   |                     |j                   |	                                 |                     |j        g d           |                     |j                   |                     |j                   |	                                 |                     |j        g d           |                     |j                   |                     |j                   d	S )
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   )r  r   r   s	   goodbye
)r  r   r   r   N)
r  r  r_   rb   rc   r&   r   r  r   rB   )r   prg   s      r   test_pauseResumezProducerTests.test_pauseResume]  s    !##	 	
z"""$$$"""""" 	
|$$$/!2333!!!!!! 	
/!2333"""""" 	
,---/8!<===!!!!!! 	
!F!F!FGGG!!!!!! 	
~&&&!F!F!FGGG!!!!!! 	
!R!R!RSSS!!!!!! 	
!R!R!RSSS""""""""r   N)r(   r)   r*   r+   r  r-   r   r   r  r  X  s2         A# A# A# A# A#r   r  c                   6    e Zd ZdZd Zd Zd Zd Zd Zd Z	dS )	FileSenderTestsz(
    Tests for L{basic.FileSender}.
    c                 |    t          j                    }|                     t          t          |                     dS )zP
        L{basic.FileSender} implements the L{IPullProducer} interface.
        N)r   
FileSenderr   r   r
   )r   senders     r   test_interfacezFileSenderTests.test_interface  s4     !##Y7788888r   c                    t          d          }t          j                    }t          j                    }|                    ||           |                     |j        |           |                     |j	                   dS )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  beginFileTransferrc   producerr   	streaming)r   sourceconsumerr  s       r   test_producerRegisteredz'FileSenderTests.test_producerRegistered  sy    
 )) 022!##  222*F333+,,,,,r   c                    t          d          }t          j                    }t          j                    }|                    ||          }|                                 |                                 |                     |j                   | 	                    d| 
                    |                     | 	                    d|                                           dS )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  rB   assertIsNoner  rc   successResultOfr   r   r  r  r  ds        r   test_transferzFileSenderTests.test_transfer  s     )) 022!##$$VX66      (+,,,t33A66777(..*:*:;;;;;r   c                    t          d          }t          j                    }t          j                    }d|_        |                    ||          }|                                 |                     d|	                                           |                                 |                     d|	                                           |                                 |                     d|	                                           |                                 |                     d| 
                    |                     |                     d|	                                           dS )zj
        L{basic.FileSender} reads at most C{CHUNK_SIZE} every time it resumes
        producing.
        r  r=   s   Tests   Test conr  N)r   r   r   r   r  
CHUNK_SIZEr  rB   rc   r   r  r  s        r   test_transferMultipleChunksz+FileSenderTests.test_transferMultipleChunks  s<   
 )) 022!##$$VX66   (.."2"2333   hnn&6&6777   (..*:*:;;;   t33A66777(..*:*:;;;;;r   c                    d }t          d          }t          j                    }t          j                    }|                    |||          }|                                 |                                 |                     d|                     |                     |                     d|	                                           dS )z
        L{basic.FileSender.beginFileTransfer} takes a C{transform} argument
        which allows to manipulate the data on the fly.
        c                 *    |                                  S r   )swapcase)chunks    r   	transformz=FileSenderTests.test_transferWithTransform.<locals>.transform  s    >>###r   r     Ts   tEST CONTENTN)
r   r   r   r   r  r  rB   rc   r  r   )r   r  r  r  r  r  s         r   test_transferWithTransformz*FileSenderTests.test_transferWithTransform  s    	$ 	$ 	$ )) 022!##$$VXyAA      t33A66777(..*:*:;;;;;r   c                 r   t          d          }t          j                    }t          j                    }|                    ||          }|                                 |                     |          }|                    t                     | 
                    dt          |j                             dS )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  rC   failureResultOftrap	Exceptionrc   strr   )r   r  r  r  r  failures         r   test_abortedTransferz$FileSenderTests.test_abortedTransfer  s     )) 022!##$$VX66&&q))Y>GM@R@RSSSSSr   N)
r(   r)   r*   r+   r  r  r  r  r  r  r-   r   r   r  r    s}         9 9 9
- 
- 
-< < <$< < <.< < <(T T T T Tr   r  );r+   rB  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   r/   r   rR   SynchronousTestCaserW   r   r   r   r   r<  r   r   r   r?  rU  Int32StringReceiverrx  r|  Int16StringReceiverr  r  Int8StringReceiverr  r  r  r  r  TestCaser  r-   r   r   <module>r     s   
  



       ' ' ' ' ' ' ' ' ' ' . . . . . . + + + + + + + + 1 1 1 1 1 1 4 4 4 4 4 4 # # # # # # + + + + + + * * * * * * & & & & & & " " " " " "# # # # #+ # # #0E: E: E: E: E:# E: E: E:P# # # # #U+ # # #*uJ uJ uJ uJ uJ4 uJ uJ uJp$ $ $ $ $%"4 $ $ $.L1 L1 L1 L1 L1(*F L1 L1 L1^)J )J )J )J )JH8 )J )J )JX                Iu6      7 7 7 7 7 7 7 72UL UL UL UL ULX9? UL UL ULpFL FL FL FL FL FL FL FLRg- g- g- g- g- g- g- g-T    	54   0 0 0 0 0-/@BU 0 0 0*    	54   A A A A A-/@BU A A A:    y%2   A A A A A,.?AT A A A:               ,    *   F# F# F# F# F#H0 F# F# F#RdT dT dT dT dTh' dT dT dT dT dTr   