U
    �Acjó§  ã                   @   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   úE/tmp/pip-unpacked-wheel-nrvc_22y/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ddddddd	d
dddddgZdd„ ZdZdddgZedg Z	dd„ Z
dZdddddgZddddddgZdd„ ZdZdddg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d0d1„ Zd2d3„ Zd4S )5Ú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

as   len 10ó
   0123456789s   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
s   twiddle1s   twiddle2r0   s   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   rG   r   N)rH   r   rI   r   ÚClockr(   rJ   r   rK   r>   ÚpauseBufrM   rN   ÚpauseOutput1r-   ÚadvanceÚpauseOutput2©r   rQ   rR   r*   rS   rT   rU   r   r   r   Útest_pausingÊ   s    
zLineReceiverTests.test_pausings/   twiddle1
twiddle2
len 5
rawpause
12345twiddle3
r1   s   12345c                 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   rG   r   N)rH   r   rI   r   rW   r(   rJ   r   rK   r>   ÚrawpauseBufrM   rN   ÚrawpauseOutput1r-   rZ   ÚrawpauseOutput2r\   r   r   r   Útest_rawPausingç   s    
z!LineReceiverTests.test_rawPausings"   twiddle1
twiddle2
stop
more
stuff
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   rG   N)rH   r   rI   r(   rJ   r   rK   r>   Ústop_bufrM   rN   Ústop_outputr-   rP   r   r   r   Útest_stopProducingû   s    z$LineReceiverTests.test_stopProducingc                 C   sB   t ƒ }t ¡ }| t |¡¡ | d¡ |  |jddddg¡ dS )z6
        Test produce/unproduce in receiving.
        s&   produce
hello world
unproduce
goodbye
r4   s   hello worldr5   ó   goodbyeN)	r(   r   rI   rJ   r   rK   rM   rN   r-   )r   rS   rR   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   rg   s   foo
bar
bazó   foos   bar
bazs   quux
s   quuxr/   N)r   ÚLineReceiverrM   rN   r   r?   )r   rg   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   rI   rJ   r   rK   ÚsysÚgetrecursionlimitrM   rN   Ú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}.
        rk   r   ó   
rN©	r   ri   r   ÚStringTransportrJ   rM   r@   Ú
assertTrueÚdisconnecting©r   ro   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   rk   r   Nr=   r   )r(   r@   r   ru   rJ   rM   r'   ÚassertFalserw   rN   r>   r-   )r   ro   rR   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   
rk   Nr   )r   ri   r'   r   ru   rJ   rM   r@   r>   rz   rw   rx   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   ri   r"   r   ru   rJ   r   rM   ZassertIsInstancer}   )r   ro   r<   Ú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   ri   ÚassertRaisesÚNotImplementedErrorr"   ©r   ro   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   ri   rƒ   r„   r   r…   r   r   r   Útest_lineReceivedNotImplemented~  s    z1LineReceiverTests.test_lineReceivedNotImplementedN)r#   r$   r%   r&   rL   rO   rV   rX   rY   r[   r]   r^   r_   r`   ra   rb   rc   rd   rf   rj   rq   ry   r{   r|   r�   r†   r‡   r   r   r   r   rD   �   sV   ó

ú	
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ˆ   ro   r@   r   ru   r<   rJ   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}.
        rk   é   N)ro   r@   rM   rN   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.
        rk   r�   N)ro   r@   rM   r'   rN   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}.
        rk   r�   N)ro   r'   rn   r@   rM   rN   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}.
        rk   r�   N)ro   r@   r'   rM   rN   r‰   rŽ   r   r   r   Útest_multipleLongLinesË  s     z:LineReceiverLineLengthExceededTests.test_multipleLongLinesc                 C   sB   t  ¡ }t ¡ }| |¡ | d|jd  d ¡ |  |j¡ dS rr   rt   rx   r   r   r   ry   Ö  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}.
        rk   N)r   ri   r   ru   rJ   rM   r@   r>   r'   rv   rw   rx   r   r   r   Útest_maximumLineLengthRemainingá  s
    
zCLineReceiverLineLengthExceededTests.test_maximumLineLengthRemainingN)r#   r$   r%   r&   rŒ   r�   r�   r‘   r’   ry   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   ru   rB   rJ   r   rL   rM   rN   r-   Úsplit)r   rR   rS   Úcr   r   r   rV   ø  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).
        rk   r   rs   N)
rB   r   ru   rJ   rM   r@   r>   r'   rv   rw   rx   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&   rL   rV   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   rU   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   ru   r   rJ   )r   rR   rS   r   r   r   ÚgetProtocol1  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   rM   rv   r<   rw   ©r   rU   Ú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dddddddgZd	d
ddg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/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9S ):ÚNetstringReceiverTestszA
    Tests for L{twisted.protocols.basic.NetstringReceiver}.
    ó   helloó   worlds   hows   ares   you123s   :todays  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaas   9999999999999999999999s   abcs   4:abcdes7   51:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab,c                 C   s$   t  ¡ | _tƒ | _| j | j¡ d S r   )r   ru   r<   r¡   ÚnetstringReceiverrJ   r   r   r   r   rŒ   V  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   rG   i»  N)rH   r   ru   r¡   r@   rJ   ÚstringsÚ
