o
    ¯b·h  ã                   @   s¼   d 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}.
é    )Úimplementer)ÚverifyObject)Útelnet)Údefer)Ú	iterbytes)Úproto_helpers)Úunittestc                   @   st   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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ó   )
ÚEORÚNOPÚDMÚBRKÚIPÚAOÚAYTÚECÚELÚGAc                    s   ˆ j  |¡S ©N)r   Úappend)ÚargÚcmdr   r
   r   Ú<lambda>)   s    z-TestProtocol.makeConnection.<locals>.<lambda>)Ú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   ÚdataReceived+   s   zTestProtocol.dataReceivedc                 C   ó   d S r"   r
   )r   Úreasonr
   r
   r   ÚconnectionLost.   s   zTestProtocol.connectionLostc                 C   s
   || _ d S r"   )r   )r   Úpayloadr
   r
   r   r(   1   s   
zTestProtocol.neg_TEST_COMMANDc                 C   ó   || j v r| j |¡ dS dS ©NTF)ÚlocalEnableabler   r#   ©r   Úoptionr
   r
   r   ÚenableLocal4   ó   
zTestProtocol.enableLocalc                 C   ó   | j  |¡ d S r"   )r   r#   r8   r
   r
   r   ÚdisableLocal:   ó   zTestProtocol.disableLocalc                 C   r5   r6   )ÚremoteEnableabler   r#   r8   r
   r
   r   ÚenableRemote=   r;   zTestProtocol.enableRemotec                 C   r<   r"   )r   r#   r8   r
   r
   r   ÚdisableRemoteC   r>   zTestProtocol.disableRemotec                 C   r1   r"   r
   r   r
   r
   r   ÚconnectionMadeF   ó   zTestProtocol.connectionMadec                 C   r1   r"   r
   )r   ÚcommandÚargumentr
   r
   r   ÚunhandledCommandJ   rC   zTestProtocol.unhandledCommandc                 C   r1   r"   r
   ©r   rD   r   r
   r
   r   ÚunhandledSubnegotiationN   rC   z$TestProtocol.unhandledSubnegotiationN)Ú__name__Ú
__module__Ú__qualname__r7   r?   r   r.   r0   r3   r(   r:   r=   r@   rA   rB   rF   rH   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   ÚTelnetProtocolr   ÚITelnetProtocol)r   Úpr
   r
   r   Útest_interfaceT   s   zInterfacesTests.test_interfaceN)rI   rJ   rK   rP   r
   r
   r
   r   rL   S   s    rL   c                   @   sB  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d$d%„ Zg g g g f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'dJdK„ Z(dLS )MÚTelnetTransportTestsz.
    Tests for L{telnet.TelnetTransport}.
    c                 C   s(   t  t¡| _t ¡ | _| j | j¡ d S r"   )r   ÚTelnetTransportr	   rO   r   ÚStringTransportÚtr.   r   r
   r
   r   ÚsetUpa   s   
zTelnetTransportTests.setUpc                 C   s>   | j j}g d¢}|D ]}| j  |¡ q
|  |jd |¡¡ d S )N)s   here are some bytes la la las   some more arrive heres   lots of bytes to play withs   la la las   ta de das   dumr   )rO   Úprotocolr0   ÚassertEqualr   Újoin©r   ÚhÚLÚbr
   r
   r   ÚtestRegularBytesf   s
   z%TelnetTransportTests.testRegularBytesc                 C   s„   | j j}g d¢}|D ]}| j  |¡ q
|  |j|d d d… d |d d d…  d |d d d…  d |d d d…  d ¡ d S )	N)s   here is the first line
s   here is the second line s   here is the third line
s   here is the last line r   éþÿÿÿó   
é   ó   é   é   )rO   rV   r0   rW   r   rY   r
   r
   r   ÚtestNewlineHandlingy   s,   ÿþýüûúùþz(TelnetTransportTests.testNewlineHandlingc                 C   sF   | j j}g d¢}|D ]}| j  |¡ q
