U
    
W[‹«  ã                   @   sz  d Z ddlmZmZ ddlZddlZddl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mZ ddlmZ ddlmZ d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'e+ƒ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„ d1e1e+ƒZ3G d2d3„ d3e2ƒZ4G d4d5„ d5e%ej5ƒZ6G d6d7„ d7ej e*e,ƒZ7G d8d9„ d9e+ƒZ8G d:d;„ d;ejƒZ9G d<d=„ d=ej ƒZ:G d>d?„ d?ej;ƒZ<G d@dA„ dAej;ƒZ=dS )Bz,
Test cases for L{twisted.protocols.basic}.
é    )ÚdivisionÚabsolute_importN)ÚBytesIO)ÚverifyObject)Ú_PY3Ú	iterbytes)Úunittest)Úbasic)Úreflect)ÚprotocolÚtask)Ú	IProducer)Úproto_helpersz&All classes are new style on Python 3.c                   @   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   úC/usr/lib/python3/dist-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   G   s    zLineTester.__init__c                 C   s
   g | _ dS ©z;
        Create/clean data received on connection.
        N©Úreceivedr   r   r   r   ÚconnectionMadeN   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   U   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   )r9   Úlenr,   r   )r   r    Úrestr   r   r   r!   o   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   ÚlineLengthExceeded{   s    zLineTester.lineLengthExceeded)N)r"   r#   r$   r%   r&   r?   r   r-   r   r!   r@   r   r   r   r   r'   7   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   rA   „   s
   rA   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   twiddle2r/   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   rF   r   N)rG   r   rH   r   ÚClockr'   rI   r   rJ   r=   ÚpauseBufrL   rM   ÚpauseOutput1r,   ÚadvanceÚpauseOutput2©r   rP   rQ   r)   rR   rS   rT   r   r   r   Útest_pausingÊ   s    
zLineReceiverTests.test_pausings/   twiddle1
twiddle2
len 5
rawpause
12345twiddle3
r0   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   rF   r   N)rG   r   rH   r   rV   r'   rI   r   rJ   r=   ÚrawpauseBufrL   rM   ÚrawpauseOutput1r,   rY   ÚrawpauseOutput2r[   r   r   r   Útest_rawPausingâ   s    
z!LineReceiverTests.test_rawPausings"   twiddle1
twiddle2
stop
more
stuff
r1   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   rF   N)rG   r   rH   r'   rI   r   rJ   r=   Ústop_bufrL   rM   Ústop_outputr,   rO   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
r3   s   hello worldr4   ó   goodbyeN)	r'   r   rH   rI   r   rJ   rL   rM   r,   )r   rR   rQ   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   rf   s   foo
bar
bazó   foos   bar
bazs   quux
s   quuxr.   N)r	   ÚLineReceiverrL   rM   r   r>   )r   rf   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   rH   rI   r   rJ   ÚsysÚgetrecursionlimitrL   rM   Ú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}.
        rj   r   ó   
rN©	r	   rh   r   ÚStringTransportrI   rL   r?   Ú
assertTrueÚdisconnecting©r   rn   r;   r   r   r   Útest_maximumLineLength3  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).
        r2   rj   r   Nr<   r   )r'   r?   r   rt   rI   rL   r&   ÚassertFalserv   rM   r=   r,   )r   rn   rQ   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   
rj   Nr   )r	   rh   r&   r   rt   rI   rL   r?   r=   ry   rv   rw   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	   rh   r!   r   rt   rI   r   rL   ZassertIsInstancer|   )r   rn   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	   rh   ÚassertRaisesÚNotImplementedErrorr!   ©r   rn   r   r   r   Ú"test_rawDataReceivedNotImplementedw  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	   rh   r   r‚   r   rƒ   r   r   r   Útest_lineReceivedNotImplemented€  s    z1LineReceiverTests.test_lineReceivedNotImplementedN)r"   r#   r$   r%   rK   rN   rU   rW   rX   rZ   r\   r]   r^   r_   r`   ra   rb   rc   re   ri   rp   rx   rz   r{   r   r„   r…   r   r   r   r   rC   š   sJ          þ

 ÿ
	rC   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   r@   ›  s    z.ExcessivelyLargeLineCatcher.lineLengthExceededN)r"   r#   r$   r%   r-   r   r@   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†   rn   r?   r   rt   r;   rI   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}.
        rj   é   N)rn   r?   rL   rM   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.
        rj   r‹   N)rn   r?   rL   r&   rM   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}.
        rj   r‹   N)rn   r&   rm   r?   rL   rM   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}.
        rj   r‹   N)rn   r?   r&   rL   rM   r‡   rŒ   r   r   r   Útest_multipleLongLinesÒ  s
     ÿz:LineReceiverLineLengthExceededTests.test_multipleLongLinesc                 C   sB   t  ¡ }t ¡ }| |¡ | d|jd  d ¡ |  |j¡ dS rq   rs   rw   r   r   r   rx   ß  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}.
        rj   N)r	   rh   r   rt   rI   rL   r?   r=   r&   ru   rv   rw   r   r   r   Útest_maximumLineLengthRemainingë  s
    
