U
    
W[g  ć                   @   sĢ   d 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 eejG d
d 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dS )z$
Tests for L{twisted.conch.telnet}.
é    )Śabsolute_importŚdivision)Śimplementer)ŚverifyObject)Śdefer)Śtelnet)Śunittest)Śproto_helpers)Ś	iterbytesc                   @   s\   e 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d Zdd Zdd ZdS )ŚTestProtocol© c                 C   s.   d| _ g | _g | _g | _g | _g | _g | _d S )Nó    )ŚdataŚsubcmdŚcallsŚenabledLocalŚenabledRemoteŚdisabledLocalŚdisabledRemote©Śselfr   r   ś@/usr/lib/python3/dist-packages/twisted/conch/test/test_telnet.pyŚ__init__   s    zTestProtocol.__init__c                    sL   i  }|_  j|d< |j ”  }|_dD ]}|f fdd	|tt|< q(d S )Nó   )	ŚNOPŚDMŚBRKŚIPŚAOŚAYTŚECŚELŚGAc                    s    j  |”S ©N)r   Śappend)ŚargŚcmdr   r   r   Ś<lambda>-   r   z-TestProtocol.makeConnection.<locals>.<lambda>)ZnegotiationMapŚneg_TEST_COMMANDŚ
commandMapŚcopyŚgetattrr   )r   Ś	transportŚdr&   r   r   r   ŚmakeConnection'   s
    

zTestProtocol.makeConnectionc                 C   s   |  j |7  _ d S r#   )r   ©r   r   r   r   r   ŚdataReceived0   s    zTestProtocol.dataReceivedc                 C   s   d S r#   r   )r   Śreasonr   r   r   ŚconnectionLost4   s    zTestProtocol.connectionLostc                 C   s
   || _ d S r#   )r   )r   Zpayloadr   r   r   r(   8   s    zTestProtocol.neg_TEST_COMMANDc                 C   s   || j kr| j |” dS dS ©NTF)ŚlocalEnableabler   r$   ©r   Zoptionr   r   r   ŚenableLocal<   s    
zTestProtocol.enableLocalc                 C   s   | j  |” d S r#   )r   r$   r5   r   r   r   ŚdisableLocalC   s    zTestProtocol.disableLocalc                 C   s   || j kr| j |” dS dS r3   )ŚremoteEnableabler   r$   r5   r   r   r   ŚenableRemoteG   s    
zTestProtocol.enableRemotec                 C   s   | j  |” d S r#   )r   r$   r5   r   r   r   ŚdisableRemoteN   s    zTestProtocol.disableRemoteN)Ś__name__Ś
__module__Ś__qualname__r4   r8   r   r.   r0   r2   r(   r6   r7   r9   r:   r   r   r   r   r      s   	r   c                   @   s   e Zd Zdd ZdS )ŚInterfacesTestsc                 C   s   t  ” }tt j| dS )zO
        L{telnet.TelnetProtocol} implements L{telnet.ITelnetProtocol}
        N)r   ZTelnetProtocolr   ŚITelnetProtocol)r   Śpr   r   r   Śtest_interfaceT   s    zInterfacesTests.test_interfaceN)r;   r<   r=   rA   r   r   r   r   r>   S   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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g g g g fd$d%Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Z d<d= Z!d>d? Z"d@dA Z#dBdC Z$dDdE Z%dFdG Z&dHdI Z'dJS )KŚTelnetTransportTestsz.
    Tests for L{telnet.TelnetTransport}.
    c                 C   s(   t  t”| _t ” | _| j | j” d S r#   )r   ZTelnetTransportr   r@   r	   ŚStringTransportŚtr.   r   r   r   r   ŚsetUpa   s    
zTelnetTransportTests.setUpc                 C   sF   | j j}ddddddg}|D ]}| j  |” q|  |jd |”” d S )Ns   here are some bytes la la las   some more arrive heres   lots of bytes to play withs   la la las   ta de das   dumr   )r@   Śprotocolr0   ŚassertEqualr   Śjoin©r   ŚhŚLŚbr   r   r   ŚtestRegularBytesg   s    ūz%TelnetTransportTests.testRegularBytesc                 C   s   | j j}ddddg}|D ]}| j  |” q|  |j|d d d d |d d d  d	 |d
 d d  d |d d d  d	 ” d S )Ns   here is the first line
