U
    Â“«jb  ã                   @   sf  d Z ddlZddl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mZ ddlmZ dd	lmZmZmZ dd
lmZ ddlmZ ddlmZmZ edƒZeejƒZej  ej!¡ed< G dd„ deƒZ"ddlm#Z# ddlm$Z$ ddl%m&Z& G dd„ dej'ƒZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1ddl	m2Z2 z@dd l3m4Z4m5Z5m6Z6m7Z7m8Z8 dd!l9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z? W n e@k
�r�   d"ZAY nŽX d#ZAG d$d%„ d%e:jBƒZCG d&d'„ d'e;jDƒZEG d(d)„ d)e?jFƒZGG d*d+„ d+e>jHƒZIG d,d-„ d-e7ƒZJG d.d/„ d/e6ƒZKG d0d1„ d1e8ƒZLe MeKeLe=jN¡ G d2d3„ d3e$jOƒZPG d4d5„ d5ƒZQG d6d7„ d7eQƒZRdd8lSmTZT G d9d:„ d:ejUeTjVƒZWG d;d<„ d<ejXeTjVƒZYG d=d>„ d>eQƒZZG d?d@„ d@eQƒZ[G dAdB„ dBƒZ\G dCdD„ dDeZee\ƒZ]G dEdF„ dFeRee\ƒZ^ee dGƒG dHdI„ dIe[ee\ƒƒZ_G dJdK„ dKƒZ`G dLdM„ dMeZee`ƒZaG dNdO„ dOeRee`ƒZbee dPƒG dQdR„ dRe[ee`ƒƒZcG dSdT„ dTeƒZddS )UzU
Tests for L{twisted.conch.recvline} and fixtures for testing related
functionality.
é    N)ÚskipIf)Úrecvline)Úinsults)Úportal)ÚdeferÚerror)ÚStringTransport)Ú
componentsÚfilepathÚreflect)Ú	iterbytes)ÚrequireModule)ÚSkipTestÚTestCaseztwisted.conch.stdioÚ
PYTHONPATHc                   @   sl   e 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 )ÚArrowsTestsc                    sF   t ƒ ˆ _t ¡ ˆ _t ¡ ˆ _‡ fdd„ˆ j_ˆ ˆ j_	ˆ j 
ˆ j¡ d S )Nc                      s   ˆ j S ©N)Úp© ©Úselfr   úD/tmp/pip-unpacked-wheel-59kc99xd/twisted/conch/test/test_recvline.pyÚ<lambda>"   ó    z#ArrowsTests.setUp.<locals>.<lambda>)r   ZunderlyingTransportr   ÚServerProtocolÚptr   ÚHistoricRecvLiner   ÚprotocolFactoryÚfactoryÚmakeConnectionr   r   r   r   ÚsetUp   s    

zArrowsTests.setUpc                 C   s@   | j  dd¡ | j  dd¡ | j  dd¡ |  | j  ¡ d¡ dS )zy
        When L{HistoricRecvLine} receives a printable character,
        it adds it to the current line buffer.
        ó   xNó   yó   z©ó   xyzr   )r   ÚkeystrokeReceivedÚassertEqualÚcurrentLineBufferr   r   r   r   Útest_printableCharacters&   s    z$ArrowsTests.test_printableCharactersc                    sF  ‡ fdd„}t dƒD ]}||ƒ qˆ  ˆ j ¡ d¡ |ˆ jjƒ ˆ  ˆ j ¡ d¡ |ˆ jjƒ ˆ  ˆ j ¡ d¡ |ˆ jjƒ ˆ  ˆ j ¡ d¡ |ˆ jjƒ ˆ  ˆ j ¡ d¡ |ˆ jjƒ ˆ  ˆ j ¡ d¡ |ˆ jjƒ ˆ  ˆ j ¡ d¡ |ˆ jjƒ ˆ  ˆ j ¡ d¡ |ˆ jjƒ ˆ  ˆ j ¡ d¡ |ˆ jjƒ ˆ  ˆ j ¡ d¡ dS )	zµ
        When L{HistoricRecvLine} receives a LEFT_ARROW or
        RIGHT_ARROW keystroke it moves the cursor left or right
        in the current line buffer, respectively.
        c                    s   ˆ j  | d ¡S r   ©r   r&   ©Úchr   r   r   r   7   r   z3ArrowsTests.test_horizontalArrows.<locals>.<lambda>r%   r$   )ó   xyr#   )r!   s   yz)r   r%   N)r   r'   r   r(   r   ZRIGHT_ARROWÚ
