a
    )¶(bô§  ã                   @   sJ  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„ dejƒZG dd„ dejƒZG dd„ dejƒZ G dd„ dej!ƒZ"G dd„ dejƒZ#G dd„ dej!ƒZ$G dd„ dej!ƒZ%G dd„ dƒZ&G dd„ de&ej'ƒZ(G d d!„ d!ƒZ)G d"d#„ d#ej!e)ƒZ*G d$d%„ d%e)ƒZ+G d&d'„ d'ƒZ,G d(d)„ d)e&ej-ƒZ.G d*d+„ d+ej!e+e,ƒZ/G d,d-„ d-e&ej0ƒZ1G d.d/„ d/ej!e+e,ƒZ2G d0d1„ d1e&ej3ƒZ4G d2d3„ d3ej!e+e,ƒZ5G d4d5„ d5ƒZ6G d6d7„ d7ejƒZ7G d8d9„ d9ej!ƒZ8G d: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                   @   s,   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	S )
ÚFlippingLineTesterzT
    A line receiver that flips between line and raw data modes after one byte.
    ó   
c                 C   s
   g | _ d S ©N)Úlines©Úself© r   ú@lib/python3.9/site-packages/twisted/protocols/test/test_basic.pyÚ__init__!   s    zFlippingLineTester.__init__c                 C   s   | j  |¡ |  ¡  dS )z&
        Set the mode to raw.
        N)r   ÚappendÚ
setRawMode©r   Úliner   r   r   ÚlineReceived$   s    zFlippingLineTester.lineReceivedc                 C   s   |   |dd… ¡ dS )z,
        Set the mode back to line.
        é   N)ÚsetLineMode©r   Údatar   r   r   ÚrawDataReceived+   s    z"FlippingLineTester.rawDataReceivedN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	delimiterr   r   r"   r   r   r   r   r      s
   r   c                   @   sB   e Zd ZdZdZdZddd„Zdd„ Zd	d
„ Zdd„ Z	d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                 C   s
   || _ dS )z@
        If given, use a clock to make callLater calls.
        N)Úclock)r   r*   r   r   r   r   B   s    zLineTester.__init__c                 C   s
   g | _ dS ©z;
        Create/clean data received on connection.
        N©Úreceivedr   r   r   r   ÚconnectionMadeH   s    zLineTester.connectionMadec                 C   sÞ   | j  |¡ |dkr|  ¡  n¼|dkr@|  ¡  | j d| j¡ nš|dkrv|  ¡  |  ¡  | j  d¡ | j d| j¡ nd|dkrˆ|  ¡  nR|dd… dkr¬t|dd… ƒ| _	n.| 
d	¡rÆ| j | d
¡ n| 
d¡rÚ| j ¡  dS )z|
        Receive line and make some action for some tokens: pause, rawpause,
        stop, len, produce, unproduce.
        ó    ó   pauser   ó   rawpauseó   stopNé   s   len ó   produceFó	   unproduce)r-   r   r   ÚpauseProducingr*   Z	callLaterÚresumeProducingÚstopProducingÚintÚlengthÚ
startswithÚ	transportZregisterProducerZunregisterProducerr   r   r   r   r   N   s&    



zLineTester.lineReceivedc                 C   sZ   |d| j … || j d…  }}| j t|ƒ | _ | jd | | jd< | j dkrV|  |¡ dS )zj
        Read raw data, until the quantity specified by a previous 'len' line is
        reached.
        Néÿÿÿÿr   )r:   Úlenr-   r   )r   r!   Úrestr   r   r   r"   g   s
    
zLineTester.rawDataReceivedc                 C   s.   t |ƒ| jd kr*|  || jd d… ¡ dS )z<
        Adjust line mode when long lines received.
        r   N)r>   Ú
MAX_LENGTHr   r   r   r   r   ÚlineLengthExceededr   s    zLineTester.lineLengthExceeded)N)r#   r$   r%   r&   r'   r@   r   r.   r   r"   rA   r   r   r   r   r(   2   s   
r(   c                   @   s(   e Zd ZdZdZdZdd„ Zdd„ ZdS )	ÚLineOnlyTesterz)
    A buffering line only receiver.
    r   r)   c                 C   s
   g | _ dS r+   r,   r   r   r   r   r.   ‚   s    zLineOnlyTester.connectionMadec                 C   s   | j  |¡ dS )z%
        Save received data.
        N©r-   r   r   r   r   r   r   ˆ   s    zLineOnlyTester.lineReceivedN)r#   r$   r%   r&   r'   r@   r.   r   r   r   r   r   rB   z   s
   rB   c                   @   sº   e Zd ZdZdZg d¢Zdd„ ZdZg d¢Zedg Z	d	d