|  |jd |¡ dd¡¡ d S )N)s*   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   ÿÿó   ÿ)rO   rV   r0   rW   r   rX   ÚreplacerY   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   )rO   rV   r   ÚIACr+   r0   rW   r   r   rX   rf   )r   ÚcmdNamerZ   r%   r[   r\   r
   r
   r   Ú_simpleCommandTest¥   s    z'TelnetTransportTests._simpleCommandTestc                 C   ó   |   d¡ d S )Nr   ©rj   r   r
   r
   r   ÚtestInterrupt´   ó   z"TelnetTransportTests.testInterruptc                 C   rk   )Nr   rl   r   r
   r
   r   ÚtestEndOfRecord·   rn   z$TelnetTransportTests.testEndOfRecordc                 C   rk   )Nr   rl   r   r
   r
   r   ÚtestNoOperationº   rn   z$TelnetTransportTests.testNoOperationc                 C   rk   )Nr   rl   r   r
   r
   r   ÚtestDataMark½   rn   z!TelnetTransportTests.testDataMarkc                 C   rk   )Nr   rl   r   r
   r
   r   Ú	testBreakÀ   rn   zTelnetTransportTests.testBreakc                 C   rk   )Nr   rl   r   r
   r
   r   ÚtestAbortOutputÃ   rn   z$TelnetTransportTests.testAbortOutputc                 C   rk   )Nr   rl   r   r
   r
   r   ÚtestAreYouThereÆ   rn   z$TelnetTransportTests.testAreYouTherec                 C   rk   )Nr   rl   r   r
   r
   r   ÚtestEraseCharacterÉ   rn   z'TelnetTransportTests.testEraseCharacterc                 C   rk   )Nr    rl   r   r
   r
   r   ÚtestEraseLineÌ   rn   z"TelnetTransportTests.testEraseLinec                 C   rk   )Nr!   rl   r   r
   r
   r   ÚtestGoAheadÏ   rn   z TelnetTransportTests.testGoAheadc                 C   s|   | j j}tjtj d tj tj }d| dg}|D ]}| j  |¡ q|  |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)rO   rV   r   rh   ÚSBÚSEr0   rW   r   rX   rf   r   Úlistr   ©r   rZ   r%   r[   r\   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   )rO   rV   r   rh   rx   ry   r0   rW   r   rX   rf   r   r{   r
   r
   r   Ú testSubnegotiationWithEmbeddedSEà   s   "z5TelnetTransportTests.testSubnegotiationWithEmbeddedSEc                 C   sÐ   t jt j d t j d t j t j }tt|ƒƒD ]L}tƒ  }| j_| 	| j¡ |d |… ||d … }}d| |d g}|D ]}| j 
|¡ q?|  |jd |¡ |d¡¡ |  |jt jgttdƒƒ ¡ qd S )Nr   s   hellos
   first parts	   last partr   )r   rh   rx   ry   ÚrangeÚlenr	   rO   rV   r.   r0   rW   r   rX   rf   r   rz   r   )r   r%   ÚirZ   Úar\   r[   r   r
   r
   r   ÚtestBoundarySubnegotiationï   s0   ÿþýüûúÿ
 õz/TelnetTransportTests.testBoundarySubnegotiationc                 C   s<   |   |j|¡ |   |j|¡ |   |j|¡ |   |j|¡ d S r"   )rW   r   r   r   r   )r   ÚoÚeLÚeRÚdLÚdRr
   r
   r   Ú_enabledHelper
  s   z#TelnetTransportTests._enabledHelperc                 C   ór   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   rh   ÚWILLrO   r0   rW   rV   r   rf   rT   ÚvalueÚDONTrˆ   ©r   r%   r   r
   r
   r   ÚtestRefuseWill  ó   z#TelnetTransportTests.testRefuseWillc                 C   r‰   rŠ   )r   rh   ÚDOrO   r0   rW   rV   r   rf   rT   rŒ   ÚWONTrˆ   rŽ   r
   r
   r   ÚtestRefuseDo  r�   z!TelnetTransportTests.testRefuseDoc                 C   óh   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•   )r„   )r   rh   r‘   rO   rV   r7   r0   rW   rT   rŒ   r‹   rˆ   ©r   r%   r   rZ   r
   r
   r   ÚtestAcceptDo&  s   z!TelnetTransportTests.testAcceptDoc                 C   r”   )Nó   ‘s   headerr–   )r™   ©r…   )r   rh   r‹   rO   rV   r?   r0   rW   rT   rŒ   r‘   rˆ   r—   r
   r
   r   ÚtestAcceptWill3  s   z#TelnetTransportTests.testAcceptWillc                 C   ó˜   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©r‡   )r   rh   r’   rO   ÚgetOptionStateÚhimÚstater0   rW   rV   r   rf   rT   rŒ   r�   rˆ   ©r   r%   Úsr   r
   r
   r   ÚtestAcceptWont?  ó   z#TelnetTransportTests.testAcceptWontc                 C   rœ   )Nr�   rž   s   fiddle dum r   rŸ   )r†   )r   rh   r�   rO   r¡   Úusr£   r0   rW   rV   r   rf   rT   rŒ   r’   rˆ   r¤   r
   r
   r   ÚtestAcceptDontS  r§   z#TelnetTransportTests.testAcceptDontc                 C   óf   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   rh   r’   rO   r0   rW   rV   r   rf   rT   rŒ   rˆ   rŽ   r
   r
   r   ÚtestIgnoreWontg  s   z#TelnetTransportTests.testIgnoreWontc                 C   rª   r«   )r   rh   r�   rO   r0   rW   rV   r   rf   rT   rŒ   rˆ   rŽ   r
   r
   r   ÚtestIgnoreDonts  s   z#TelnetTransportTests.testIgnoreDontc                 C   óz   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   rh   r‹   rO   r¡   r¢   r£   r0   rW   rV   r   rf   rT   rŒ   rˆ   r¤   r
   r
   r   ÚtestIgnoreWill€  ó   z#TelnetTransportTests.testIgnoreWillc                 C   r±   r²   )r   rh   r‘   rO   r¡   r¨   r£   r0   rW   rV   r   rf   rT   rŒ   rˆ   r¤   r
   r
   r   ÚtestIgnoreDo“  rµ   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š   )rˆ   ©Ú_©rZ   r   r
   r   r&   µ  s    z@TelnetTransportTests.testAcceptedEnableRequest.<locals>.<lambda>)rO   ÚdorV   r?   rW   rT   rŒ   r   rh   r‘   r0   r‹   ÚaddCallback©r   r-   r
   r»   r   ÚtestAcceptedEnableRequest¦  s   z.TelnetTransportTests.testAcceptedEnableRequestc                    óÌ   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                    ó   ˆ   ˆ jj¡S r"   ©rˆ   rO   rV   ©Úignoredr   r
   r   r&   Ð  ó    z@TelnetTransportTests.test_refusedEnableRequest.<locals>.<lambda>c                    ó   ˆ  ˆ jj¡S r"   )ÚassertFalser¢   ÚnegotiatingrÃ   ©r¥   r   r
   r   r&   Ñ  rÅ   )rO   rV   r?   r¼   rW   rT   rŒ   r   rh   r‘   r¡   r¢   r£   r¨   Ú