s   here is the second line s   here is the third line
s   here is the last line r   éž’’’ó   
é   ó   é   é   )r@   rF   r0   rG   r   rI   r   r   r   ŚtestNewlineHandlingy   s*    ż’’žžżżz(TelnetTransportTests.testNewlineHandlingc                 C   sH   | j j}dddg}|D ]}| j  |” q|  |jd |” dd”” d S )Ns*   here are some bytes’’ with an embedded IACs&   and here is a test of a border escape’s   ’ did you get that IAC?r   s   ’’ó   ’)r@   rF   r0   rG   r   rH   ŚreplacerI   r   r   r   ŚtestIACEscape   s    žz"TelnetTransportTests.testIACEscapec                 C   sn   | j j}tjtt| }dd| d g}|D ]}| j  |” q,|  |j|g” |  |jd 	|” 
|d”” d S )Ns   Here's some bytes, tra la las   But ono!s    an interruptr   )r@   rF   r   ŚIACr+   r0   rG   r   r   rH   rV   )r   ZcmdNamerJ   r&   rK   rL   r   r   r   Ś_simpleCommandTest   s    
’z'TelnetTransportTests._simpleCommandTestc                 C   s   |   d” d S )Nr   ©rY   r   r   r   r   ŚtestInterrupt­   s    z"TelnetTransportTests.testInterruptc                 C   s   |   d” d S )Nr   rZ   r   r   r   r   ŚtestNoOperation±   s    z$TelnetTransportTests.testNoOperationc                 C   s   |   d” d S )Nr   rZ   r   r   r   r   ŚtestDataMarkµ   s    z!TelnetTransportTests.testDataMarkc                 C   s   |   d” d S )Nr   rZ   r   r   r   r   Ś	testBreak¹   s    zTelnetTransportTests.testBreakc                 C   s   |   d” d S )Nr   rZ   r   r   r   r   ŚtestAbortOutput½   s    z$TelnetTransportTests.testAbortOutputc                 C   s   |   d” d S )Nr   rZ   r   r   r   r   ŚtestAreYouThereĮ   s    z$TelnetTransportTests.testAreYouTherec                 C   s   |   d” d S )Nr    rZ   r   r   r   r   ŚtestEraseCharacterÅ   s    z'TelnetTransportTests.testEraseCharacterc                 C   s   |   d” d S )Nr!   rZ   r   r   r   r   ŚtestEraseLineÉ   s    z"TelnetTransportTests.testEraseLinec                 C   s   |   d” d S )Nr"   rZ   r   r   r   r   ŚtestGoAheadĶ   s    z TelnetTransportTests.testGoAheadc                 C   s|   | j j}tjtj d tj tj }d| dg}|D ]}| j  |” q4|  |jd 	|” 
|d”” |  |jttd” d S )Ns   hello worlds   These are some bytes but soons   there will be some morer   s   hello world)r@   rF   r   rX   ŚSBŚSEr0   rG   r   rH   rV   r   Ślistr
   ©r   rJ   r&   rK   rL   r   r   r   ŚtestSubnegotiationŃ   s    ’z'TelnetTransportTests.testSubnegotiationc                 C   s   | j j}tjtj d tj tj tj }d| d dg}|D ]}| j  |” q>|  |jd 	|” 