LEFT_ARROW©r   ÚkRr,   r   r   r   Útest_horizontalArrows1   s,    
z!ArrowsTests.test_horizontalArrowsc                    s|   ‡ fdd„}t dƒD ]}||ƒ qˆ  ˆ j ¡ d¡ |dƒ |dƒ |dƒ ˆ  ˆ j ¡ d¡ |dƒ ˆ  ˆ j ¡ d	¡ d
S )z‡
        When {HistoricRecvLine} receives a newline, it adds the current
        line buffer to the end of its history buffer.
        c                    s   ˆ j  | d ¡S r   r*   r+   r   r   r   r   ]   r   z*ArrowsTests.test_newline.<locals>.<lambda>ó   xyz
abc
123
©©r%   ó   abcó   123r   ó   có   bó   aó   
))r%   r5   r6   s   cbar   N)r   r'   r   ÚcurrentHistoryBufferr/   r   r   r   Útest_newlineX   s    
 ÿzArrowsTests.test_newlinec                    s8  ‡ fdd„}t dƒD ]}||ƒ qˆ  ˆ j ¡ d¡ ˆ  ˆ j ¡ d¡ |ˆ jjƒ ˆ  ˆ j ¡ d¡ ˆ  ˆ j ¡ d¡ |ˆ jjƒ ˆ  ˆ j ¡ d¡ ˆ  ˆ j ¡ d	¡ |ˆ jjƒ ˆ  ˆ j ¡ d
¡ ˆ  ˆ j ¡ d¡ |ˆ jjƒ ˆ  ˆ j ¡ d
¡ ˆ  ˆ j ¡ d¡ tdƒD ]}|ˆ jjƒ �qˆ  ˆ j ¡ d¡ dS )a  
        When L{HistoricRecvLine} receives UP_ARROW or DOWN_ARROW
        keystrokes it move the current index in the current history
        buffer up or down, and resets the current line buffer to the
        previous or next line in history, respectively for each.
        c                    s   ˆ j  | d ¡S r   r*   r+   r   r   r   r   u   r   z1ArrowsTests.test_verticalArrows.<locals>.<lambda>r2   r3   ©r   r   ))r%   r5   )r6   )r6   r   ))r%   )r5   r6   )r5   r   )r   r4   r$   é   N)	r   r'   r   r;   r(   r   ZUP_ARROWÚrangeZ
DOWN_ARROW)r   r0   r,   Úir   r   r   Útest_verticalArrowsn   s(    
zArrowsTests.test_verticalArrowsc                    sV   ‡ fdd„}t dƒD ]}||ƒ qˆ  ˆ j ¡ d¡ |ˆ jjƒ ˆ  ˆ j ¡ d¡ dS )z�
        When L{HistoricRecvLine} receives a HOME keystroke it moves the
        cursor to the beginning of the current line buffer.
        c                    s   ˆ j  | d ¡S r   r*   r+   r   r   r   r   –   r   z'ArrowsTests.test_home.<locals>.<lambda>ó   hello, world©rB   r   )r   rB   N)r   r'   r   r(   r   ÚHOMEr/   r   r   r   Ú	test_home‘   s    
zArrowsTests.test_homec                    sb   ‡ fdd„}t dƒD ]}||ƒ qˆ  ˆ j ¡ d¡ |ˆ jjƒ |ˆ jjƒ ˆ  ˆ j ¡ d¡ dS )z‡
        When L{HistoricRecvLine} receives an END keystroke it moves the cursor
        to the end of the current line buffer.
        c                    s   ˆ j  | d ¡S r   r*   r+   r   r   r   r   ¤   r   z&ArrowsTests.test_end.<locals>.<lambda>rB   rC   N)r   r'   r   r(   r   rD   ZENDr/   r   r   r   Útest_endŸ   s    
