U
    Jë]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
   úgc:\users\psant\downloads\hotstarbackend\school\venv\Lib\site-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>)   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   ÚcommandZ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>   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)rA   rB   rC   rG   r
   r
   r
   r   rD   S   s   rD   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	   rF   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   )rF   Ú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   éþÿÿÿó   
é   ó   é   é   )rF   rL   r/   rM   r   rO   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   ÿÿó   ÿ)rF   rL   r/   rM   r   rN   ÚreplacerO   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   )rF   rL   r   ÚIACr*   r/   rM   r   r   rN   r\   )r   ZcmdNamerP   r%   rQ   rR   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   r`   r   r
   r
   r   ÚtestEndOfRecord·   s    z$TelnetTransportTests.testEndOfRecordc                 C   s   |   d¡ d S )Nr   r`   r   r
   r
   r   ÚtestNoOperationº   s    z$TelnetTransportTests.testNoOperationc                 C   s   |   d¡ d S )Nr   r`   r   r
   r
   r   ÚtestDataMark½   s    z!TelnetTransportTests.testDataMarkc                 C   s   |   d¡ d S )Nr   r`   r   r
   r
   r   Ú	testBreakÀ   s    zTelnetTransportTests.testBreakc                 C   s   |   d¡ d S )Nr   r`   r   r
   r
   r   ÚtestAbortOutputÃ   s    z$TelnetTransportTests.testAbortOutputc                 C   s   |   d¡ d S )Nr   r`   r   r
   r
   r   ÚtestAreYouThereÆ   s    z$TelnetTransportTests.testAreYouTherec                 C   s   |   d¡ d S )Nr   r`   r   r
   r
   r   ÚtestEraseCharacterÉ   s    z'TelnetTransportTests.testEraseCharacterc                 C   s   |   d¡ d S )Nr    r`   r   r
   r
   r   ÚtestEraseLineÌ   s    z"TelnetTransportTests.testEraseLinec                 C   s   |   d¡ d S )Nr!   r`   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)rF   rL   r   r^   ÚSBÚSEr/   rM   r   rN   r\   r   Úlistr   ©r   rP   r%   rQ   rR   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   )rF   rL   r   r^   rk   rl   r/   rM   r   rN   r\   r   rn   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^   rk   rl   ÚrangeÚlenr	   rF   rL   r-   r/   rM   r   rN   r\   r   rm   r   )r   r%   ÚirP   ÚarR   rQ   r   r
   r
   r   ÚtestBoundarySubnegotiationï   s.    ÿþýüûúÿ
z/TelnetTransportTests.testBoundarySubnegotiationc                 C   s<   |   |j|¡ |   |j|¡ |   |j|¡ |   |j|¡ d S r"   )rM   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^   ÚWILLrF   r/   rM   rL   r   r\   rJ   Ú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^   ÚDOrF   r/   rM   rL   r   r\   rJ   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…   )rw   )r   r^   r‚   rF   rL   r4   r/   rM   rJ   r~   r}   r{   ©r   r%   r   rP   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‰   ©rx   )r   r^   r}   rF   rL   r9   r/   rM   rJ   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©rz   )r   r^   rƒ   rF   ÚgetOptionStateÚhimÚstater/   rM   rL   r   r\   rJ   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Ž   )ry   )r   r^   r   rF   r�   Úusr’   r/   rM   rL   r   r\   rJ   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ƒ   rF   r/   rM   rL   r   r\   rJ   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   rF   r/   rM   rL   r   r\   rJ   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}   rF   r�   r‘   r’   r/   rM   rL   r   r\   rJ   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‚   rF   r�   r–   r’   r/   rM   rL   r   r\   rJ   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{   ©Ú_©rP   r   r
   r   r&   µ  r   z@TelnetTransportTests.testAcceptedEnableRequest.<locals>.<lambda>)rF   ÚdorL   r9   rM   rJ   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{   rF   rL   ©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   )rF   rL   r9   r§   rM   rJ   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   )rF   rL   r4   ZwillrM   rJ   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>)rF   r�   r‘   r’   ÚdontrM   rJ   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¸   )rF   r§   r±   r   ÚAlreadyNegotiating©Úxr,   r   r
   r   Ú_do
  s    zITelnetTransportTests.testNegotiationBlocksFurtherNegotiation.<locals>._doc                    s   ˆ j  d¡}ˆ  |tj¡S r¹   )rF   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¸   )rx   rz   r«   r¤   r   r
   r   r&     s     ÿz^TelnetTransportTests.testNegotiationBlocksFurtherNegotiation.<locals>._final.<locals>.<lambda>)rF   r/   r   r^   rƒ   r{   rL   r9   r§   r}   r¨   rM   r»   r   r
   r   Ú_final  s    

ÿzLTelnetTransportTests.testNegotiationBlocksFurtherNegotiation.<locals>._final)rF   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ó   «)rF   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�   )rF   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)rA   rB   rC   r
   r
   r
   r   ÚTestException8  s   rÆ   zTotal failure!)rF   r§   Ú	Exceptionr1   r±   r   ZgatherResults)r   Úd1Zd2Zd3rÆ   r
   r
   r   Ú testLostConnectionFailsDeferreds3  s    z5TelnetTransportTests.testLostConnectionFailsDeferredsN))rA   rB   rC   Ú__doc__rK   rS   rZ   r]   r_   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   ro   rp   ru   r{   r�   r„   rˆ   r‹   r•   r—   rœ   r�   r    r¡   rª   r³   r´   r·   rÀ   rÂ   rÃ   rÉ   r
   r
   r
   r   rH   \   sL   %rH   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   r@   X  s    z"TestTelnet.unhandledSubnegotiationN)rA   rB   rC   rÊ   r   rÐ   r>   r@   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Ë   rL   r   r
   r
   r   rK   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­   rL   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­   rL   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ÚNotImplementedErrorrL   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×   rL   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   rI   rL   r-   ZrequestNegotiationrM   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)rL   rÍ   r/   rM   rm   )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.
        rW   rU   )rÎ   rU   s   
rÓ   )rÎ   rW   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)rL   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^   rk   rl   r   r
   r
   r   Ú(test_applicationDataBeforeSubnegotiation  s
    
ýz4TelnetTests.test_applicationDataBeforeSubnegotiationN)rA   rB   rC   rÊ   rK   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   rE   r	   ZTestCaserD   rH   rÌ   rË   rÒ   r
   r
   r
   r   Ú<module>   s    >	   j