|d”” |  |jtjg” d S )Nr   s   Some bytes are heres   and herer   )r@   rF   r   rX   rd   re   r0   rG   r   rH   rV   r   rg   r   r   r   Ś testSubnegotiationWithEmbeddedSEį   s"    
’’žž
’z5TelnetTransportTests.testSubnegotiationWithEmbeddedSEc                 C   sŠ   t jt j d t j d t j t j }tt|D ]}t  }| j_| 	| j” |d | ||d   }}d| |d g}|D ]}| j 
|” q~|  |jd |” |d”” |  |jt jgttd ” q2d S )Nr   s   hellos
   first parts	   last partr   )r   rX   rd   re   ŚrangeŚlenr   r@   rF   r.   r0   rG   r   rH   rV   r   rf   r
   )r   r&   ŚirJ   ŚarL   rK   r   r   r   r   ŚtestBoundarySubnegotiationō   s,    
’’’žž’z/TelnetTransportTests.testBoundarySubnegotiationc                 C   s<   |   |j|” |   |j|” |   |j|” |   |j|” d S r#   )rG   r   r   r   r   )r   ŚoŚeLŚeRŚdLŚdRr   r   r   Ś_enabledHelper  s    z#TelnetTransportTests._enabledHelperc                 C   sr   t jt j d }d| d }| j |” |  | jjj| |d”” |  | j	 
” t jt j d ” |  | jj” d S ©Nr   s   surrounding bytess   to spice things upr   )r   rX   ŚWILLr@   r0   rG   rF   r   rV   rD   ŚvalueŚDONTrt   ©r   r&   r   r   r   r   ŚtestRefuseWill  s    z#TelnetTransportTests.testRefuseWillc                 C   sr   t jt j d }d| d }| j |” |  | jjj| |d”” |  | j	 
” t jt j d ” |  | jj” d S ru   )r   rX   ŚDOr@   r0   rG   rF   r   rV   rD   rw   ŚWONTrt   ry   r   r   r   ŚtestRefuseDo  s    z!TelnetTransportTests.testRefuseDoc                 C   sh   t jt j d }d| d }| jj}d|_| j |” |  | j 	” t jt j
 d ” | j|dgd d S )Nó   ó   paddings   trailer)r~   )rp   )r   rX   r{   r@   rF   r4   r0   rG   rD   rw   rv   rt   ©r   r&   r   rJ   r   r   r   ŚtestAcceptDo*  s    z!TelnetTransportTests.testAcceptDoc                 C   sh   t jt j d }d| d }| jj}d|_| j |” |  | j 	” t jt j
 d ” | j|dgd d S )Nó   s   headerr   )r   ©rq   )r   rX   rv   r@   rF   r8   r0   rG   rD   rw   r{   rt   r   r   r   r   ŚtestAcceptWill8  s    z#TelnetTransportTests.testAcceptWillc                 C   s   t jt j d }| j d”}d|j_d| }| j |” |  | jj	j
| |d”” |  | j ” t jt j d ” |  |jjd” | j| jj	dgd d S )Nó   )Śyess
   fiddle deer   Śno©rs   )r   rX   r|   r@   ŚgetOptionStateŚhimŚstater0   rG   rF   r   rV   rD   rw   rx   rt   ©r   r&   Śsr   r   r   r   ŚtestAcceptWontE  s    z#TelnetTransportTests.testAcceptWontc                 C   s   t jt j d }| j d”}d|j_d| }| j |” |  | jj	j
| |d”” |  | j ” t jt j d ” |  |jjd” | j| jj	dgd d S )Nr   r   s   fiddle dum r   r   )rr   )r   rX   rx   r@   r   Śusr   r0   rG   rF   r   rV   rD   rw   r|   rt   r   r   r   r   ŚtestAcceptDontZ  s    z#TelnetTransportTests.testAcceptDontc                 C   sf   t jt j d }d| d }| j |” |  | jjj| |d”” |  | j	 
” d” |  | jj” d S ©Nó   Gó
   dum de dumó	   tra la lar   )r   rX   r|   r@   r0   rG   rF   r   rV   rD   rw   rt   ry   r   r   r   ŚtestIgnoreWonto  s    z#TelnetTransportTests.testIgnoreWontc                 C   sf   t jt j d }d| d }| j |” |  | jjj| |d”” |  | j	 