assertTruerÈ   rÇ   r0   r’   ÚassertFailureÚOptionRefusedr½   r¾   r
   rÉ   r   Útest_refusedEnableRequest¸  ó   

z.TelnetTransportTests.test_refusedEnableRequestc                    rÀ   )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                    rÁ   r"   rÂ   rÃ   r   r
   r   r&   ì  rÅ   z>TelnetTransportTests.test_refusedEnableOffer.<locals>.<lambda>c                    rÆ   r"   )rÇ   r¨   rÈ   rÃ   rÉ   r
   r   r&   í  rÅ   )rO   rV   r7   ÚwillrW   rT   rŒ   r   rh   r‹   r¡   r¢   r£   r¨   rÇ   rÈ   rÊ   r0   r�   rË   rÌ   r½   r¾   r
   rÉ   r   Útest_refusedEnableOfferÔ  rÎ   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>)rO   r¡   r¢   r£   ÚdontrW   rT   rŒ   r   rh   r�   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                    ó   ˆ j  d¡}ˆ  |tj¡S ©NrÔ   )rO   r¼   rË   r   ÚAlreadyNegotiating©Úxr-   r   r
   r   Ú_do
  ó   zITelnetTransportTests.testNegotiationBlocksFurtherNegotiation.<locals>._doc                    rÕ   rÖ   )rO   rÑ   rË   r   r×   rØ   r   r
   r   Ú_dont  rÛ   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Ô   )r…   r‡   rÂ   r¹   r   r
   r   r&     s    ÿz^TelnetTransportTests.testNegotiationBlocksFurtherNegotiation.<locals>._final.<locals>.<lambda>)rO   r0   r   rh   r’   rˆ   rV   r?   r¼   r‹   r½   rW   rØ   r   r
   r   Ú_final  s   