zCLineReceiverLineLengthExceededTests.test_maximumLineLengthRemainingN)r"   r#   r$   r%   rŠ   r   rŽ   r   r   rx   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   rt   rA   rI   r   rK   rL   rM   r,   Úsplit)r   rQ   rR   Úcr   r   r   rU     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).
        rj   r   rr   N)
rA   r   rt   rI   rL   r?   r=   r&   ru   rv   rw   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%   rK   rU   r•   r…   r   r   r   r   r’   ø  s
   r’   c                   @   s,   e Zd Zdd„ Zdd„ ZdZdZ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   rB   ©r   rT   r   r   r   ÚstringReceived,  s    zTestMixin.stringReceivedé2   r   c                 C   s
   d| _ d S )Nr   )Úclosed)r   Úreasonr   r   r   ÚconnectionLost3  s    zTestMixin.connectionLostN)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ž   8  s   rž   c                   @   s$   e Zd Zg ZdZdd„ Zdd„ ZdS )ÚLPTestCaseMixinNc                 C   s   t  ¡ }|  ¡ }| |¡ |S )z„
        Return a new instance of C{self.protocol} connected to a new instance
        of L{proto_helpers.StringTransport}.
        )r   rt   r   rI   )r   rQ   rR   r   r   r   ÚgetProtocolF  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)ÚillegalStringsr¡   r   rL   ru   r;   rv   ©r   rT   Úrr”   r   r   r   Útest_illegalQ  s
    
zLPTestCaseMixin.test_illegal)r"   r#   r$   r¢   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   rt   r;   rž   ÚnetstringReceiverrI   r   r   r   r   rŠ   j  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   rF   i»  N)rG   r   rt   rž   r?   rI   ÚstringsÚ
sendStringÚvaluer=   rL   rM   r,   )r   rP   rQ   rR   rT   ÚoutrS   r   r   r   rU   p  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©   rL   rM   r,   r   r   r   r   Útest_receiveEmptyNetstringƒ  s    z1NetstringReceiverTests.test_receiveEmptyNetstringc                 C   s"   | j  d¡ |  | j jdg¡ dS )z;
        One-character netstrings can be received.
        ó   1:a,rE   Nr®   r   r   r   r   Útest_receiveOneCharacter‹  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©   rL   ru   r;   rv   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©   rL   rM   r,   ru   Ú_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ó   ,rD   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ó   :rE   ó   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,1rE   s   :b,rÅ   N)r©   rL   ru   r¼   rM   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Ä   rE   N)r©   r?   rL   rm   Úbytesru   r;   rv   )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Ú_consumeLengthrM   Ú_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Í   rM   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Š   rU   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¦   ]  s@   ÿ  þ
				

	
r¦   c                   @   sP   e Zd ZdZdZd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 )ÚIntNTestCaseMixinz4
    TestCase mixin for int-prefixed protocols.
    Nc                 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=   rL   rM   r,   )r   r¤   rT   r”   r   r   r   Útest_receiveO  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)ÚpartialStringsr¡   r   rL   rM   r,   r£   r   r   r   Útest_partialZ  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«   rM   r;   r¬   rÙ   rÚ   rÛ   ©r   r¤   r   r   r   Ú	test_sende  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.
        rF   rÒ   N)	r¡   r   ÚlengthLimitExceededr?   rL   rÙ   rÚ   rÛ   rM   )r   r9   r¤   r   r   r   Útest_lengthLimitExceededo  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}.
        rF   rÒ   s   xxxxxxxxxxxN)r¡   r?   rL   rÙ   rÚ   rÛ   rM   r,   rá   r   r   r   Útest_longStringNotDelivered}  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Ø   E  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   ÚmakeMessage›  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Û   rL   rM   )r   r™   ZcompleteMessageZincompleteMessager   rë   r   Útest_recvdContainsRemainingData£  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™   rL   rM   )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SWITCHrn   rì   r   r   r™   Ø  s    