” d” |  | jj” d S r   )r   rX   rx   r@   r0   rG   rF   r   rV   rD   rw   rt   ry   r   r   r   ŚtestIgnoreDont|  s    z#TelnetTransportTests.testIgnoreDontc                 C   sz   t jt j d }| j d”}d|j_d| d }| j |” |  | jj	j
| |d”” |  | j ” d” |  | jj	” d S ©Nó   Vr   r   r   r   )r   rX   rv   r@   r   r   r   r0   rG   rF   r   rV   rD   rw   rt   r   r   r   r   ŚtestIgnoreWill  s    z#TelnetTransportTests.testIgnoreWillc                 C   sz   t jt j d }| j d”}d|j_d| d }| j |” |  | jj	j
| |d”” |  | j ” d” |  | jj	” d S r   )r   rX   r{   r@   r   r   r   r0   rG   rF   r   rV   rD   rw   rt   r   r   r   r   ŚtestIgnoreDo  s    z!TelnetTransportTests.testIgnoreDoc                    sv   j  d”}j j d _ j ” tjtj	 d ” j  
tjtj d ” | jd” |  fdd” |S )Nó   B©r   Tc                    s   j  dgdS )Nr   r   )rt   ©Ś_©rJ   r   r   r   r'   Į  r   z@TelnetTransportTests.testAcceptedEnableRequest.<locals>.<lambda>)r@   ŚdorF   r8   rG   rD   rw   r   rX   r{   r0   rv   ŚaddCallback©r   r-   r   r   r   ŚtestAcceptedEnableRequest²  s    z.TelnetTransportTests.testAcceptedEnableRequestc                    sĢ   dj j_j  d”} j ” tjtj	 d ” j  
d”   jjd”   jjd”   jj”   jj” j  tjtj d ”  |tj”}| fdd” |  fdd” |S )z¾
        If the peer refuses to enable an option we request it to enable, the
        L{Deferred} returned by L{TelnetProtocol.do} fires with an
        L{OptionRefused} L{Failure}.
        r   r   r   c                    s       jj”S r#   ©rt   r@   rF   ©Zignoredr   r   r   r'   Ż  r   z@TelnetTransportTests.test_refusedEnableRequest.<locals>.<lambda>c                    s      jj”S r#   )ŚassertFalser   Śnegotiatingr„   ©r   r   r   r   r'   ß  r   )r@   rF   r8   r    rG   rD   rw   r   rX   r{   r   r   r   r   Ś
assertTruer§   r¦   r0   r|   ŚassertFailureŚOptionRefusedr”   r¢   r   rØ   r   Śtest_refusedEnableRequestÅ  s    

’z.TelnetTransportTests.test_refusedEnableRequestc                    sĢ   dj j_j  d”} j ” tjtj	 d ” j  
d”   jjd”   jjd”   jj”   jj” j  tjtj d ”  |tj”}| fdd” |  fdd” |S )z“
        If the peer refuses to allow us to enable an option, the L{Deferred}
        returned by L{TelnetProtocol.will} fires with an L{OptionRefused}
        L{Failure}.
        r   r   r   c                    s       jj”S r#   r¤   r„   r   r   r   r'   ū  r   z>TelnetTransportTests.test_refusedEnableOffer.<locals>.<lambda>c                    s      jj”S r#   )r¦   r   r§   r„   rØ   r   r   r'   ż  r   )r@   rF   r4   ZwillrG   rD   rw   r   rX   rv   r   r   r   r   r¦   r§   r©   r0   rx   rŖ   r«   r”   r¢   r   rØ   r   Śtest_refusedEnableOfferć  s    

’z,TelnetTransportTests.test_refusedEnableOfferc                    sz    j  d”}d|j_ j  d”}   j ” tj	tj
 d ”  j  tj	tj d ” |  jd” |  fdd” |S )Nr   r   Tc                    s    j  jjdgdS )Nr   r   r¤   r   r   r   r   r'     s   
