o
    Òó·ib  ã                   @   sb  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@yÆ   d"ZAY nGw 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   úfC:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\twisted/conch/test/test_recvline.pyÚ<lambda>"   s    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©ó   xyzó    )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                    ó   ˆ j  | d ¡S r   ©r   r&   ©Úchr   r   r   r   7   ó    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                    r*   r   r+   r,   r   r   r   r   ]   r.   z*ArrowsTests.test_newline.<locals>.<lambda>ó   xyz
abc
123
©©r$   ó   abcó   123r   ó   có   bó   aó   
))r$   r7   r8   s   cbar   N)r   r'   r   ÚcurrentHistoryBufferr1   r   r   r   Útest_newlineX   s   

ÿzArrowsTests.test_newlinec                    s6  ‡ 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                    r*   r   r+   r,   r   r   r   r   u   r.   z1ArrowsTests.test_verticalArrows.<locals>.<lambda>r4   r5   ©r%   r%   ))r$   r7   )r8   )r8   r%   ))r$   )r7   r8   )r7   r%   )r   r6   r#   é   N)	r   r'   r   r=   r(   r   ZUP_ARROWÚrangeZ
DOWN_ARROW)r   r2   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                    r*   r   r+   r,   r   r   r   r   –   r.   z'ArrowsTests.test_home.<locals>.<lambda>ó   hello, world©rD   r%   )r%   rD   N)r   r'   r   r(   r   ÚHOMEr1   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                    r*   r   r+   r,   r   r   r   r   ¤   r.   z&ArrowsTests.test_end.<locals>.<lambda>rD   rE   N)r   r'   r   r(   r   rF   ZENDr1   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                    r*   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	BACKSPACEr0   r1   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                    r*   r   r+   r,   r   r   r   r   È   r.   z)ArrowsTests.test_delete.<locals>.<lambda>r$   r#   rI   )r    r%   r?   N)r   r'   r   r(   r   ÚDELETEr0   r1   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                    r*   r   r+   r,   r   r   r   r   å   r.   z)ArrowsTests.test_insert.<locals>.<lambda>r$   ó   A)ó   xyAr"   ó   B)ó   xyBs   AzN)r   r   r0   r'   r   r(   r1   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                    r*   r   r+   r,   r   r   r   r   ù   r.   z+ArrowsTests.test_typeover.<locals>.<lambda>r$   rM   )rN   r%   rO   )rP   r%   N)r   r   ZINSERTr0   r'   r   r(   r1   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¡ q'dS )z¡
        When L{HistoricRecvLine} receives a keystroke for an unprintable
        function key with no assigned behavior, the line buffer is unmodified.
        c                    r*   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   r2   r   r-   r   r   r   Útest_unprintableCharacters  s(   òïz&ArrowsTests.test_unprintableCharactersN)Ú__name__Ú