zArrowsTests.test_endc                    sž   ‡ fdd„}t dƒD ]}||ƒ qˆ  ˆ j ¡ d¡ |ˆ jjƒ ˆ  ˆ j ¡ d¡ |ˆ jjƒ |ˆ jjƒ ˆ  ˆ j ¡ d¡ |ˆ jjƒ ˆ  ˆ j ¡ d¡ dS )z‰
        When L{HistoricRecvLine} receives a BACKSPACE keystroke it deletes
        the character immediately before the cursor.
        c                    s   ˆ j  | d ¡S r   r*   r+   r   r   r   r   ³   r   z,ArrowsTests.test_backspace.<locals>.<lambda>r%   r$   ©r-   r   )r   r"   N)r   r'   r   r(   r   Z	BACKSPACEr.   r/   r   r   r   Útest_backspace®   s    
zArrowsTests.test_backspacec                    sò   ‡ fdd„}t dƒD ]}||ƒ qˆ  ˆ j ¡ d¡ |ˆ jjƒ ˆ  ˆ j ¡ d¡ |ˆ jjƒ |ˆ jjƒ ˆ  ˆ j ¡ d¡ |ˆ jjƒ |ˆ jjƒ ˆ  ˆ j ¡ d¡ |ˆ jjƒ |ˆ jjƒ ˆ  ˆ j ¡ d¡ |ˆ jjƒ ˆ  ˆ j ¡ d¡ dS )	z…
        When L{HistoricRecvLine} receives a DELETE keystroke, it
        delets the character immediately after the cursor.
        c                    s   ˆ j  | d ¡S r   r*   r+   r   r   r   r   È   r   z)ArrowsTests.test_delete.<locals>.<lambda>r%   r$   rG   )r!   r   r=   N)r   r'   r   r(   r   ÚDELETEr.   r/   r   r   r   Útest_deleteÃ   s"    
zArrowsTests.test_deletec                    sr   ‡ fdd„}t dƒD ]}||ƒ q|ˆ jjƒ |dƒ ˆ  ˆ j ¡ d¡ |ˆ jjƒ |dƒ ˆ  ˆ j ¡ d¡ dS )	z‹
        When not in INSERT mode, L{HistoricRecvLine} inserts the typed
        character at the cursor before the next character.
        c                    s   ˆ j  | d ¡S r   r*   r+   r   r   r   r   å   r   z)ArrowsTests.test_insert.<locals>.<lambda>r%   ó   A)ó   xyAr#   ó   B)ó   xyBs   AzN)r   r   r.   r'   r   r(   r/   r   r   r   Útest_insertà   s    
zArrowsTests.test_insertc                    s~   ‡ fdd„}t dƒD ]}||ƒ q|ˆ jjƒ |ˆ jjƒ |dƒ ˆ  ˆ j ¡ d¡ |ˆ jjƒ |dƒ ˆ  ˆ j ¡ d¡ dS )	a  
        When in INSERT mode and upon receiving a keystroke with a printable
        character, L{HistoricRecvLine} replaces the character at
        the cursor with the typed character rather than inserting before.
        Ah, the ironies of INSERT mode.
        c                    s   ˆ j  | d ¡S r   r*   r+   r   r   r   r   ù   r   z+ArrowsTests.test_typeover.<locals>.<lambda>r%   rK   )rL   r   rM   )rN   r   N)r   r   ZINSERTr.   r'   r   r(   r/   r   r   r   Útest_typeoverò   s    
zArrowsTests.test_typeoverc                    sr   ‡ fdd„}ˆ j }|j|j|j|j|j|j|j|j|j	|j
|j|j|j|jfD ]}||ƒ ˆ  ˆ j ¡ d¡ qNdS )z¡
        When L{HistoricRecvLine} receives a keystroke for an unprintable
        function key with no assigned behavior, the line buffer is unmodified.
        c                    s   ˆ j  | d ¡S r   r*   r+   r   r   r   r     r   z8ArrowsTests.test_unprintableCharacters.<locals>.<lambda>r=   N)r   ZF1ZF2ZF3ZF4ZF5ZF6ZF7ZF8ZF9ZF10ZF11ZF12ZPGUPZPGDNr'   r   r(   )r   r0   r   r,   r   r   r   Útest_unprintableCharacters  s&    òz&ArrowsTests.test_unprintableCharactersN)Ú__name__Ú