’zATelnetTransportTests.testAcceptedDisableRequest.<locals>.<lambda>)r@   r   r   r   ŚdontrG   rD   rw   r   rX   rx   r0   r|   r”   ©r   r   r-   r   r   r   ŚtestAcceptedDisableRequest  s    z/TelnetTransportTests.testAcceptedDisableRequestc                    sd    j  d”}d|j_ j  d”  fdd} fdd} fdd}|d }| |” | |” |S )	Nó   $r   c                    s    j  d”}  |tj”S ©Nr±   )r@   r    rŖ   r   ŚAlreadyNegotiating©Śxr-   r   r   r   Ś_do  s    zITelnetTransportTests.testNegotiationBlocksFurtherNegotiation.<locals>._doc                    s    j  d”}  |tj”S r²   )r@   r®   rŖ   r   r³   r“   r   r   r   Ś_dont"  s    zKTelnetTransportTests.testNegotiationBlocksFurtherNegotiation.<locals>._dontc                    s~    j  tjtj d ”  j j jdgd d j j_ j  d”} j  tjtj	 d ” | 
 jd” | 
 fdd” |S )Nr±   r   )r±   Tc                    s    j  jjdgdgdS )Nr±   )rq   rs   r¤   r   r   r   r   r'   0  s   
žz^TelnetTransportTests.testNegotiationBlocksFurtherNegotiation.<locals>._final.<locals>.<lambda>)r@   r0   r   rX   r|   rt   rF   r8   r    rv   r”   rG   r“   r   r   r   Ś_final'  s    
zLTelnetTransportTests.testNegotiationBlocksFurtherNegotiation.<locals>._final)r@   r   r   r   r®   r”   )r   r   r¶   r·   rø   r-   r   r   r   Ś'testNegotiationBlocksFurtherNegotiation  s    