sendStringÚvaluer>   rM   rN   r-   )r   rQ   rR   rS   rU   ÚoutrT   r   r   r   rV   [  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¯   rM   rN   r-   r   r   r   r   Útest_receiveEmptyNetstringm  s    z1NetstringReceiverTests.test_receiveEmptyNetstringc                 C   s"   | j  d¡ |  | j jdg¡ dS )z;
        One-character netstrings can be received.
        ó   1:a,rF   Nr´   r   r   r   r   Útest_receiveOneCharactert  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¯   rM   rv   r<   rw   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¯   rM   rN   r-   rv   Ú_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ó   :rF   ó   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,1rF   s   :b,rË   N)r¯   rM   rv   rÂ   rN   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Ê   rF   N)r¯   r@   rM   rn   rª   rv   r<   rw   )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Ú_consumeLengthrN   Ú_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Ò   rN   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Œ   rV   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¬   F  s<   ü				
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>   rM   rN   r-   )r   r¨   rU   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   rM   rN   r-   r§   r   r   r   Útest_partial2  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±   rN   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.
        rG   r×   N)	r¦   r   ÚlengthLimitExceededr@   rM   rß   rà   rá   rN   )r   r:   r¨   r   r   r   Útest_lengthLimitExceededF  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}.
        rG   r×   s   xxxxxxxxxxxN)r¦   r@   rM   rß   rà   rá   rN   r-   ræ   r   r   r   Útest_longStringNotDeliveredS  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   ÚmakeMessagen  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á   rM   rN   )r   r›   ZcompleteMessageZincompleteMessager   rð   r   Útest_recvdContainsRemainingDatau  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›   rM   rN   )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SWITCHro   rñ   r   r   r›   ­  s    
z:RecvdAttributeMixin.test_switching.<locals>.stringReceivedr/   ó   N)	r¦   r°   r   rì   r›   rM   rn   rN   rî   )r   ZmixrU   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:   ©ro   rñ   r   r   rè   Ç  s    
zPRecvdAttributeMixin.test_recvdInLengthLimitExceeded.<locals>.lengthLimitExceededr   N)r¦   r>   r@   rì   rè   rM   rN   )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ë   g  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                   @   s4   e Zd ZdZeZddgZdgZdddgZdd	„ Z	d
S )Ú
Int32Testsz/
    Test case for int32-prefixed protocol
    rF   rä   s
      aaaaaas      ó   hello therer/   c                 C   sB   |   ¡ }| d¡ |  |j ¡ d¡ | d¡ |  |jdg¡ dS )z?
        Test specific behavior of the 32-bits length.
        rh   s      foos      ubaró   ubarN©r¦   r±   rN   r<   r²   rM   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dddgZdd	„ Z	d
d„ Z
dS )Ú
Int16Testsz/
    Test case for int16-prefixed protocol
    rF   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.
        rh   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dddgZdd	„ Z	d
d„ Z
dS )Ú	Int8Testsz.
    Test case for int8-prefixed protocol
    rF   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.
        rh   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  /  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   A  s    zOnlyProducerTransport.__init__c                 C   s
   d| _ d S )NT©Úpausedr   r   r   r   r6   D  s    z$OnlyProducerTransport.pauseProducingc                 C   s
   d| _ d S )NFr  r   r   r   r   r7   G  s    z%OnlyProducerTransport.resumeProducingc                 C   s   | j  |¡ d S r   )r!   r   )r   rª   r   r   r   r¢   J  s    zOnlyProducerTransport.writeN)
r#   r$   r%   r&   r  rw   r   r6   r7   r¢   r   r   r   r   r  8  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   S  s    zConsumingProtocol.lineReceivedN)r#   r$   r%   r&   r   r   r   r   r   r  N  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dddg¡ |  |j¡ |  |j¡ | d¡ |  |jdddg¡ |  |j¡ |  |j¡ | 	¡  |  |jddddg¡ |  |j¡ |  |j¡ | 	¡  |  |jddddg¡ |  |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
s   hello, worlds   hello
world
r­   r®   s	   goodbye
re   N)
r  r  rJ   rM   rN   r!   rz   r  rv   r7   )r   ÚprR   r   r   r   Útest_pauseResume]  sF    	




zProducerTests.test_pauseResumeN)r#   r$   r%   r&   r  r   r   r   r   r  X  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   Ú
FileSenderrv   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   ru   r   r  ÚbeginFileTransferrN   Úproducerrz   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   ru   r   r  r  r7   ZassertIsNoner  rN   Ú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   ru   r   r  Z
CHUNK_SIZEr  r7   rN   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   ru   r   r  r  r7   rN   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   ru   r   r  r  r8   ZfailureResultOfZtrapÚ	ExceptionrN   Ú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+  r.  r   r   r   r   r  ¡  s   r  );r&   rß   rl   Ú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   ri   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