„ Z
dZg d¢Zg d¢Zdd„ ZdZg d¢Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$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                 C   s‚   t ddƒD ]r}t ¡ }tƒ }| t |¡¡ t t| jƒ| d ƒD ](}| j|| |d | … }| 	|¡ qB|  
| j|j¡ q
dS )zl
        Test buffering for different packet size, checking received matches
        expected data.
        r   é
   N)Úranger   ÚStringIOWithoutClosingr(   ÚmakeConnectionr   ÚFileWrapperr>   ÚbufferÚdataReceivedÚassertEqualÚoutputr-   ©r   Úpacket_sizeÚtÚaÚiÚsr   r   r   Útest_buffer·   s    zLineReceiverTests.test_buffers!   twiddle1
twiddle2
pause
twiddle3
)ó   twiddle1ó   twiddle2r0   ó   twiddle3c                 C   s¦   t ddƒD ]–}t ¡ }t ¡ }t|ƒ}| t |¡¡ t t	| j
ƒ| d ƒD ](}| j
|| |d | … }| |¡ qL|  | j|j¡ | d¡ |  | j|j¡ q
dS )zo
        Test pause inside data receiving. It uses fake clock to see if
        pausing/resuming work.
        r   rH   r   N)rI   r   rJ   r   ÚClockr(   rK   r   rL   r>   ÚpauseBufrN   rO   ÚpauseOutput1r-   ÚadvanceÚpauseOutput2©r   rR   rS   r*   rT   rU   rV   r   r   r   Útest_pausingÊ   s    
zLineReceiverTests.test_pausings/   twiddle1
twiddle2
len 5
rawpause
12345twiddle3
)rX   rY   rF   r1   r/   )rX   rY   rF   r1   s   12345rZ   c                 C   s¦   t ddƒD ]–}t ¡ }t ¡ }t|ƒ}| t |¡¡ t t	| j
ƒ| d ƒD ](}| j
|| |d | … }| |¡ qL|  | j|j¡ | d¡ |  | j|j¡ q
dS )z7
        Test pause inside raw date receiving.
        r   rH   r   N)rI   r   rJ   r   r[   r(   rK   r   rL   r>   ÚrawpauseBufrN   rO   ÚrawpauseOutput1r-   r^   ÚrawpauseOutput2r`   r   r   r   Útest_rawPausingç   s    
z!LineReceiverTests.test_rawPausings"   twiddle1
twiddle2
stop
more
stuff
)rX   rY   r2   c                 C   s‚   t ddƒD ]r}t ¡ }tƒ }| t |¡¡ t t| jƒ| d ƒD ](}| j|| |d | … }| 	|¡ qB|  
| j|j¡ q
dS )z-
        Test stop inside producing.
        r   rH   N)rI   r   rJ   r(   rK   r   rL   r>   Ústop_bufrN   rO   Ústop_outputr-   rQ   r   r   r   Útest_stopProducingû   s    z$LineReceiverTests.test_stopProducingc                 C   s>   t ƒ }t ¡ }| t |¡¡ | d¡ |  |jg d¢¡ dS )z6
        Test produce/unproduce in receiving.
        s&   produce
hello world
unproduce
goodbye
)r4   s   hello worldr5   ó   goodbyeN)	r(   r   rJ   rK   r   rL   rN   rO   r-   )r   rT   rS   r   r   r   Útest_lineReceiverAsProducer  s    

ÿz-LineReceiverTests.test_lineReceiverAsProducerc                 C   sh   G dd„ dt jƒ}|ƒ }| d¡ |  |jd¡ |  |jd¡ | 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                   @   s   e Zd Zdd„ ZdS )z@LineReceiverTests.test_clearLineBuffer.<locals>.ClearingReceiverc                 S   s   || _ |  ¡ | _d S r   )r   ZclearLineBufferr?   r   r   r   r   r     s    zMLineReceiverTests.test_clearLineBuffer.<locals>.ClearingReceiver.lineReceivedN)r#   r$   r%   r   r   r   r   r   ÚClearingReceiver  s   rk   s   foo
bar
bazó   foos   bar
bazs   quux
s   quuxr/   N)r   ÚLineReceiverrN   rO   r   r?   )r   rk   r   r   r   r   Útest_clearLineBuffer  s    

z&LineReceiverTests.test_clearLineBufferc                 C   sP   t ƒ }t ¡ }| t |¡¡ t ¡ }| d| ¡ |  	d| d 
|j¡¡ dS )zC
        Test switching modes many times on the same data.
        s   x
xó   xr/   N)r   r   rJ   rK   r   rL   ÚsysÚgetrecursionlimitrN   rO   Újoinr   )r   Úprotor<   Úlimitr   r   r   Útest_stackRecursion*  s    z%LineReceiverTests.test_stackRecursionc                 C   sB   t  ¡ }t ¡ }| |¡ | d|jd  d ¡ |  |j¡ dS ©zx
        C{LineReceiver} disconnects the transport if it receives a line longer
        than its C{MAX_LENGTH}.
        ro   r   ó   
rN©	r   rm   r   ÚStringTransportrK   rN   r@   Ú
assertTrueÚdisconnecting©r   rs   r<   r   r   r   Útest_maximumLineLength5  s
    
z(LineReceiverTests.test_maximumLineLengthc                 C   s–   t ƒ }d|_t ¡ }| |¡ d|jd  }| |¡ | |jdd… ¡ | |jdd… | ¡ |  |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).
        r3   ro   r   Nr=   r   )r(   r@   r   ry   rK   rN   r'   ÚassertFalser{   rO   r>   r-   )r   rs   rS   r   r   r   r   Ú&test_maximumLineLengthPartialDelimiter@  s    	

z8LineReceiverTests.test_maximumLineLengthPartialDelimiterc                 C   sX   t  ¡ }d|_t ¡ }| |¡ | d|j |jdt|jƒd …  ¡ |  	|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   
ro   Nr   )r   rm   r'   r   ry   rK   rN   r@   r>   r~   r{   r|   r   r   r   Ú(test_notQuiteMaximumLineLengthUnfinishedV  s    
 ÿz:LineReceiverTests.test_notQuiteMaximumLineLengthUnfinishedc                 C   sF   t  ¡ }dd„ |_t ¡ }| |¡ | ¡  | d¡}|  |t	¡ dS )zf
        C{LineReceiver.dataReceived} forwards errors returned by
        C{rawDataReceived}.
        c                 S   s   t dƒS )NZoops)ÚRuntimeError©r!   r   r   r   Ú<lambda>o  r/   z5LineReceiverTests.test_rawDataError.<locals>.<lambda>s   dataN)
r   rm   r"   r   ry   rK   r   rN   ZassertIsInstancer   )r   rs   r<   Zwhyr   r   r   Útest_rawDataErrori  s    


z#LineReceiverTests.test_rawDataErrorc                 C   s   t  ¡ }|  t|jd¡ dS )z‰
        When L{LineReceiver.rawDataReceived} is not overridden in a
        subclass, calling it raises C{NotImplementedError}.
        ÚfooN)r   rm   ÚassertRaisesÚNotImplementedErrorr"   ©r   rs   r   r   r   Ú"test_rawDataReceivedNotImplementedv  s    z4LineReceiverTests.test_rawDataReceivedNotImplementedc                 C   s   t  ¡ }|  t|jd¡ dS )z†
        When L{LineReceiver.lineReceived} is not overridden in a subclass,
        calling it raises C{NotImplementedError}.
        r…   N)r   rm   r†   r‡   r   rˆ   r   r   r   Útest_lineReceivedNotImplemented~  s    z1LineReceiverTests.test_lineReceivedNotImplementedN)r#   r$   r%   r&   rM   rP   rW   r\   r]   r_   ra   rb   rc   rd   re   rf   rg   rh   rj   rn   ru   r}   r   r€   r„   r‰   rŠ   r   r   r   r   rD      s0   
	rD   c                   @   s(   e Zd ZdZdd„ Zdd„ Zd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                 C   s
   g | _ d S r   )Ú	longLinesr   r   r   r   r.     s    z*ExcessivelyLargeLineCatcher.connectionMadec                 C   s   dS )z/
        Disregard any received lines.
        Nr   r   r   r   r   r   ’  s    z(ExcessivelyLargeLineCatcher.lineReceivedc                 C   s   | j  |¡ dS )zF
        Record any data that exceeds the line length limits.
        N)rŒ   r   r    r   r   r   rA   —  s    z.ExcessivelyLargeLineCatcher.lineLengthExceededN)r#   r$   r%   r&   r.   r   rA   r   r   r   r   r‹   ‡  s   r‹   c                   @   sH   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dS )Ú#LineReceiverLineLengthExceededTestszO
    Tests for L{twisted.protocols.basic.LineReceiver.lineLengthExceeded}.
    c                 C   s,   t ƒ | _d| j_t ¡ | _| j | j¡ d S )Né   )r‹   rs   r@   r   ry   r<   rK   r   r   r   r   ÚsetUp£  s    
z)LineReceiverLineLengthExceededTests.setUpc                 C   s6   d| j jd d  }| 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}.
        ro   é   N)rs   r@   rN   rO   rŒ   ©r   Z	excessiver   r   r   Útest_longUnendedLine©  s    z8LineReceiverLineLengthExceededTests.test_longUnendedLinec                 C   sB   d| j jd d  }| j  d| j j | ¡ |  |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.
        ro   r   N)rs   r@   rN   r'   rO   rŒ   r‘   r   r   r   Útest_longLineAfterShortLine³  s    z?LineReceiverLineLengthExceededTests.test_longLineAfterShortLinec                 C   sF   | j j d| j jd d  gd ¡}| 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}.
        ro   r   N)rs   r'   rr   r@   rN   rO   rŒ   r‘   r   r   r   Útest_longLineWithDelimiter¾  s
    ÿz>LineReceiverLineLengthExceededTests.test_longLineWithDelimiterc                 C   sB   d| j jd d  | j j d }| 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}.
        ro   r   N)rs   r@   r'   rN   rO   rŒ   r‘   r   r   r   Útest_multipleLongLinesË  s     z:LineReceiverLineLengthExceededTests.test_multipleLongLinesc                 C   sB   t  ¡ }t ¡ }| |¡ | d|jd  d ¡ |  |j¡ dS rv   rx   r|   r   r   r   r}   Ö  s
    
z:LineReceiverLineLengthExceededTests.test_maximumLineLengthc                 C   sD   t  ¡ }t ¡ }| |¡ | d|jt|jƒ  ¡ |  	|j
¡ dS )z…
        C{LineReceiver} disconnects the transport it if receives a non-finished
        line longer than its C{MAX_LENGTH}.
        ro   N)r   rm   r   ry   rK   rN   r@   r>   r'   rz   r{   r|   r   r   r   Útest_maximumLineLengthRemainingá  s
    
zCLineReceiverLineLengthExceededTests.test_maximumLineLengthRemainingN)r#   r$   r%   r&   r   r’   r“   r”   r•   r}   r–   r   r   r   r   r   ž  s   
r   c                   @   s,   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	S )
ÚLineOnlyReceiverTestsz@
    Tests for L{twisted.protocols.basic.LineOnlyReceiver}.
    s7   foo
    bleakness
    desolation
    plastic forks
    c                 C   sT   t  ¡ }tƒ }| |¡ t| jƒD ]}| |¡ q"|  |j| j 	d¡dd… ¡ dS )zW
        Test buffering over line protocol: data received should match buffer.
        r   Nr=   )
r   ry   rB   rK   r   rM   rN   rO   r-   Úsplit)r   rS   rT   Úcr   r   r   rW   ø  s    
z!LineOnlyReceiverTests.test_bufferc                 C   sJ   t ƒ }t ¡ }| |¡ | d|jt|jƒ d  d ¡ |  |j	¡ dS )z
        C{LineOnlyReceiver} disconnects the transport if it receives a
        line longer than its C{MAX_LENGTH} + len(delimiter).
        ro   r   rw   N)
rB   r   ry   rK   rN   r@   r>   r'   rz   r{   r|   r   r   r   Ú!test_greaterThanMaximumLineLength  s    
ÿz7LineOnlyReceiverTests.test_greaterThanMaximumLineLengthc                 C   s   t  ¡ }|  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ˆ   r   r   r   rŠ     s    z5LineOnlyReceiverTests.test_lineReceivedNotImplementedN)r#   r$   r%   r&   rM   rW   rš   rŠ   r   r   r   r   r—   í  s
   r—   c                   @   s8   e Zd Zdd„ Zdd„ ZdZdZefeddœd	d
„Z	dS )Ú	TestMixinc                 C   s
   g | _ d S r   r,   r   r   r   r   r.     s    zTestMixin.connectionMadec                 C   s   | j  |¡ d S r   rC   ©r   rV   r   r   r   ÚstringReceived  s    zTestMixin.stringReceivedé2   r   N)ÚreasonÚreturnc                 C   s
   d| _ d S )Nr   )Úclosed)r   r    r   r   r   ÚconnectionLost#  s    zTestMixin.connectionLost)
r#   r$   r%   r.   rž   r@   r¢   r
   r   r£   r   r   r   r   rœ     s
   rœ   c                   @   s   e Zd Zdd„ ZdS )ÚTestNetstringc                 C   s   | j  |¡ | j |¡ d S r   )r-   r   r<   Úwriter   r   r   r   rž   (  s    zTestNetstring.stringReceivedN)r#   r$   r%   rž   r   r   r   r   r¤   '  s   r¤   c                   @   s>   e Zd ZU g Zeee  ed< dZded< dd„ Z	dd„ Z
dS )	ÚLPTestCaseMixinÚillegalStringsNú!Optional[Type[protocol.Protocol]]r   c                 C   s   t  ¡ }|  ¡ }| |¡ |S )z„
        Return a new instance of C{self.protocol} connected to a new instance
        of L{proto_helpers.StringTransport}.
        )r   ry   r   rK   )r   rS   rT   r   r   r   ÚgetProtocol2  s    
zLPTestCaseMixin.getProtocolc                 C   s>   | j D ]2}|  ¡ }t|ƒD ]}| |¡ q|  |jj¡ qdS )zO
        Assert that illegal strings cause the transport to be closed.
        N)r§   r©   r   rN   rz   r<   r{   ©r   rV   Úrr™   r   r   r   Útest_illegal<  s
    
zLPTestCaseMixin.test_illegal)r#   r$   r%   r§   r   r   ÚbytesÚ__annotations__r   r©   r¬   r   r   r   r   r¦   -  s   

r¦   c                   @   sÔ   e Zd ZdZg d¢Zg d¢ZeZdd„ Zdd„ Z	dd	„ Z
d
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0S )1ÚNetstringReceiverTestszA
    Tests for L{twisted.protocols.basic.NetstringReceiver}.
    )ó   helloó   worlds   hows   ares   you123s   :todays  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)s   9999999999999999999999s   abcs   4:abcdes7   51:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab,c                 C   s$   t  ¡ | _tƒ | _| j | j¡ d S r   )r   ry   r<   r¤   ÚnetstringReceiverrK   r   r   r   r   r   W  s    
zNetstringReceiverTests.setUpc                 C   s    t ddƒD ]}t ¡ }tƒ }d|_| |¡ | jD ]}| |¡ q2| ¡ }t t	|ƒ| d ƒD ]*}||| |d | … }|r^| 
|¡ q^|  |j| j¡ q
dS )zI
        Strings can be received in chunks of different lengths.
        r   rH   i»  N)rI   r   ry   r¤   r@   rK   ÚstringsÚ
sendStringÚvaluer>   rN   rO   r-   )r   rR   rS   rT   rV   ÚoutrU   r   r   r   rW   \  s    

z"NetstringReceiverTests.test_bufferc                 C   s"   | j  d¡ |  | j jdg¡ dS )zE
        Empty netstrings (with length '0') can be received.
        s   0:,r/   N©r²   rN   rO   r-   r   r   r   r   Útest_receiveEmptyNetstringn  s    z1NetstringReceiverTests.test_receiveEmptyNetstringc                 C   s"   | j  d¡ |  | j jdg¡ dS )z;
        One-character netstrings can be received.
        ó   1:a,rG   Nr·   r   r   r   r   Útest_receiveOneCharacteru  s    z/NetstringReceiverTests.test_receiveOneCharacterc                 C   s"   | j  d¡ |  | j jdg¡ dS )z;
        Two-character netstrings can be received.
        s   2:ab,ó   abNr·   r   r   r   r   Útest_receiveTwoCharacters|  s    z0NetstringReceiverTests.test_receiveTwoCharactersc                 C   s"   | 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   r   r   r   Útest_receiveNestedNetstringƒ  s    z2NetstringReceiverTests.test_receiveNestedNetstringc                 C   s   | j  d¡ |  | jj¡ dS )zL
        Netstrings containing more data than expected are refused.
        s   2:aaa,N©r²   rN   rz   r<   r{   r   r   r   r   Útest_moreDataThanSpecifiedŒ  s    z1NetstringReceiverTests.test_moreDataThanSpecifiedc                 C   s   | 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   r   r   r   Ú$test_moreDataThanSpecifiedBorderCase“  s    z;NetstringReceiverTests.test_moreDataThanSpecifiedBorderCasec                 C   s   | j  d¡ |  | jj¡ dS )z`
        Netstrings without leading digits that specify the length
        are refused.
        s   :aaa,Nr¾   r   r   r   r   Útest_missingNumber›  s    z)NetstringReceiverTests.test_missingNumberc                 C   s   | j  d¡ |  | jj¡ dS )zg
        Netstrings without a colon between length specification and
        data are refused.
        s   3aaa,Nr¾   r   r   r   r   Útest_missingColon£  s    z(NetstringReceiverTests.test_missingColonc                 C   s   | j  d¡ |  | jj¡ dS )zY
        Netstrings that have no leading digits nor a colon are
        refused.
        s   aaa,Nr¾   r   r   r   r   Útest_missingNumberAndColon«  s    z1NetstringReceiverTests.test_missingNumberAndColonc                 C   s   | j  d¡ |  | jj¡ dS )zA
        Netstrings consisting only of data are refused.
        s   aaaNr¾   r   r   r   r   Útest_onlyData³  s    z$NetstringReceiverTests.test_onlyDatac                 C   s>   | 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²   rN   rO   r-   rz   Ú_payloadCompleter   r   r   r   Útest_receiveNetstringPortions_1º  s    z6NetstringReceiverTests.test_receiveNetstringPortions_1c                 C   s,   dD ]}| j  |¡ q|  | 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ó   ,rE   Nr·   ©r   Úpartr   r   r   Útest_receiveNetstringPortions_2Ã  s    z6NetstringReceiverTests.test_receiveNetstringPortions_2c                 C   s,   dD ]}| j  |¡ q|  | j jdg¡ dS )zE
        Netstrings can be received one character at a time.
        )ó   2ó   :rG   ó   brÈ   r»   Nr·   rÉ   r   r   r   Útest_receiveNetstringPortions_3Ì  s    z6NetstringReceiverTests.test_receiveNetstringPortions_3c                 C   sR   | 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,1rG   s   :b,rÎ   N)r²   rN   rz   rÅ   rO   r-   r   r   r   r   Útest_receiveTwoNetstringsÔ  s
    z0NetstringReceiverTests.test_receiveTwoNetstringsc                 C   s>   | j jd }| j  d t|ƒdd| f¡¡ |  | jj¡ dS )zs
        Netstrings with a length specification exceeding the specified
        C{MAX_LENGTH} are refused.
        r   r/   rÍ   rG   N)r²   r@   rN   rr   r­   rz   r<   r{   )r   ZtooLongr   r   r   Útest_maxReceiveLimità  s
    ÿz+NetstringReceiverTests.test_maxReceiveLimitc                 C   s&   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Ú_consumeLengthrO   Ú_expectedPayloadSizer   r   r   r   Útest_consumeLengthë  s    