z<TelnetTransportTests.testNegotiationBlocksFurtherNegotiationc                 C   s   | j  d”}|  |tj”S )Nó   «)r@   r®   rŖ   r   ZAlreadyDisabledr¢   r   r   r   Ś#testSuperfluousDisableRequestRaises;  s    z8TelnetTransportTests.testSuperfluousDisableRequestRaisesc                 C   s.   | j  d”}d|j_| j  d”}|  |tj”S )Nrŗ   r   )r@   r   r   r   r    rŖ   r   ZAlreadyEnabledrÆ   r   r   r   Ś"testSuperfluousEnableRequestRaisesA  s    z7TelnetTransportTests.testSuperfluousEnableRequestRaisesc                 C   sx   | j  d”}| j  d”}| j  d”}G dd dt}| j  |d” |  ||”}|  ||”}|  ||”}t |||g”S )Nr   ó   #ó   4c                   @   s   e Zd ZdS )zLTelnetTransportTests.testLostConnectionFailsDeferreds.<locals>.TestExceptionN)r;   r<   r=   r   r   r   r   ŚTestExceptionN  s   ræ   zTotal failure!)r@   r    Ś	Exceptionr2   rŖ   r   ZgatherResults)r   Zd1Zd2Zd3ræ   r   r   r   Ś testLostConnectionFailsDeferredsI  s    z5TelnetTransportTests.testLostConnectionFailsDeferredsN)(r;   r<   r=   Ś__doc__rE   rM   rT   rW   rY   r[   r\   r]   r^   r_   r`   ra   rb   rc   rh   ri   rn   rt   rz   r}   r   r   r   r   r   r   r   r   r£   r¬   r­   r°   r¹   r»   r¼   rĮ   r   r   r   r   rB   ]   sJ   &rB   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )Ś
TestTelnetzP
    A trivial extension of the telnet protocol class useful to unit tests.
    c                 C   s   t j | ” g | _d S r#   )r   ŚTelnetr   Śeventsr   r   r   r   r   ]  s    zTestTelnet.__init__c                 C   s   | j  d|f” dS )z:
        Record the given data in C{self.events}.
        ŚbytesN©rÅ   r$   r/   r   r   r   ŚapplicationDataReceivedb  s    z"TestTelnet.applicationDataReceivedc                 C   s   | j  d||f” dS )z=
        Record the given command in C{self.events}.
        ŚcommandNrĒ   ©r   rÉ   r   r   r   r   ŚunhandledCommandi  s    zTestTelnet.unhandledCommandc                 C   s   | j  d||f” dS )zL
        Record the given subnegotiation command in C{self.events}.
        Ś	negotiateNrĒ   rŹ   r   r   r   ŚunhandledSubnegotiationp  s    z"TestTelnet.unhandledSubnegotiationN)r;   r<   r=   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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 )#ŚTelnetTestsz°
    Tests for L{telnet.Telnet}.

    L{telnet.Telnet} implements the TELNET protocol (RFC 854), including option
    and suboption negotiation, and option state tracking.
    c                 C   s   t  | _dS )zM
        Create an unconnected L{telnet.Telnet} to be used by tests.
        N)rĆ   rF   r   r   r   r   rE     s    zTelnetTests.setUpc                 C   s   |   | j d”” dS )z
        L{telnet.Telnet.enableLocal} should reject all options, since
        L{telnet.Telnet} does not know how to implement any options.
        ó    N)r¦   rF   r6   r   r   r   r   Śtest_enableLocal  s    zTelnetTests.test_enableLocalc                 C   s   |   | j d”” dS )z
        L{telnet.Telnet.enableRemote} should reject all options, since
        L{telnet.Telnet} does not know how to implement any options.
        rĻ   N)r¦   rF   r9   r   r   r   r   Śtest_enableRemote  s    zTelnetTests.test_enableRemotec                 C   s   |   t| jjd” dS )a	  
        It is an error for L{telnet.Telnet.disableLocal} to be called, since
        L{telnet.Telnet.enableLocal} will never allow any options to be enabled
        locally.  If a subclass overrides enableLocal, it must also override
        disableLocal.
        rĻ   N)ŚassertRaisesŚNotImplementedErrorrF   r7   r   r   r   r   Śtest_disableLocal  s    zTelnetTests.test_disableLocalc                 C   s   |   t| jjd” dS )a  
        It is an error for L{telnet.Telnet.disableRemote} to be called, since
        L{telnet.Telnet.enableRemote} will never allow any options to be
        enabled remotely.  If a subclass overrides enableRemote, it must also
        override disableRemote.
        rĻ   N)rŅ   rÓ   rF   r:   r   r   r   r   Śtest_disableRemote   s    zTelnetTests.test_disableRemotec                 C   s6   t  ” }| j |” | j dd” |  | ” d” dS )z±
        L{telnet.Telnet.requestNegotiation} formats the feature byte and the
        payload bytes into the subnegotiation format and sends them.

        See RFC 855.
        ó   s   s   ’ś’šN©r	   rC   rF   r.   ZrequestNegotiationrG   rw   ©r   r,   r   r   r   Śtest_requestNegotiationŖ  s    żz#TelnetTests.test_requestNegotiationc                 C   s6   t  ” }| j |” | j dd” |  | ” d” dS )z®
        If the payload for a subnegotiation includes I{IAC}, it is escaped by
        L{telnet.Telnet.requestNegotiation} with another I{IAC}.

        See RFC 855.
        rÖ   rU   s   ’ś’’’šNr×   rŲ   r   r   r   Ś!test_requestNegotiationEscapesIACŗ  s    žz-TelnetTests.test_requestNegotiationEscapesIACc                 G   s,   g  }| j _| j  |” |  |t|” dS )z
        Pass the given bytes to the protocol's C{dataReceived} method and
        assert that the given events occur.
        N)rF   rÅ   r0   rG   rf   )r   r   ZexpectedZreceivedr   r   r   Ś_deliverÉ  s    zTelnetTests._deliverc                 C   s   |   dd” dS )zc
        One application-data byte in the default state gets delivered right
        away.
        ó   a)rĘ   rÜ   N©rŪ   r   r   r   r   Śtest_oneApplicationDataByteÓ  s    z'TelnetTests.test_oneApplicationDataBytec                 C   s   |   dd” dS )za
        Two application-data bytes in the default state get delivered
        together.
        ó   bc)rĘ   rß   NrŻ   r   r   r   r   Śtest_twoApplicationDataBytesŪ  s    z(TelnetTests.test_twoApplicationDataBytesc                 C   s   |   dtj d” dS )z~
        Three application-data bytes followed by a control byte get
        delivered, but the control byte doesn't.
        ó   def)rĘ   rį   N©rŪ   r   rX   r   r   r   r   Śtest_threeApplicationDataBytesć  s    z*TelnetTests.test_threeApplicationDataBytesc                 C   s,   |   tj” |   tjd dtjd f” dS )zy
        IAC in the escaped state gets delivered and so does another
        application-data byte following it.
        ó   grĘ   Nrā   r   r   r   r   Śtest_escapedControlė  s    zTelnetTests.test_escapedControlc                 C   s   |   d” |   dd” |   dd” |   d” |   dd” |   dd” |   d” |   dd	” |   d