z:RecvdAttributeMixin.test_switching.<locals>.stringReceivedr.   ó   N)	r¡   rª   r   rç   r™   rL   rm   rM   ré   )r   ZmixrT   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è   )r9   ©rn   rì   r   r   rã   ò  s    
zPRecvdAttributeMixin.test_recvdInLengthLimitExceeded.<locals>.lengthLimitExceededr   N)r¡   r=   r?   rç   rã   rL   rM   )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æ   ”  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
    rE   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.
        rg   s      foos      ubaró   ubarN©r¡   r«   rM   r;   r¬   rL   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
    rE   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.
        rg   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 )ÚNewStyleTestInt16z0
    A new-style class version of TestInt16
    Nrù   r   r   r   r   r  D  s   r  c                   @   s   e Zd ZdZereZeZdS )ÚNewStyleInt16Testszn
    This test case verifies that IntNStringReceiver still works when inherited
    by a new-style class.
    N)	r"   r#   r$   r%   r   Ú_PY3NEWSTYLESKIPÚskipr  r   r   r   r   r   r	  K  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  W  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
    rE   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.
        rg   s   foos   ubarrü   Nrý   rá   r   r   r   rþ   k  s
    

zInt8Tests.test_datac                 C   s2   |   ¡ }dd|jd  d  }|  t|j|¡ dS r  r  r  r   r   r   r  v  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   ‰  s    zOnlyProducerTransport.__init__c                 C   s
   d| _ d S )NT©Úpausedr   r   r   r   r5     s    z$OnlyProducerTransport.pauseProducingc                 C   s
   d| _ d S )NFr  r   r   r   r   r6   ‘  s    z%OnlyProducerTransport.resumeProducingc                 C   s   | j  |¡ d S r   )r    r   )r   rÈ   r   r   r   rŸ   •  s    zOnlyProducerTransport.writeN)
r"   r#   r$   r%   r  rv   r   r5   r6   rŸ   r   r   r   r   r  €  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Ÿ   r5   r   r   r   r   r   Ÿ  s    zConsumingProtocol.lineReceivedN)r"   r#   r$   r%   r   r   r   r   r   r  š  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
rd   N)
r  r  rI   rL   rM   r    ry   r  ru   r6   )r   ÚprQ   r   r   r   Útest_pauseResumeª  sR    	




 
ÿ 
ÿzProducerTests.test_pauseResumeN)r"   r#   r$   r%   r  r   r   r   r   r  ¥  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	   Ú
FileSenderru   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   rt   r	   r  ÚbeginFileTransferrM   Úproducerry   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   rt   r	   r  r  r6   ZassertIsNoner  rM   Ú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  r2   s   Tests   Test conr   N)r   r   rt   r	   r  Z
CHUNK_SIZEr  r6   rM   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   rt   r	   r  r  r6   rM   r!  r¬   )r   r(  r  r  r  r#  r   r   r   Útest_transferWithTransform6  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   rt   r	   r  r  r7   ZfailureResultOfZtrapÚ	ExceptionrM   Ústrr¬   )r   r  r  r  r#  Zfailurer   r   r   Útest_abortedTransferK  s    

ÿz$FileSenderTests.test_abortedTransferN)
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erdZdd„ ZdS )ÚMiceDeprecationTestsz2
    L{twisted.protocols.mice} is deprecated.
    z7twisted.protocols.mice is not being ported to Python 3.c                 C   s:   t  d¡ |  ¡ }|  dt|ƒ¡ |  d|d d ¡ dS )zM
        L{twisted.protocols.mice} is deprecated since Twisted 16.0.
        ztwisted.protocols.micer   zatwisted.protocols.mice was deprecated in Twisted 16.0.0: There is no replacement for this module.r   rö   N)r
   ZnamedAnyZflushWarningsrM   r=   )r   ZwarningsShownr   r   r   Útest_MiceDeprecationg  s    

ýz)MiceDeprecationTests.test_MiceDeprecationN)r"   r#   r$   r%   r   r  r/  r   r   r   r   r.  _  s   r.  )>r%   Z
__future__r   r   rk   rÙ   Úior   Zzope.interface.verifyr   Ztwisted.python.compatr   r   Ztwisted.trialr   Ztwisted.protocolsr	   Ztwisted.pythonr
   Ztwisted.internetr   r   Ztwisted.internet.interfacesr   Ztwisted.testr   r
  rh   r   r'   r–   rA   ZSynchronousTestCaserC   r†   rˆ   r’   r—   rÖ   rž   r    r¦   rØ   Úobjectræ   ZInt32StringReceiverrø   rú   ZInt16StringReceiverrÿ   r   r  r	  ZInt8StringReceiverr  r  r  r  r  ZTestCaser  r.  r   r   r   r   Ú<module>   s^   M qU. iOi	ÿ	ÿ	ÿ Ln