__module__Ú__qualname__r    r)   r1   r<   rA   rE   rF   rH   rJ   rO   rP   rQ   r   r   r   r   r      s   '#r   )Útelnet)Úhelper)ÚLoopbackRelayc                   @   s   e Zd Zdd„ ZdS )Ú
EchoServerc                 C   s    | j  |d | j| j  ¡ d S )Nr:   )ZterminalÚwriteZpsZpn)r   Úliner   r   r   ÚlineReceived*  s    zEchoServer.lineReceivedN)rR   rS   rT   r[   r   r   r   r   rX   )  s   rX   s   [Ds   [Cs   [As   [Bs   [2~s   [1~s   [3~s   [4~ó   )Úcheckers)ÚConchFactoryÚTerminalRealmÚTerminalSessionÚTerminalSessionTransportÚTerminalUser)ÚchannelÚ
connectionÚkeysÚsessionÚ	transportÚuserauthFTc                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚSessionChannels   sessionc                 O   s6   t jj| f|ž|Ž || _|| _|| _|| _|| _d S r   )rc   Ú
SSHChannelÚ__init__r   ÚprotocolArgsÚprotocolKwArgsÚwidthÚheight©r   r   rl   rm   rn   ro   ÚaÚkwr   r   r   rk   S  s    zSessionChannel.__init__c                 C   sd   t  d| j| jddfd¡}| j | d|¡ | j | dd¡ | j| j| jŽ| _	| | j	_
| j	 | ¡ d S )Ns   vt102r   r   s   pty-reqs   shell)rf   ZpackRequest_pty_reqro   rn   ÚconnZsendRequestr   rl   rm   Ú_protocolInstancer   r   )r   ÚdataZtermr   r   r   ÚchannelOpen_  s      ÿ ÿzSessionChannel.channelOpenc                 C   s   | j  t ¡ ¡ d S r   )rt   ÚconnectionLostr   ZConnectionDoner   r   r   r   Úclosedl  s    zSessionChannel.closedc                 C   s   | j  |¡ d S r   )rt   ÚdataReceived©r   ru   r   r   r   ry   o  s    zSessionChannel.dataReceivedN)rR   rS   rT   Únamerk   rv   rx   ry   r   r   r   r   ri   P  s
   ri   c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚTestConnectionc                 O   s6   t jj| f|ž|Ž || _|| _|| _|| _|| _d S r   )rd   ÚSSHConnectionrk   r   rl   rm   rn   ro   rp   r   r   r   rk   s  s    zTestConnection.__init__c                 C   s,   t | j| j| j| j| jƒ| _|  | j¡ d S r   )ri   r   rl   rm   rn   ro   Ú_TestConnection__channelZopenChannelr   r   r   r   ÚserviceStarted  s    ûzTestConnection.serviceStartedc                 C   s   | j  |¡S r   )r~   rY   rz   r   r   r   rY   ‰  s    zTestConnection.writeN)rR   rS   rT   rk   r   rY   r   r   r   r   r|   r  s   
r|   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚTestAuthc                 O   s    t jj| |f|ž|Ž || _d S r   )rh   ÚSSHUserAuthClientrk   Úpassword)r   Úusernamer‚   rq   rr   r   r   r   rk   �  s    zTestAuth.__init__c                 C   s   t  | j¡S r   )r   Úsucceedr‚   r   r   r   r   ÚgetPassword‘  s    zTestAuth.getPasswordN)rR   rS   rT   rk   r…   r   r   r   r   r€   Œ  s   r€   c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚTestTransportc           
      O   s.   || _ || _|| _|| _|| _|| _|| _d S r   )r   rl   rm   rƒ   r‚   rn   ro   )