d	” |   d” |   tjtj d ddtj d f” dS )aĶ  
        A carriage return only puts the protocol into the newline state.  A
        linefeed in the newline state causes just the newline to be
        delivered.  A nul in the newline state causes a carriage return to
        be delivered.  An IAC in the newline state causes a carriage return
        to be delivered and puts the protocol into the escaped state.
        Anything else causes a carriage return and that thing to be
        delivered.
        rQ   rO   )rĘ   rO   s   
rĻ   )rĘ   rQ   s    rÜ   )rĘ   ó   arę   ó   xrĘ   Nrā   r   r   r   r   Śtest_carriageReturnō  s    




 ’zTelnetTests.test_carriageReturnc                 C   s&   |   dtj tj ddtjdf” dS )zt
        Application bytes received before a command are delivered before the
        command is processed.
        rē   )rĘ   rē   rÉ   N)rŪ   r   rX   r   r   r   r   r   Ś'test_applicationDataBeforeSimpleCommand  s
     
žz3TelnetTests.test_applicationDataBeforeSimpleCommandc                 C   s2   i | j _|  dtj tj d ddtjdf” dS )z~
        Application bytes received before a WILL/WONT/DO/DONT are delivered
        before the command is processed.
        ó   yrĻ   )rĘ   rź   rÉ   N)rF   r)   rŪ   r   rX   rv   r   r   r   r   Ś!test_applicationDataBeforeCommand  s     
žz-TelnetTests.test_applicationDataBeforeCommandc                 C   s6   |   dtj tj d tj tj ddddgf” dS )z
        Application bytes received before a subnegotiation command are
        delivered before the negotiation is processed.
        ó   zs   Qx)rĘ   rģ   rĢ   ó   Qrē   N)rŪ   r   rX   rd   re   r   r   r   r   Ś(test_applicationDataBeforeSubnegotiation$  s
     
žz4TelnetTests.test_applicationDataBeforeSubnegotiationN)r;   r<   r=   rĀ   rE   rŠ   rŃ   rŌ   rÕ   rŁ   rŚ   rŪ   rŽ   rą   rć   rå   rč   ré   rė   rī   r   r   r   r   rĪ   x  s"   


	
rĪ   N)rĀ   Z
__future__r   r   Zzope.interfacer   Zzope.interface.verifyr   Ztwisted.internetr   Ztwisted.conchr   Ztwisted.trialr   Ztwisted.testr	   Ztwisted.python.compatr
   r?   r   ZTestCaser>   rB   rÄ   rĆ   rĪ   r   r   r   r   Ś<module>   s$   ;
     