U
    ˆj·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
   úB/tmp/pip-unpacked-wheel-j5h_c8_q/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>)   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   ÚdataReceived+   s    zTestProtocol.dataReceivedc                 C   s   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   s   || j kr| j |¡ dS dS ©NTF)ÚlocalEnableabler   r#   ©r   Úoptionr
   r
   r   ÚenableLocal4   s    
zTestProtocol.enableLocalc                 C   s   | j  |¡ d S r"   )r   r#   r5   r
   r
   r   ÚdisableLocal:   s    zTestProtocol.disableLocalc                 C   s   || j kr| j |¡ dS dS r3   )ÚremoteEnableabler   r#   r5   r
   r
   r   ÚenableRemote=   s    
zTestProtocol.enableRemotec                 C   s   | j  |¡ d S r"   )r   r#   r5   r
   r
   r   ÚdisableRemoteC   s    zTestProtocol.disableRemotec                 C   s   d S r"   r
   r   r
   r
   r   ÚconnectionMadeF   s    zTestProtocol.connectionMadec                 C   s   d S r"   r
   )r   ÚcommandÚargumentr
   r
   r   ÚunhandledCommandJ   s    zTestProtocol.unhandledCommandc                 C   s   d S r"   r
   ©r   r=   r   r
   r
   r   ÚunhandledSubnegotiationN   s    z$TestProtocol.unhandledSubnegotiationN)Ú__name__Ú
__module__Ú__qualname__r4   r9   r   r-   r/   r1   r'   r7   r8   r:   r;   r<   r?   rA   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)rB   rC   rD   rH   r
   r
   r
   r   rE   S   s   rE   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   ZTelnetTransportr	   rG   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   )rG   Úprotocolr/   ÚassertEqualr   Újoin©r   ÚhÚLÚbr
   r
   r   ÚtestRegularBytesf   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   éþÿÿÿó   
é   ó   é   é   )rG   rM   r/   rN   r   rP   r
   r
   r   ÚtestNewlineHandlingy   s4    üÿþýüûúùþ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   ÿÿó   ÿ)rG   rM   r/   rN   r   rO   ÚreplacerP   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   )rG   rM   r   ÚIACr*   r/   rN   r   r   rO   r]   )r   ZcmdNamerQ   r%   rR   rS   r
   r
   r   Ú_simpleCommandTest¥   s    z'TelnetTransportTests._simpleCommandTestc                 C   s   |   d¡ d S )Nr   ©r`   r   r
   r
   r   ÚtestInterrupt´   s    z"TelnetTransportTests.testInterruptc                 C   s   |   d¡ d S )Nr   ra   r   r
   r
   r   ÚtestEndOfRecord·   s    z$TelnetTransportTests.testEndOfRecordc                 C   s   |   d¡ d S )Nr   ra   r   r
   r
   r   ÚtestNoOperationº   s    z$TelnetTransportTests.testNoOperationc                 C   s   |   d¡ d S )Nr   ra   r   r
   r
   r   ÚtestDataMark½   s    z!TelnetTransportTests.testDataMarkc                 C   s   |   d¡ d S )Nr   ra   r   r
   r
   r   Ú	testBreakÀ   s    zTelnetTransportTests.testBreakc                 C   s   |   d¡ d S )Nr   ra   r   r
   r
   r   ÚtestAbortOutputÃ   s    z$TelnetTransportTests.testAbortOutputc                 C   s   |   d¡ d S )Nr   ra   r   r
   r
   r   ÚtestAreYouThereÆ   s    z$TelnetTransportTests.testAreYouTherec                 C   s   |   d¡ d S )Nr   ra   r   r
   r
   r   ÚtestEraseCharacterÉ   s    z'TelnetTransportTests.testEraseCharacterc                 C   s   |   d¡ d S )Nr    ra   r   r
   r
   r   ÚtestEraseLineÌ   s    z"TelnetTransportTests.testEraseLinec                 C   s   |   d¡ d S )Nr!   ra   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)rG   rM   r   r_   ÚSBÚSEr/   rN   r   rO   r]   r   Úlistr   ©r   rQ   r%   rR   rS   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   )rG   rM   r   r_   rl   rm   r/   rN   r   rO   r]   r   ro   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   r_   rl   rm   ÚrangeÚlenr	   rG   rM   r-   r/   rN   r   rO   r]   r   rn   r   )r   r%   ÚirQ   ÚarS   rR   r   r
   r
   r   ÚtestBoundarySubnegotiationï   s.    ÿþýüûúÿ
