o
    Òó·i·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
   údC:\Users\psant\Downloads\PAF backend\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>)   s    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   ó   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#   r7   r
   r
   r   ÚdisableLocal:   ó   zTestProtocol.disableLocalc                 C   r4   r5   )ÚremoteEnableabler   r#   r7   r
   r
   r   ÚenableRemote=   r:   zTestProtocol.enableRemotec                 C   r;   r"   )r   r#   r7   r
   r
   r   ÚdisableRemoteC   r=   zTestProtocol.disableRemotec                 C   r0   r"   r
   r   r
   r
   r   ÚconnectionMadeF   ó   zTestProtocol.connectionMadec                 C   r0   r"   r
   )r   ÚcommandZargumentr
   r
   r   ÚunhandledCommandJ   rB   zTestProtocol.unhandledCommandc                 C   r0   r"   r
   ©r   rC   r   r
   r
   r   ÚunhandledSubnegotiationN   rB   z$TestProtocol.unhandledSubnegotiationN)Ú__name__Ú
__module__Ú__qualname__r6   r>   r   r-   r/   r2   r'   r9   r<   r?   r@   rA   rD   rF   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)rG   rH   rI   rM   r
   r
   r
   r   rJ   S   s    rJ   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	   rL   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   )rL   Úprotocolr/   Ú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   éþÿÿÿó   
é   ó   é   é   )rL   rR   r/   rS   r   rU   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   ÿÿó   ÿ)rL   rR   r/   rS   r   rT   ÚreplacerU   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   )rL   rR   r   ÚIACr*   r/   rS   r   r   rT   rb   )r   ZcmdNamerV   r%   rW   rX   r
   r
   r   Ú_simpleCommandTest¥   s    z'TelnetTransportTests._simpleCommandTestc                 C   ó   |   d¡ d S )Nr   ©re   r   r
   r
   r   ÚtestInterrupt´   ó   z"TelnetTransportTests.testInterruptc                 C   rf   )Nr   rg   r   r
   r
   r   ÚtestEndOfRecord·   ri   z$TelnetTransportTests.testEndOfRecordc                 C   rf   )Nr   rg   r   r
   r
   r   ÚtestNoOperationº   ri   z$TelnetTransportTests.testNoOperationc                 C   rf   )Nr   rg   r   r
   r
   r   ÚtestDataMark½   ri   z!TelnetTransportTests.testDataMarkc                 C   rf   )Nr   rg   r   r
   r
   r   Ú	testBreakÀ   ri   zTelnetTransportTests.testBreakc                 C   rf   )Nr   rg   r   r
   r
   r   ÚtestAbortOutputÃ   ri   z$TelnetTransportTests.testAbortOutputc                 C   rf   )Nr   rg   r   r
   r
   r   ÚtestAreYouThereÆ   ri   z$TelnetTransportTests.testAreYouTherec                 C   rf   )Nr   rg   r   r
   r
   r   ÚtestEraseCharacterÉ   ri   z'TelnetTransportTests.testEraseCharacterc                 C   rf   )Nr    rg   r   r
   r
   r   ÚtestEraseLineÌ   ri   z"TelnetTransportTests.testEraseLinec                 C   rf   )Nr!   rg   r   r
   r
   r   ÚtestGoAheadÏ   ri   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)rL   rR   r   rd   ÚSBÚSEr/   rS   r   rT   rb   r   Úlistr   ©r   rV   r%   rW   rX   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   )rL   rR   r   rd   rs   rt   r/   rS   r   rT   rb   r   rv   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   rd   rs   rt   ÚrangeÚlenr	   rL   rR   r-   r/   rS   r   rT   rb   r   ru   r   )r   r%   ÚirV   ÚarX   rW   r   r
   r
   r   ÚtestBoundarySubnegotiationï   s0   ÿþýüûúÿ
 õz/TelnetTransportTests.testBoundarySubnegotiationc                 C   s<   |   |j|¡ |   |j|¡ |   |j|¡ |   |j|¡ d S r"   )rS   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   rd   ÚWILLrL   r/   rS   rR   r   rb   rP   ÚvalueÚDONTrƒ   ©r   r%   r   r
   r
   r   ÚtestRefuseWill  ó   z#TelnetTransportTests.testRefuseWillc                 C   r„   r…   )r   rd   ÚDOrL   r/   rS   rR   r   rb   rP   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   rd   rŒ   rL   rR   r6   r/   rS   rP   r‡   r†   rƒ   ©r   r%   r   rV   r
   r
   r   ÚtestAcceptDo&  s   z!TelnetTransportTests.testAcceptDoc                 C   r�   )Nó   ‘s   headerr‘   )r”   ©r€   )r   rd   r†   rL   rR   r>   r/   rS   rP   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   rd   r�   rL   ÚgetOptionStateÚhimÚstater/   rS   rR   r   rb   rP   r‡   rˆ   rƒ   ©r   r%   Úsr   r
   r
   r   ÚtestAcceptWont?  ó   z#TelnetTransportTests.testAcceptWontc                 C   r—   )Nr˜   r™   s   fiddle dum r   rš   )r�   )r   rd   rˆ   rL   rœ   Úusrž   r/   rS   rR   r   rb   rP   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   rd   r�   rL   r/   rS   rR   r   rb   rP   r‡   rƒ   r‰   r
   r
   r   ÚtestIgnoreWontg  s   z#TelnetTransportTests.testIgnoreWontc                 C   r¥   r¦   )r   rd   rˆ   rL   r/   rS   rR   r   rb   rP   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   rd   r†   rL   rœ   r�   rž   r/   rS   rR   r   rb   rP   r‡   rƒ   rŸ   r
   r
   r   ÚtestIgnoreWill€  ó   z#TelnetTransportTests.testIgnoreWillc                 C   r¬   r­   )r   rd   rŒ   rL   rœ   r£   rž   r/   rS   rR   r   rb   rP   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ƒ   ©Ú_©rV   r   r
   r   r&   µ  s    z@TelnetTransportTests.testAcceptedEnableRequest.<locals>.<lambda>)rL   ÚdorR   r>   rS   rP   r‡   r   rd   rŒ   r/   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ƒ   rL   rR   ©Zignoredr   r
   r   r&   Ð  ó    z@TelnetTransportTests.test_refusedEnableRequest.<locals>.<lambda>c                    ó   ˆ  ˆ jj¡S r"   )ÚassertFalser�   Únegotiatingr¾   ©r    r   r
   r   r&   Ñ  r¿   N)rL   rR   r>   r·   rS   rP   r‡   r   rd   rŒ   rœ   r�   rž   r£   Ú