z)NetstringReceiverTests.test_consumeLengthc                 C   s.   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Ô   r@   rÕ   rO   rÖ   r   r   r   r   Útest_consumeLengthBorderCase1ô  s    
z4NetstringReceiverTests.test_consumeLengthBorderCase1c                 C   s&   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Ô   r@   r†   r   ZNetstringParseErrorrÕ   r   r   r   r   Útest_consumeLengthBorderCase2þ  s
    
ÿz4NetstringReceiverTests.test_consumeLengthBorderCase2c                 C   s&   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:rÚ   NrÛ   r   r   r   r   Útest_consumeLengthBorderCase3
  s
    
ÿz4NetstringReceiverTests.test_consumeLengthBorderCase3c                 C   s   t  ¡ }|  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ˆ   r   r   r   Ú!test_stringReceivedNotImplemented  s    z8NetstringReceiverTests.test_stringReceivedNotImplementedN)r#   r$   r%   r&   r³   r§   r¤   r   r   rW   r¸   rº   r¼   r½   r¿   rÀ   rÁ   rÂ   rÃ   rÄ   rÆ   rË   rÏ   rÐ   rÑ   r×   rÙ   rÜ   rÝ   rß   r   r   r   r   r¯   G  s4   				
r¯   c                   @   sŠ   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d	„ Zd
d„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚIntNTestCaseMixinz4
    TestCase mixin for int-prefixed protocols.
    Nr¨   r   r³   r§   ÚpartialStringsc                 C   sR   |   ¡ }| jD ].}tt |jt|ƒ¡| ƒD ]}| |¡ q,q|  |j	| j¡ dS )z>
        Test receiving data find the same data send.
        N)