r   r   rl   rm   rƒ   r‚   rn   ro   rq   rr   r   r   r   rk   •  s    zTestTransport.__init__c                 C   s
   t  d¡S )NT)r   r„   )r   ZhostKeyÚfingerprintr   r   r   ÚverifyHostKey©  s    zTestTransport.verifyHostKeyc                 C   s8   t | j| j| j| j| jƒ| _|  t| j	| j
| jƒ¡ d S r   )r|   r   rl   rm   rn   ro   Ú_TestTransport__connectionZrequestServicer€   rƒ   r‚   r   r   r   r   ÚconnectionSecure¬  s    ûÿzTestTransport.connectionSecurec                 C   s   | j  |¡S r   )r‰   rY   rz   r   r   r   rY   ¸  s    zTestTransport.writeN)rR   rS   rT   rk   rˆ   rŠ   rY   r   r   r   r   r†   ”  s   r†   c                   @   s   e Zd Zdd„ ZdS )ÚTestSessionTransportc                 C   s   | j jjj ¡ S r   )Zavatarrs   rg   r   ÚserverProtocolr   r   r   r   r   ¼  s    z$TestSessionTransport.protocolFactoryN)rR   rS   rT   r   r   r   r   r   r‹   »  s   r‹   c                   @   s   e Zd ZeZdS )ÚTestSessionN)rR   rS   rT   r‹   ZtransportFactoryr   r   r   r   r�   ¿  s   r�   c                   @   s   e Zd ZdS )ÚTestUserN©rR   rS   rT   r   r   r   r   rŽ   Â  s   rŽ   c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚNotifyingExpectableBufferc                 C   s   t  ¡ | _t  ¡ | _d S r   )r   ZDeferredÚonConnectionÚonDisconnectionr   r   r   r   rk   É  s    
z"NotifyingExpectableBuffer.__init__c                 C   s   t j | ¡ | j | ¡ d S r   )rV   ÚExpectableBufferÚconnectionMader‘   Úcallbackr   r   r   r   r”   Í  s    z(NotifyingExpectableBuffer.connectionMadec                 C   s   | j  |¡ d S r   )r’   Zerrback)r   Úreasonr   r   r   rw   Ñ  s    z(NotifyingExpectableBuffer.connectionLostN)rR   rS   rT   rk   r”   rw   r   r   r   r   r�   È  s   r�   c                   @   s$   e Zd ZdZdZdd„ Zdd„ ZdS )Ú
_BaseMixinéP   é   c                 C   s:   | j  ¡  ¡ }|dg| jt|ƒ d   }|  ||¡ d S )Nr   é   )ÚrecvlineClientÚ	__bytes__Ú
splitlinesÚHEIGHTÚlenr'   )r   ÚlinesZreceivedLinesZexpectedLinesr   r   r   Ú_assertBufferÙ  s    z_BaseMixin._assertBufferc                    s.   ˆj  d¡}ˆ |¡ ‡ ‡fdd„}| |¡S )Ns   donec                    s   ˆ  ˆ ¡ d S r   )r¡   )Zign©Úoutputr   r   r   Úfinishedã  s    z)_BaseMixin._trivialTest.<locals>.finished)r›   ÚexpectÚ
_testwriteZaddCallback)r   Z	inputLiner£   Údoner¤   r   r¢   r   Ú_trivialTestÞ  s    
z_BaseMixin._trivialTestN)rR   rS   rT   ÚWIDTHrž   r¡   r¨   r   r   r   r   r—   Õ  s   r—   c                   @   s   e Zd Zdd„ Zdd„ ZdS )Ú	_SSHMixinc                    s>  t stdƒ‚d\}}tƒ }t|_‡fdd„|_t ¡ }| ||¡ t	 
|¡}| |¡ t|ƒ}tjt |  ¡ ¡dd�}||jd< ||jd< | j|_| ¡  |  ¡ ‰t ‡fdd„¡‰| d ¡}t|ƒ}	tƒ ‰t ‡fd	d„¡‰ t‡ fd
d„di ||| j| jƒ}
t|
ƒ}|
 |	¡ | |¡ ˆ| _ |