__module__Ú__qualname__r   r)   r3   r>   rC   rG   rH   rJ   rL   rQ   rR   rS   r   r   r   r   r      s    '#r   )Útelnet)Úhelper)ÚLoopbackRelayc                   @   ó   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)rT   rU   rV   r^   r   r   r   r   r[   )  ó    r[   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   ó<   t jj| g|¢R i |¤Ž || _|| _|| _|| _|| _d S r   )rg   Ú
SSHChannelÚ__init__r   ÚprotocolArgsÚprotocolKwArgsÚwidthÚheight©r   r   rq   rr   rs   rt   ÚaÚkwr   r   r   rp   S  ó   
zSessionChannel.__init__c                 C   sh   t  d| j| jddfd¡}| j | d|¡ | j | dd¡ | j| ji | j¤Ž| _	| | j	_
| j	 | ¡ d S )Ns   vt102r   r%   s   pty-reqs   shell)rj   ZpackRequest_pty_reqrt   rs   ÚconnZsendRequestr   rq   rr   Ú_protocolInstancer   r   )r   ÚdataZtermr   r   r   ÚchannelOpen_  s   ÿÿÿzSessionChannel.channelOpenc                 C   s   | j  t ¡ ¡ d S r   )rz   ÚconnectionLostr   ZConnectionDoner   r   r   r   Úclosedl  s   zSessionChannel.closedc                 C   ó   | j  |¡ d S r   )rz   ÚdataReceived©r   r{   r   r   r   r€   o  ó   zSessionChannel.dataReceivedN)rT   rU   rV   Únamerp   r|   r~   r€   r   r   r   r   rm   P  s    rm   c                   @   ó$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚTestConnectionc                 O   rn   r   )rh   ÚSSHConnectionrp   r   rq   rr   rs   rt   ru   r   r   r   rp   s  rx   zTestConnection.__init__c                 C   s,   t | j| j| j| j| jƒ| _|  | j¡ d S r   )rm   r   rq   rr   rs   rt   Ú_TestConnection__channelZopenChannelr   r   r   r   ÚserviceStarted  s   ûzTestConnection.serviceStartedc                 C   ó   | j  |¡S r   )r‡   r\   r�   r   r   r   r\   ‰  ó   zTestConnection.writeN)rT   rU   rV   rp   rˆ   r\   r   r   r   r   r…   r  s    
r…   c                   @   ó   e Zd Zdd„ Zdd„ ZdS )ÚTestAuthc                 O   s&   t jj| |g|¢R i |¤Ž || _d S r   )rl   ÚSSHUserAuthClientrp   Úpassword)r   ÚusernamerŽ   rv   rw   r   r   r   rp   �  s   
zTestAuth.__init__c                 C   s   t  | j¡S r   )r   ÚsucceedrŽ   r   r   r   r   ÚgetPassword‘  rŠ   zTestAuth.getPasswordN)rT   rU   rV   rp   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   rq   rr   r�   rŽ   rs   rt   )
r   r   rq   rr   r�   rŽ   rs   rt   rv   rw   r   r   r   rp   •  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   rq   rr   rs   rt   Ú_TestTransport__connectionZrequestServicerŒ   r�   rŽ   r   r   r   r   ÚconnectionSecure¬  s   ûÿzTestTransport.connectionSecurec                 C   r‰   r   )r•   r\   r�   r   r   r   r\   ¸  rŠ   zTestTransport.writeN)rT   rU   rV   rp   r”   r–   r\   r   r   r   r   r’   ”  s
    r’   c                   @   rZ   )ÚTestSessionTransportc                 C   s   | j jjj ¡ S r   )Zavatarry   rk   r   ÚserverProtocolr   r   r   r   r   ¼  r‚   z$TestSessionTransport.protocolFactoryN)rT   rU   rV   r   r   r   r   r   r—   »  r_   r—   c                   @   s   e Zd ZeZdS )ÚTestSessionN)rT   rU   rV   r—   ZtransportFactoryr   r   r   r   r™   ¿  s    r™   c                   @   ó   e Zd ZdS )ÚTestUserN©rT   rU   rV   r   r   r   r   r›   Â  ó    r›   c                   @   r„   )ÚNotifyingExpectableBufferc                 C   s   t  ¡ | _t  ¡ | _d S r   )r   ZDeferredÚonConnectionÚonDisconnectionr   r   r   r   rp   É  s   