r©   r³   r   ÚstructÚpackÚstructFormatr>   rN   rO   r-   )r   r«   rV   r™   r   r   r   Útest_receive)  s
    
zIntNTestCaseMixin.test_receivec                 C   s>   | j D ]2}|  ¡ }t|ƒD ]}| |¡ q|  |jg ¡ qdS )zK
        Send partial data, nothing should be definitely received.
        N)rá   r©   r   rN   rO   r-   rª   r   r   r   Útest_partial3  s
    
zIntNTestCaseMixin.test_partialc                 C   s6   |   ¡ }| d¡ |  |j ¡ t |jd¡d ¡ dS )z2
        Test sending data over protocol.
        ó   bbbbbbbbbbbbbbbbé   N)r©   r´   rO   r<   rµ   râ   rã   rä   ©r   r«   r   r   r   Ú	test_send=  s
    
ÿzIntNTestCaseMixin.test_sendc                 C   s@   g }|   ¡ }|j|_d|_| t |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.
        rH   rÚ   N)	r©   r   ÚlengthLimitExceededr@   rN   râ   rã   rä   rO   )r   r:   r«   r   r   r   Útest_lengthLimitExceededG  s    z*IntNTestCaseMixin.test_lengthLimitExceededc                 C   s8   |   ¡ }d|_| t |jd¡d ¡ |  |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}.
        rH   rÚ   s   xxxxxxxxxxxN)r©   r@   rN   râ   rã   rä   rO   r-   ré   r   r   r   Útest_longStringNotDeliveredT  s    z-IntNTestCaseMixin.test_longStringNotDeliveredc                 C   s   t  ¡ }|  t|jd¡ dS )zŽ
        When L{IntNStringReceiver.stringReceived} is not overridden in a
        subclass, calling it raises C{NotImplementedError}.
        r…   N)r   ZIntNStringReceiverr†   r‡   rž   rˆ   r   r   r   rß   _  s    z3IntNTestCaseMixin.test_stringReceivedNotImplemented)r#   r$   r%   r&   r   r®   r³   r   r   r­   r§   rá   rå   ræ   rê   rì   rí   rß   r   r   r   r   rà     s   