assertTruerÂ   rÁ   r/   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¿   N)rL   rR   r6   ZwillrS   rP   r‡   r   rd   r†   rœ   r�   rž   r£   rÁ   rÂ   rÄ   r/   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>)rL   rœ   r�   rž   ÚdontrS   rP   r‡   r   rd   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                    ó   ˆ j  d¡}ˆ  |tj¡S ©NrÍ   )rL   r·   rÅ   r   ÚAlreadyNegotiating©Úxr,   r   r
   r   Ú_do
  ó   zITelnetTransportTests.testNegotiationBlocksFurtherNegotiation.<locals>._doc                    rÎ   rÏ   )rL   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>)rL   r/   r   rd   r�   rƒ   rR   r>   r·   r†   r¸   rS   rÑ   r   r
   r   Ú_final  s   

ÿzLTelnetTransportTests.testNegotiationBlocksFurtherNegotiation.<locals>._final)rL   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ó   «)rL   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™   )rL   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)rG   rH   rI   r
   r
   r
   r   ÚTestException8  s    rÝ   zTotal failure!)rL   r·   Ú	Exceptionr2   rÅ   r   ZgatherResults)r   Zd1Zd2Zd3rÝ   r
   r
   r   Ú testLostConnectionFailsDeferreds3  s   z5TelnetTransportTests.testLostConnectionFailsDeferredsN))rG   rH   rI   Ú__doc__rQ   rY   r`   rc   re   rh   rj   rk   rl   rm   rn   ro   rp   rq   rr   rw   rx   r}   rƒ   rŠ   rŽ   r“   r–   r¡   r¤   rª   r«   r¯   r±   rº   rÇ   rÉ   rÌ   r×   rÙ   rÚ   rß   r
   r
   r
   r   rN   \   sN    %rN   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}.
        rC   Nrå   rE   r
   r
   r   rD   R  ó   zTestTelnet.unhandledCommandc                 C   rç   )zL
        Record the given subnegotiation command in C{self.events}.
        Ú	negotiateNrå   rE   r
   r
   r   rF   X  rè   z"TestTelnet.unhandledSubnegotiationN)rG   rH   rI   rà   r   ræ   rD   rF   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á   rR   r   r
   r
   r   rQ   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Á   rR   r9   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Á   rR   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ÚNotImplementedErrorrR   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ò   rR   r@   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   rO   rR   r-   ZrequestNegotiationrS   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÷   ra   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)rR   rã   r/   rS   ru   )r   r   ÚexpectedZ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   rd   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.
        r]   r[   )rä   r[   s   
rì   )rä   r]   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  rC   N)rý   r   rd   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  rC   N)rR   r(   rý   r   rd   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   rd   rs   rt   r   r
   r
   r   Ú(test_applicationDataBeforeSubnegotiation  s
   
ýz4TelnetTests.test_applicationDataBeforeSubnegotiationN)rG   rH   rI   rà   rQ   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   rK   r	   ZTestCaserJ   rN   râ   rá   rê   r
   r
   r
   r   Ú<module>   s"   >	   j