| _!|| _"|	| _#|| _$ˆj%S )NzMcryptography requirements missing, can't run historic recvline tests over ssh)s   testusers   testpassc                      s   ˆ S r   r   r   ©ÚinsultsServerr   r   r   ô  r   z!_SSHMixin.setUp.<locals>.<lambda>i   )ZkeySizes   ssh-rsac                      s   ˆ S r   r   r   ©ÚrecvlineServerr   r   r     r   c                      s   ˆ S r   r   r   ©r›   r   r   r     r   c                      s   ˆ S r   r   r   ©ÚinsultsClientr   r   r     r   r   )&Ússhr   r_   rŽ   ZuserFactoryZchainedProtocolFactoryr]   Z'InMemoryUsernamePasswordDatabaseDontUseZaddUserr   ZPortalZregisterCheckerr^   re   Z_getPersistentRSAKeyr
   ZFilePathÚmktempZ
publicKeysZprivateKeysrŒ   ZstartFactoryr   r   ZbuildProtocolrW   r�   ÚClientProtocolr†   r©   rž   r   r›   Ú	sshClientÚ	sshServerÚclientTransportÚserverTransportr‘   )r   Úur   ÚrlmÚcheckerZptlZ
sshFactoryZsshKeyr¶   r·   rµ   r¸   r   ©r±   r¬   r›   r®   r   r    ê  sZ    ÿ

 ÿ



      ÿ

z_SSHMixin.setUpc                 C   s   | j  |¡ d S r   )rµ   rY   rz   r   r   r   r¦     s    z_SSHMixin._testwriteN©rR   rS   rT   r    r¦   r   r   r   r   rª   é  s   2rª   )Útest_telnetc                   @   s   e Zd ZdS )ÚTestInsultsClientProtocolNr�   r   r   r   r   r¿   #  s   r¿   c                   @   s   e Zd ZdS )ÚTestInsultsServerProtocolNr�   r   r   r   r   rÀ   '  s   rÀ   c                   @   s   e Zd Zdd„ Zdd„ ZdS )Ú_TelnetMixinc                    s¤   |   ¡ ‰t‡fdd„ƒ‰t ‡fdd„¡}t|ƒ}tƒ ‰t‡fdd„ƒ‰ t ‡ fdd„¡}t|ƒ}| |¡ | |¡ | ¡  | ¡  ˆ| _	|| _
|| _|| _ˆjS )Nc                      s   ˆ S r   r   r   r­   r   r   r   .  r   z$_TelnetMixin.setUp.<locals>.<lambda>c                      s   ˆ S r   r   r   r«   r   r   r   /  r   c                      s   ˆ S r   r   r   r¯   r   r   r   3  r   c                      s   ˆ S r   r   r   r°   r   r   r   4  r   )rŒ   rÀ   rU   ZTelnetTransportrW   r�   r¿   r   ZclearBufferr›   ÚtelnetClientr·   r¸   r‘   )r   ZtelnetServerr·   rÂ   r¸   r   r¼   r   r    ,  s"    

z_TelnetMixin.setUpc                 C   s   | j  |¡ d S r   )rÂ   rY   rz   r   r   r   r¦   D  s    z_TelnetMixin._testwriteNr½   r   r   r   r   rÁ   +  s   rÁ   c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )Ú_StdioMixinc                    s´   t ƒ ‰ t ‡ fdd„¡}t |¡}tj}tj}| d¡sB| d¡rN|d d… }||t	 
| j¡g}ddlm} |j|||tdd	�}ˆ  | _| _|| _|| _t td |jˆ  d
¡gƒ¡S )Nc                      s   ˆ S r   r   r   ©ÚtestTerminalr   r   r   S  r   z#_StdioMixin.setUp.<locals>.<lambda>z.pycz.pyoéÿÿÿÿr   )ÚreactorT)ÚenvZusePTYs   >>> )r�   r   r´   ÚstdioZTerminalProcessProtocolÚsysÚ
executableÚ__file__Úendswithr   ZqualrŒ   Útwisted.internetrÇ   ZspawnProcessÚ	properEnvr›   rÅ   ÚprocessClientr·   r   ZgatherResultsÚfilterr‘   r¥   )r   r±   rÐ   ZexeÚmoduleÚargsrÇ   r·   r   rÄ   r   r    I  s,    
    ÿÿz_StdioMixin.setUpc              	      sF   zˆ j  d¡ W n tjtfk