rà   c                   @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
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                 C   s   t  |jt|ƒ¡| S )zg
        Return C{data} prefixed with message length in C{protocol.structFormat}
        form.
        )râ   rã   rä   r>   )r   r   r!   r   r   r   ÚmakeMessageo  s    zRecvdAttributeMixin.makeMessagec                    sd   g ‰|   ¡ ‰ ‡ ‡fdd„}|ˆ _t ˆ jd¡d }t ˆ jd¡d }ˆ  || ¡ |  ˆ|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                    s   ˆ  ˆ j¡ d S r   ©r   Úrecvd©ZreceivedString©r«   Úresultr   r   rž   ~  s    zKRecvdAttributeMixin.test_recvdContainsRemainingData.<locals>.stringReceivedé   ó   aaaaas   bbbbN)r©   rž   râ   rã   rä   rN   rO   )r   rž   ZcompleteMessageZincompleteMessager   ró   r   Útest_recvdContainsRemainingDatav  s    z3RecvdAttributeMixin.test_recvdContainsRemainingDatac                    st   |   ¡ ‰g ‰d}|  ˆ|¡‰ ‡ ‡‡fdd„}|ˆ_d}d}|  ˆ|¡}|  ˆ|¡}ˆ || ¡ |  ˆ||g¡ dS )zŠ
        In stringReceived, if recvd is changed, messages should be parsed from
        it rather than the input to dataReceived.
        s   cccccc                    s   ˆs