z"NotifyingExpectableBuffer.__init__c                 C   s   t j | ¡ | j | ¡ d S r   )rX   ÚExpectableBufferÚconnectionMaderŸ   Úcallbackr   r   r   r   r¢   Í  s   z(NotifyingExpectableBuffer.connectionMadec                 C   r   r   )r    Zerrback)r   Úreasonr   r   r   r}   Ñ  r‚   z(NotifyingExpectableBuffer.connectionLostN)rT   rU   rV   rp   r¢   r}   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)rT   rU   rV   ÚWIDTHr¬   r¯   r¶   r   r   r   r   r¥   Õ  s
    r¥   c                   @   r‹   )Ú	_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 r   r   r   ©ÚinsultsServerr   r   r   ô  ó    z!_SSHMixin.setUp.<locals>.<lambda>i   )ZkeySizes   ssh-rsac                      r¹   r   r   r   ©ÚrecvlineServerr   r   r     r¼   c                      r¹   r   r   r   ©r©   r   r   r     r¼   c                      r¹   r   r   r   ©ÚinsultsClientr   r   r     r¼   r   )&Ússhr   rc   r›   ZuserFactoryZchainedProtocolFactoryra   Z'InMemoryUsernamePasswordDatabaseDontUseZaddUserr   ZPortalZregisterCheckerrb   ri   Z_getPersistentRSAKeyr
   ZFilePathÚmktempZ
publicKeysZprivateKeysr˜   ZstartFactoryr   r   ZbuildProtocolrY   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   ê  sL   ÿ

ÿ


ÿ

z_SSHMixin.setUpc                 C   r   r   )rÅ   r\   r�   r   r   r   r´     r‚   z_SSHMixin._testwriteN©rT   rU   rV   r   r´   r   r   r   r   r¸   é  s    2r¸   )Útest_telnetc                   @   rš   )ÚTestInsultsClientProtocolNrœ   r   r   r   r   rÏ   #  r�   rÏ   c                   @   rš   )ÚTestInsultsServerProtocolNrœ   r   r   r   r   rÐ   '  r�   rÐ   c                   @   r‹   )Ú_TelnetMixinc                    s¤   |   ¡ ‰t‡fdd„ƒ‰t ‡fdd„¡}t|ƒ}tƒ ‰t‡fdd„ƒ‰ t ‡ fdd„¡}t|ƒ}| |¡ | |¡ | ¡  | ¡  ˆ| _	|| _
|| _|| _ˆjS )Nc                      r¹   r   r   r   r½   r   r   r   .  r¼   z$_TelnetMixin.setUp.<locals>.<lambda>c                      r¹   r   r   r   rº   r   r   r   /  r¼   c                      r¹   r   r   r   r¿   r   r   r   3  r¼   c                      r¹   r   r   r   rÀ   r   r   r   4  r¼   )r˜   rÐ   rW   ZTelnetTransportrY   rž   rÏ   r   ZclearBufferr©   ÚtelnetClientrÇ   rÈ   rŸ   )r   ZtelnetServerrÇ   rÒ   rÈ   r   rÌ   r   r   ,  s"   

z_TelnetMixin.setUpc                 C   r   r   )rÒ   r\   r�   r   r   r   r´   D  r‚   z_TelnetMixin._testwriteNrÍ   r   r   r   r   rÑ   +  s    rÑ   c                   @   r„   )Ú_StdioMixinc                    s´   t ƒ ‰ t ‡ fdd„¡}t |¡}tj}tj}| d¡s!| d¡r'|d d… }||t	 
| j¡g}ddlm} |j|||tdd	�}ˆ  | _| _|| _|| _t td |jˆ  d
¡gƒ¡S )Nc                      r¹   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              	      sD   zˆ j  d¡ W n tjtfy   Y nw ‡ 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   r   r   )rÇ   r\   r�   r   r   r   r´   ‚  r‚   z_StdioMixin._testwriteN)rT   rU   rV   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g d¢¡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 g d¢¡S )Nrì   r@   ó	   xxxx
done)s   >>> first xxxxs
   first xxxxrí   )r¶   ÚinsertÚleftr   r   r   r   ÚtestLeftArrowŽ  ó   þz#RecvlineLoopbackMixin.testLeftArrowc                 C   s(   |   td td  td  d g d¢¡S )Ns
   right liner@   é   s   xx