r*   Y nX ‡ fdd„}ˆ jj |¡S )NZKILLc                    s.   |   tj¡ ˆ  | jj¡ ˆ  | jjd¡ d S )Né	   )Útrapr   ZProcessTerminatedZassertIsNoneÚvalueZexitCoder'   Ústatus)Zfailurer   r   r   rÕ   {  s    z"_StdioMixin.tearDown.<locals>.trap)r·   ZsignalProcessr   ZProcessExitedAlreadyÚOSErrorrÅ   r’   Z
addErrback)r   rÕ   r   r   r   ÚtearDownt  s    z_StdioMixin.tearDownc                 C   s   | j  |¡ d S r   )r·   rY   rz   r   r   r   r¦   ‚  s    z_StdioMixin._testwriteN)rR   rS   rT   r    rÙ   r¦   r   r   r   r   rÃ   H  s   +rÃ   c                   @   sX   e Zd Ze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 )ÚRecvlineLoopbackMixinc                 C   s   |   ddddg¡S )Ns   first line
doneó   >>> first lineó
   first lineó   >>> done)r¨   r   r   r   r   Ú
testSimple‰  s     ÿz RecvlineLoopbackMixin.testSimplec                 C   s"   |   td td  d dddg¡S )NrÜ   r>   ó	   xxxx
dones   >>> first xxxxs
   first xxxxrÝ   )r¨   ÚinsertÚleftr   r   r   r   ÚtestLeftArrowŽ  s    þz#RecvlineLoopbackMixin.testLeftArrowc                 C   s*   |   td td  td  d dddg¡S )Ns
   right liner>   é   s   xx
dones   >>> right lixxs
   right lixxrÝ   )r¨   rà   rá   Úrightr   r   r   r   ÚtestRightArrow”  s    þz$RecvlineLoopbackMixin.testRightArrowc                 C   s   |   dtd  d dddg¡S )Nó   second liner>   rß   s   >>> second xxxxs   second xxxxrÝ   )r¨   Ú	backspacer   r   r   r   ÚtestBackspaceš  s    þz#RecvlineLoopbackMixin.testBackspacec                 C   s&   |   dtd  td  d dddg¡S )Ns   delete xxxxr>   ó	   line
dones   >>> delete lines   delete linerÝ   )r¨   rá   Údeleter   r   r   r   Ú
testDelete   s    þz RecvlineLoopbackMixin.testDeletec                 C   s   |   dtd  d dddg¡S )Ns	   third ineé   ó   l
dones   >>> third lines
   third linerÝ   )r¨   rá   r   r   r   r   Ú