ÿzLTelnetTransportTests.testNegotiationBlocksFurtherNegotiation.<locals>._final)rO   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ó   «)rO   rÑ   rË   r   ÚAlreadyDisabledr¾   r
   r
   r   Ú#testSuperfluousDisableRequestRaises'  s   z8TelnetTransportTests.testSuperfluousDisableRequestRaisesc                 C   s.   | j  d¡}d|j_| j  d¡}|  |tj¡S )Nrß   rž   )rO   r¡   r¢   r£   r¼   rË   r   ÚAlreadyEnabledrÒ   r
   r
   r   Ú"testSuperfluousEnableRequestRaises,  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)rI   rJ   rK   r
   r
   r
   r   ÚTestException8  s    ræ   zTotal failure!)rO   r¼   Ú	Exceptionr3   rË   r   ÚgatherResults)r   Úd1Úd2Úd3ræ   r
   r
   r   Ú testLostConnectionFailsDeferreds3  s   z5TelnetTransportTests.testLostConnectionFailsDeferredsN))rI   rJ   rK   Ú__doc__rU   r]   rd   rg   rj   rm   ro   rp   rq   rr   rs   rt   ru   rv   rw   r|   r}   r‚   rˆ   r�   r“   r˜   r›   r¦   r©   r¯   r°   r´   r¶   r¿   rÍ   rÐ   rÓ   rÞ   rá   rã   rì   r
   r
   r
   r   rQ   \   sN    %rQ   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   H  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   ÚapplicationDataReceivedL  s   z"TestTelnet.applicationDataReceivedc                 C   ó   | j  d||f¡ dS )z=
        Record the given command in C{self.events}.
        rD   Nrò   rG   r
   r
   r   rF   R  ó   zTestTelnet.unhandledCommandc                 C   rô   )zL
        Record the given subnegotiation command in C{self.events}.
        Ú	negotiateNrò   rG   r
   r
   r   rH   X  rõ   z"TestTelnet.unhandledSubnegotiationN)rI   rJ   rK   rí   r   ró   rF   rH   r
   r
   r
   r   rî   C  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î   rV   r   r
   r
   r   rU   g  s   zTelnetTests.setUpc                 C   ó   |   | 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Ç   rV   r:   r   r
   r
   r   Útest_enableLocalm  ó   zTelnetTests.test_enableLocalc                 C   rø   )z•
        L{telnet.Telnet.enableRemote} should reject all options, since
        L{telnet.Telnet} does not know how to implement any options.
        rù   N)rÇ   rV   r@   r   r
   r
   r   Útest_enableRemotet  rû   zTelnetTests.test_enableRemotec                 C   ó   |   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ÚNotImplementedErrorrV   r=   r   r
   r
   r   Útest_disableLocal{  ó   zTelnetTests.test_disableLocalc                 C   rý   )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ÿ   rV   rA   r   r
   r
   r   Útest_disableRemote„  r  zTelnetTests.test_disableRemotec                 C   ó6   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   rS   rV   r.   ÚrequestNegotiationrW   rŒ   ©r   r,   r
   r
   r   Útest_requestNegotiation�  s   ýz#TelnetTests.test_requestNegotiationc                 C   r  )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  re   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)rV   rð   r0   rW   rz   )r   r   ÚexpectedÚreceivedr
   r
   r   Ú_deliver©  s   zTelnetTests._deliverc                 C   ó   |   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²  ó   z'TelnetTests.test_oneApplicationDataBytec                 C   r  )za
        Two application-data bytes in the default state get delivered
        together.
        ó   bc)rñ   r  Nr  r   r
   r
   r   Útest_twoApplicationDataBytes¹  r  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   rh   r   r
   r
   r   Útest_threeApplicationDataBytesÀ  rû   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.
        ra   r_   )rñ   r_   s   
rù   )rñ   ra   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  rD   N)r  r   rh   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  rD   N)rV   r)   r  r   rh   r‹   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   rh   rx   ry   r   r
   r
   r   Ú(test_applicationDataBeforeSubnegotiation  s
   
ýz4TelnetTests.test_applicationDataBeforeSubnegotiationN)rI   rJ   rK   rí   rU   rú   rü   r   r  r  r	  r  r  r  r  r  r  r  r  r!  r
   r
   r
   r   r÷   _  s$    			r÷   N)rí   Úzope.interfacer   Úzope.interface.verifyr   Útwisted.conchr   Útwisted.internetr   Útwisted.python.compatr   Útwisted.testr   Útwisted.trialr   rN   r	   ÚTestCaserL   rQ   rï   rî   r÷   r
   r
   r
   r   Ú<module>   s"   >	   j