done)s   >>> right lixxs
   right lixxrí   )r¶   rð   rñ   Úrightr   r   r   r   ÚtestRightArrow”  s   þz$RecvlineLoopbackMixin.testRightArrowc                 C   ó   |   dtd  d g d¢¡S )Nó   second liner@   rï   )s   >>> second xxxxs   second xxxxrí   )r¶   Ú	backspacer   r   r   r   ÚtestBackspaceš  ó   þz#RecvlineLoopbackMixin.testBackspacec                 C   s$   |   dtd  td  d g d¢¡S )Ns   delete xxxxr@   ó	   line
done)s   >>> delete lines   delete linerí   )r¶   rñ   Údeleter   r   r   r   Ú
testDelete   s   þz RecvlineLoopbackMixin.testDeletec                 C   r÷   )Ns	   third ineé   ó   l
done)s   >>> third lines
   third linerí   )r¶   rñ   r   r   r   r   Ú
testInsert¦  rû   z RecvlineLoopbackMixin.testInsertc                 C   ó    |   dtd  t d g d¢¡S )Ns   fourth xiner@   r   )s   >>> fourth lines   fourth linerí   )r¶   rñ   rð   r   r   r   r   ÚtestTypeover¬  ró   z"RecvlineLoopbackMixin.testTypeoverc                 C   s   |   td t d g d¢¡S )Ns	   blah lines	   home
done)s   >>> home lines	   home linerí   )r¶   rð   Úhomer   r   r   r   ÚtestHome²  rû   zRecvlineLoopbackMixin.testHomec                 C   r  )Ns   end r@   rü   )s   >>> end lines   end linerí   )r¶   rñ   Úendr   r   r   r   ÚtestEnd¸  ró   zRecvlineLoopbackMixin.testEndN)rT   rU   rV   r[   r˜   rî   rò   rö   rú   rþ   r  r  r  r  r   r   r   r   rê   †  s    rê   c                   @   rš   )ÚRecvlineLoopbackTelnetTestsNrœ   r   r   r   r   r  ¿  r�   r  c                   @   rš   )ÚRecvlineLoopbackSSHTestsNrœ   r   r   r   r   r	  Ã  r�   r	  zBTerminal requirements missing, can't run recvline tests over stdioc                   @   rš   )Ú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 g d¢¡S )Ns   first line
ó   
done)rë   rì   rë   rì   rí   )r¶   Úupr   r   r   r   ÚtestUpArrowÏ  s   
þz)HistoricRecvlineLoopbackMixin.testUpArrowc                 C   s   |   dt t d g d¢¡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í   N©r¶   r  Údownr   r   r   r   Ú$test_DownArrowToPartialLineInHistoryÛ  s   þzBHistoricRecvlineLoopbackMixin.test_DownArrowToPartialLineInHistoryc                 C   r  )Ns   first line
second line
rô   r  )rë   rì   ó   >>> second linerø   r  rø   rí   r  r   r   r   r   ÚtestDownArrowò  ró   z+HistoricRecvlineLoopbackMixin.testDownArrowN)rT   rU   rV   r[   r˜   r  r  r  r   r   r   r   r  Ì  s
    r  c                   @   rš   )Ú#HistoricRecvlineLoopbackTelnetTestsNrœ   r   r   r   r   r    ó    r  c                   @   rš   )Ú HistoricRecvlineLoopbackSSHTestsNrœ   r   r   r   r   r    r  r  zKTerminal requirements missing, can't run historic recvline tests over stdioc                   @   rš   )Ú"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)rT   rU   rV   Ú__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   rW   rX   Ztwisted.conch.test.loopbackrY   r   r[   rñ   rõ   r  r  rð   r  rý   r  rù   ra   Ztwisted.conch.manhole_sshrb   rc   rd   re   rf   Ztwisted.conch.sshrg   rh   ri   rj   rk   rl   ÚImportErrorrÂ   ro   rm   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ÿ
ÿþ
ÿ