ˆ ˆ_ ˆ | ¡ d S r   )rñ   r   rò   ©ZmessageCr«   rô   r   r   rž   ’  s    z=RecvdAttributeMixin.test_recvdChanged.<locals>.stringReceivedrö   s   bbbbbN)r©   rï   rž   rN   rO   )r   ZpayloadCrž   ZpayloadAZpayloadBZmessageAZmessageBr   rø   r   Útest_recvdChangedˆ  s    z%RecvdAttributeMixin.test_recvdChangedc                    sŒ   |   ¡ ‰g }d‰ | jD ] }| |  ˆ|¡¡ | ˆ ¡ qg ‰‡ ‡‡fd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                    s"   ˆ  | ¡ ˆjtˆ ƒd … ˆ_d S r   )r   rñ   r>   rò   ©ZSWITCHrs   rô   r   r   rž   ®  s    
z:RecvdAttributeMixin.test_switching.<locals>.stringReceivedr/   ó   N)	r©   r³   r   rï   rž   rN   rr   rO   rñ   )r   ZmixrV   rž   r   rú   r   Útest_switchingŸ  s    

z"RecvdAttributeMixin.test_switchingc                    sp   |   ¡ ‰ d}t|ƒd ˆ _|  ˆ |¡}g ‰‡ ‡fd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                    s   ˆ  | ¡ ˆ  ˆ j¡ d S r   rð   )r:   ©rs   rô   r   r   rë   È  s    
zPRecvdAttributeMixin.test_recvdInLengthLimitExceeded.<locals>.lengthLimitExceededr   N)r©   r>   r@   rï   rë   rN   rO   )r   ZDATAÚmessagerë   r   rý   r   Útest_recvdInLengthLimitExceeded»  s    
z3RecvdAttributeMixin.test_recvdInLengthLimitExceededN)	r#   r$   r%   r&   rï   r÷   rù   rü   rÿ   r   r   r   r   rî   h  s   rî   c                   @   s   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   r   r   Ò  s   r   c                   @   s2   e Zd ZdZeZddgZdgZg d¢Zdd„ Z	dS )	Ú
Int32Testsz/
    Test case for int32-prefixed protocol
    rG   rç   s
      aaaaaa)s      ó   hello therer/   c                 C   sB   |   ¡ }| d¡ |  |j ¡ d¡ | d¡ |  |jdg¡ dS )z?
        Test specific behavior of the 32-bits length.
        rl   s      foos      ubaró   ubarN©r©   r´   rO   r<   rµ   rN   r-   ré   r   r   r   Ú	test_dataä  s
    