testInsert¦  s    þz RecvlineLoopbackMixin.testInsertc                 C   s"   |   dtd  t d dddg¡S )Ns   fourth xiner>   rí   s   >>> fourth lines   fourth linerÝ   )r¨   rá   rà   r   r   r   r   ÚtestTypeover¬  s    þz"RecvlineLoopbackMixin.testTypeoverc                 C   s   |   td t d dddg¡S )Ns	   blah lines	   home
dones   >>> home lines	   home linerÝ   )r¨   rà   Úhomer   r   r   r   ÚtestHome²  s    þzRecvlineLoopbackMixin.testHomec                 C   s"   |   dtd  t d dddg¡S )Ns   end r>   ré   s   >>> end lines   end linerÝ   )r¨   rá   Úendr   r   r   r   ÚtestEnd¸  s    þzRecvlineLoopbackMixin.testEndN)rR   rS   rT   rX   rŒ   rÞ   râ   rå   rè   rë   rî   rï   rñ   ró   r   r   r   r   rÚ   †  s   rÚ   c                   @   s   e Zd ZdS )ÚRecvlineLoopbackTelnetTestsNr�   r   r   r   r   rô   ¿  s   rô   c                   @   s   e Zd ZdS )ÚRecvlineLoopbackSSHTestsNr�   r   r   r   r   rõ   Ã  s   rõ   zBTerminal requirements missing, can't run recvline tests over stdioc                   @   s   e Zd ZdS )ÚRecvlineLoopbackStdioTestsNr�   r   r   r   r   rö   Ç  s   rö   c                   @   s(   e Zd ZeZdd„ Zdd„ Zdd„ ZdS )ÚHistoricRecvlineLoopbackMixinc                 C   s   |   dt d dddddg¡S )Ns   first line
ó   
donerÛ   rÜ   rÝ   )r¨   Úupr   r   r   r   ÚtestUpArrowÏ  s    
ûþz)HistoricRecvlineLoopbackMixin.testUpArrowc                 C   s"   |   dt t d dddddg¡S )aH  
        Pressing down arrow to visit an entry that was added to the
        history by pressing the up arrow instead of return does not
        raise a L{TypeError}.

        @see: U{http://twistedmatrix.com/trac/ticket/9031}

        @return: A L{defer.Deferred} that fires when C{b"done"} is
            echoed back.
        s   first line
partial linerø   rÛ   rÜ   s   >>> partial lines   partial linerÝ   ©r¨   rù   Údownr   r   r   r   Ú$test_DownArrowToPartialLineInHistoryÛ  s    ûþzBHistoricRecvlineLoopbackMixin.test_DownArrowToPartialLineInHistoryc              
   C   s*   |   dtd  t d dddddddg¡S )	Ns   first line
second line
rã   rø   rÛ   rÜ   s   >>> second lineræ   rÝ   rû   r   r   r   r   ÚtestDownArrowò  s    ùþz+HistoricRecvlineLoopbackMixin.testDownArrowN)rR   rS   rT   rX   rŒ   rú   rý   rþ   r   r   r   r   r÷   Ì  s   r÷   c                   @   s   e Zd ZdS )Ú#HistoricRecvlineLoopbackTelnetTestsNr�   r   r   r   r   rÿ     s   rÿ   c                   @   s   e Zd ZdS )Ú HistoricRecvlineLoopbackSSHTestsNr�   r   r   r   r   r     s   r   zKTerminal requirements missing, can't run historic recvline tests over stdioc                   @   s   e Zd ZdS )Ú"HistoricRecvlineLoopbackStdioTestsNr�   r   r   r   r   r    s   r  c                   @   s   e Zd ZdZdd„ ZdS )ÚTransportSequenceTestsz5
    L{twisted.conch.recvline.TransportSequence}
    c                 C   s   |   ttj¡ dS )zh
        Initializing a L{recvline.TransportSequence} with no args
        raises an assertion.
        N)ÚassertRaisesÚAssertionErrorr   ZTransportSequencer   r   r   r   Útest_invalidSequence  s    z+TransportSequenceTests.test_invalidSequenceN)rR   rS   rT   Ú__doc__r  r   r   r   r   r    s   r  )er  ÚosrÊ   Zunittestr   Ztwisted.conchr   Ztwisted.conch.insultsr   Ztwisted.credr   rÎ   r   r   Ztwisted.internet.testingr   Ztwisted.pythonr	   r
   r   Ztwisted.python.compatr   Ztwisted.python.reflectr   Ztwisted.trial.unittestr   r   rÉ   ÚdictÚenvironrÏ   ÚpathsepÚjoinÚpathr   rU   rV   Ztwisted.conch.test.loopbackrW   r   rX   rá   rä   rù   rü   rà   rð   rê   rò   rç   r]   Ztwisted.conch.manhole_sshr^   r_   r`   ra   rb   Ztwisted.conch.sshrc   rd   re   rf   rg   rh   ÚImportErrorr²   rj   ri   r}   r|   r�   r€   ZSSHClientTransportr†   r‹   r�   rŽ   ZregisterAdapterZISessionr“   r�   r—   rª   Ztwisted.conch.testr¾   r´   ZTestProtocolr¿   r   rÀ   rÁ   rÃ   rÚ   rô   rõ   rö   r÷   rÿ   r   r  r  r   r   r   r   Ú<module>   s    
  	$
"'7>9
5
  ÿ
  ÿþ
  ÿ