z/TelnetTransportTests.testBoundarySubnegotiationc                 C   s<   |   |j|¡ |   |j|¡ |   |j|¡ |   |j|¡ d S r"   )rN   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   r_   ÚWILLrG   r/   rN   rM   r   r]   rK   ÚvalueÚDONTr|   ©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 r}   )r   r_   ÚDOrG   r/   rN   rM   r   r]   rK   r   ÚWONTr|   r�   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†   )rx   )r   r_   rƒ   rG   rM   r4   r/   rN   rK   r   r~   r|   ©r   r%   r   rQ   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Š   ©ry   )r   r_   r~   rG   rM   r9   r/   rN   rK   r   rƒ   r|   rˆ   r
   r
   r   ÚtestAcceptWill3  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©r{   )r   r_   r„   rG   ÚgetOptionStateÚhimÚstater/   rN   rM   r   r]   rK   r   r€   r|   ©r   r%   Úsr   r
   r
   r   ÚtestAcceptWont?  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�   )rz   )r   r_   r€   rG   r‘   Úusr“   r/   rN   rM   r   r]   rK   r   r„   r|   r”   r
   r
   r   ÚtestAcceptDontS  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   r_   r„   rG   r/   rN   rM   r   r]   rK   r   r|   r�   r
   r
   r   ÚtestIgnoreWontg  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   r_   r€   rG   r/   rN   rM   r   r]   rK   r   r|   r�   r
   r
   r   ÚtestIgnoreDonts  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   r_   r~   rG   r‘   r’   r“   r/   rN   rM   r   r]   rK   r   r|   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   r_   rƒ   rG   r‘   r—   r“   r/   rN   rM   r   r]   rK   r   r|   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‹   )r|   ©Ú_©rQ   r   r
   r   r&   µ  r   z@TelnetTransportTests.testAcceptedEnableRequest.<locals>.<lambda>)rG   ÚdorM   r9   rN   rK   r   r   r_   rƒ   r/   r~   Ú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"   ©r|   rG   rM   ©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   )rG   rM   r9   r¨   rN   rK   r   r   r_   rƒ   r‘   r’   r“   r—   Ú
assertTruer¯   r®   r/   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   )rG   rM   r4   ZwillrN   rK   r   r   r_   r~   r‘   r’   r“   r—   r®   r¯   r±   r/   r€   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&   ÿ  r   zATelnetTransportTests.testAcceptedDisableRequest.<locals>.<lambda>)rG   r‘   r’   r“   ÚdontrN   rK   r   r   r_   r€   r/   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¹   )rG   r¨   r²   r   ÚAlreadyNegotiating©Úxr,   r   r
   r   Ú_do
  s    zITelnetTransportTests.testNegotiationBlocksFurtherNegotiation.<locals>._doc                    s   ˆ j  d¡}ˆ  |tj¡S rº   )rG   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¹   )ry   r{   r¬   r¥   r   r
   r   r&     s     ÿz^TelnetTransportTests.testNegotiationBlocksFurtherNegotiation.<locals>._final.<locals>.<lambda>)rG   r/   r   r_   r„   r|   rM   r9   r¨   r~   r©   rN   r¼   r   r
   r   Ú_final  s    

ÿzLTelnetTransportTests.testNegotiationBlocksFurtherNegotiation.<locals>._final)rG   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ó   «)rG   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Ž   )rG   r‘   r’   r“   r¨   r²   r   Z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)rB   rC   rD   r
   r
   r
   r   ÚTestException8  s   rÇ   zTotal failure!)rG   r¨   Ú	Exceptionr1   r²   r   ZgatherResults)r   Úd1Zd2Zd3rÇ   r
   r
   r   Ú testLostConnectionFailsDeferreds3  s    z5TelnetTransportTests.testLostConnectionFailsDeferredsN))rB   rC   rD   Ú__doc__rL   rT   r[   r^   r`   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rp   rq   rv   r|   r‚   r…   r‰   rŒ   r–   r˜   r�   rž   r¡   r¢   r«   r´   rµ   r¸   rÁ   rÃ   rÄ   rÊ   r
   r
   r
   r   rI   \   sL   %rI   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   s   | j  d||f¡ dS )z=
        Record the given command in C{self.events}.
        r=   NrÐ   r@   r
   r
   r   r?   R  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   rA   X  s    z"TestTelnet.unhandledSubnegotiationN)rB   rC   rD   rË   r   rÑ   r?   rA   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Ì   rM   r   r
   r
   r   rL   g  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®   rM   r7   r   r
   r
   r   Útest_enableLocalm  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®   rM   r:   r   r
   r
   r   Útest_enableRemotet  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ÚNotImplementedErrorrM   r8   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Ø   rM   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   rJ   rM   r-   ZrequestNegotiationrN   r   ©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Û   r\   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)rM   rÎ   r/   rN   rn   )r   r   Ú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   r_   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.
        rX   rV   )rÏ   rV   s   
rÔ   )rÏ   rX   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   r_   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)rM   r(   rá   r   r_   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   r_   rl   rm   r   r
   r
   r   Ú(test_applicationDataBeforeSubnegotiation  s
    
ýz4TelnetTests.test_applicationDataBeforeSubnegotiationN)rB   rC   rD   rË   rL   rÕ   rÖ   rÙ   rÚ   rÞ   rß   rá   rä   ræ   ré   rë   rî   rï   rñ   rô   r
   r
   r
   r   rÓ   _  s"   			rÓ   N)rË   Zzope.interfacer   Zzope.interface.verifyr   Ztwisted.conchr   Ztwisted.internetr   Ztwisted.python.compatr   Ztwisted.testr   Ztwisted.trialr   rF   r	   ZTestCaserE   rI   rÍ   rÌ   rÓ   r
   r
   r
   r   Ú<module>   s    >	   j