zInt32Tests.test_dataN)
r#   r$   r%   r&   r   r   r³   r§   rá   r  r   r   r   r   r  Ú  s   r  c                   @   s   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.
    Nr  r   r   r   r   r  ï  s   r  c                   @   s:   e Zd ZdZeZddgZdgZg d¢Zdd„ Z	dd	„ Z
d
S )Ú
Int16Testsz/
    Test case for int16-prefixed protocol
    rG   rç   s    aaaaaa)ó    r  r/   c                 C   sB   |   ¡ }| d¡ |  |j ¡ d¡ | d¡ |  |jdg¡ dS )z?
        Test specific behavior of the 16-bits length.
        rl   s    foos    ubarr  Nr  ré   r   r   r   r    s
    

zInt16Tests.test_datac                 C   s2   |   ¡ }dd|jd  d  }|  t|j|¡ dS ©zA
        Send too much data: that should cause an error.
        rÎ   r   é   r   N©r©   ZprefixLengthr†   ÚAssertionErrorr´   ©r   r«   ZtooSendr   r   r   Útest_tooLongSend  s    zInt16Tests.test_tooLongSendN)r#   r$   r%   r&   r  r   r³   r§   rá   r  r  r   r   r   r   r  ÷  s   
r  c                   @   s   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.
    Nr  r   r   r   r   r    s   r  c                   @   s:   e Zd ZdZeZddgZdgZg d¢Zdd„ Z	dd	„ Z
d
S )Ú	Int8Testsz.
    Test case for int8-prefixed protocol
    rG   rç   s     aaaaaa)ó   s   dzadzr/   c                 C   sB   |   ¡ }| d¡ |  |j ¡ d¡ | d¡ |  |jdg¡ dS )z>
        Test specific behavior of the 8-bits length.
        rl   s   foos   ubarr  Nr  ré   r   r   r   r  &  s
    

zInt8Tests.test_datac                 C   s2   |   ¡ }dd|jd  d  }|  t|j|¡ dS r
  r  r  r   r   r   r  0  s    zInt8Tests.test_tooLongSendN)r#   r$   r%   r&   r  r   r³   r§   rá   r  r  r   r   r   r   r    s   
r  c                   @   s8   e Zd ZdZdZdZdd„ Zdd„ Zdd„ Zd	d
„ Z	dS )ÚOnlyProducerTransportzm
    Transport which isn't really a transport, just looks like one to
    someone not looking very hard.
    Fc                 C   s
   g | _ d S r   r‚   r   r   r   r   r   B  s    zOnlyProducerTransport.__init__c                 C   s
   d| _ d S )NT©Úpausedr   r   r   r   r6   E  s    z$OnlyProducerTransport.pauseProducingc                 C   s
   d| _ d S )NFr  r   r   r   r   r7   H  s    z%OnlyProducerTransport.resumeProducingc                 C   s   | j  |¡ d S r   )r!   r   )r   r­   r   r   r   r¥   K  s    zOnlyProducerTransport.writeN)
r#   r$   r%   r&   r  r{   r   r6   r7   r¥   r   r   r   r   r  9  s   r  c                   @   s   e Zd ZdZdd„ ZdS )ÚConsumingProtocolzC
    Protocol that really, really doesn't want any more bytes.
    c                 C   s   | j  |¡ |  ¡  d S r   )r<   r¥   r6   r   r   r   r   r   T  s    zConsumingProtocol.lineReceivedN)r#   r$   r%   r&   r   r   r   r   r   r  O  s   r  c                   @   s   e Zd ZdZdd„ ZdS )ÚProducerTestszM
    Tests for L{basic._PausableMixin} and L{basic.LineReceiver.paused}.
    c                 C   sª  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±   ri   N)
r  r  rK   rN   rO   r!   r~   r  rz   r7   )r   ÚprS   r   r   r   Útest_pauseResume^  sF    	




zProducerTests.test_pauseResumeN)r#   r$   r%   r&   r  r   r   r   r   r  Y  s   r  c                   @   s@   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dS )ÚFileSenderTestsz(
    Tests for L{basic.FileSender}.
    c                 C   s   t  ¡ }|  tt|ƒ¡ dS )zP
        L{basic.FileSender} implements the L{IPullProducer} interface.
        N)r   Ú
FileSenderrz   r   r	   )r   Úsenderr   r   r   Útest_interface§  s    zFileSenderTests.test_interfacec                 C   sB   t dƒ}t ¡ }t ¡ }| ||¡ |  |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   ry   r   r  ÚbeginFileTransferrO   Úproducerr~   Z	streaming)r   ÚsourceÚconsumerr  r   r   r   Útest_producerRegistered®  s    z'FileSenderTests.test_producerRegisteredc                 C   sf   t dƒ}t ¡ }t ¡ }| ||¡}| ¡  | ¡  |  |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   ry   r   r  r   r7   ZassertIsNoner!  rO   ÚsuccessResultOfrµ   ©r   r"  r#  r  Údr   r   r   Útest_transferº  s    zFileSenderTests.test_transferc                 C   s    t dƒ}t ¡ }t ¡ }d|_| ||¡}| ¡  |  d| 	¡ ¡ | ¡  |  d| 	¡ ¡ | ¡  |  d| 	¡ ¡ | ¡  |  d|  
|¡¡ |  d| 	¡ ¡ dS )zj
        L{basic.FileSender} reads at most C{CHUNK_SIZE} every time it resumes
        producing.
        r  r3   s   Tests   Test conr%  N)r   r   ry   r   r  Z
CHUNK_SIZEr   r7   rO   rµ   r&  r'  r   r   r   Útest_transferMultipleChunksÌ  s    z+FileSenderTests.test_transferMultipleChunksc                 C   sd   dd„ }t dƒ}t ¡ }t ¡ }| |||¡}| ¡  | ¡  |  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   s   |   ¡ S r   )Úswapcase)Úchunkr   r   r   Ú	transformé  s    z=FileSenderTests.test_transferWithTransform.<locals>.transformr  ó   Ts   tEST CONTENTN)
r   r   ry   r   r  r   r7   rO   r&  rµ   )r   r-  r"  r#  r  r(  r   r   r   Útest_transferWithTransformã  s    z*FileSenderTests.test_transferWithTransformc                 C   sV   t dƒ}t ¡ }t ¡ }| ||¡}| ¡  |  |¡}| 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   ry   r   r  r   r8   ZfailureResultOfZtrapÚ	ExceptionrO   Ústrrµ   )r   r"  r#  r  r(  Zfailurer   r   r   Útest_abortedTransfer÷  s    

z$FileSenderTests.test_abortedTransferN)
r#   r$   r%   r&   r  r$  r)  r*  r/  r2  r   r   r   r   r  ¢  s   r  );r&   râ   rp   Úior   Útypingr   r   r   Zzope.interface.verifyr   Ztwisted.internetr   r   Ztwisted.internet.interfacesr	   Ztwisted.internet.protocolr
   Ztwisted.protocolsr   Ztwisted.python.compatr   Ztwisted.python.failurer   Ztwisted.testr   Ztwisted.trialr   rm   r   r(   r›   rB   ZSynchronousTestCaserD   r‹   r   r—   rœ   rÞ   r¤   r¦   r¯   rà   rî   ZInt32StringReceiverr   r  ZInt16StringReceiverr  r  ZInt8StringReceiverr  r  r  r  r  ZTestCaser  r   r   r   r   Ú<module>   sL   H yO, YIj
I