o
    ¯bK  ã                   @   sÊ   d Z ddl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mZ ddlmZ G dd	„ d	ƒZG d
d„ dƒZee
jƒG dd„ dejƒƒZG dd„ dejejƒZG dd„ dƒZG dd„ dejƒZdS )z9
insults/SSH integration support.

@author: Jp Calderone
é    )ÚDict)Úimplementer)ÚavatarÚerrorÚ
interfaces)Úinsults)ÚfactoryÚsession)Ú
componentsc                   @   s    e Zd ZdZdd„ Zdd„ ZdS )Ú_Gluez¸
    A feeble class for making one attribute look like another.

    This should be replaced with a real class at some point, probably.
    Try not to write new code that uses it.
    c                 K   s   | j  |¡ d S ©N)Ú__dict__Úupdate)ÚselfÚkw© r   ú;/usr/lib/python3/dist-packages/twisted/conch/manhole_ssh.pyÚ__init__   s   z_Glue.__init__c                 C   s   t | jd|ƒ‚)Nzhas no attribute)ÚAttributeErrorÚname)r   r   r   r   r   Ú__getattr__    ó   z_Glue.__getattr__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r      s    r   c                   @   ó   e Zd Zdd„ ZdS )ÚTerminalSessionTransportc                    sx   |ˆ_ ˆ ˆ_|ˆ_ˆj j‰ˆj  tˆjj‡ ‡fdd„dd�¡ ‡fdd„}ˆj tˆj j|dd�¡ ˆjj 	||¡ d S )Nc                      s   ˆ j  ˆ¡S r   )ÚconnÚ	sendCloser   )r   ÚprotoSessionr   r   Ú<lambda>/   s    z3TerminalSessionTransport.__init__.<locals>.<lambda>zSSH Proto Transport)ÚwriteÚloseConnectionr   c                      s   ˆ j  ¡  d S r   )Úprotor#   r   ©r   r   r   r#   4   r   z9TerminalSessionTransport.__init__.<locals>.loseConnectionzChained Proto Transport)
r$   r   ÚchainedProtocolr	   ÚmakeConnectionr   ÚdataReceivedr"   ÚterminalProtocolÚterminalSize)r   r$   r&   r   ÚwidthÚheightr#   r   )r   r    r   r   r   %   s(   ýÿýÿz!TerminalSessionTransport.__init__N©r   r   r   r   r   r   r   r   r   $   ó    r   c                   @   sF   e Zd ZeZejZdd„ Zdd„ Z	dd„ Z
dd„ Zd	d
„ Zdd„ ZdS )ÚTerminalSessionc                 C   s   |d d… \| _ | _d S )Né   )r,   r+   )r   ÚtermÚ
windowSizeÚattrsr   r   r   ÚgetPtyM   s   zTerminalSession.getPtyc                 C   s&   |   ||  ¡ t | j¡| j| j¡ d S r   )ÚtransportFactoryÚchainedProtocolFactoryÚiconchÚ
IConchUserÚoriginalr+   r,   )r   r$   r   r   r   Ú	openShellP   s   
ûzTerminalSession.openShellc                 C   s
   t  d¡‚)NzCannot execute commands)ÚeconchÚ
ConchError)r   r$   Úcmdr   r   r   ÚexecCommandY   ó   
zTerminalSession.execCommandc                 C   ó   t dƒ‚)Nz,Unimplemented: TerminalSession.windowChanged©ÚNotImplementedError)r   ÚnewWindowSizer   r   r   ÚwindowChanged\   ó   zTerminalSession.windowChangedc                 C   r@   )Nz*Unimplemented: TerminalSession.eofReceivedrA   r%   r   r   r   ÚeofReceived`   rE   zTerminalSession.eofReceivedc                 C   ó   d S r   r   r%   r   r   r   Úclosedd   s   zTerminalSession.closedN)r   r   r   r   r5   r   ÚServerProtocolr6   r4   r:   r>   rD   rF   rH   r   r   r   r   r/   H   s    	r/   c                   @   r   )ÚTerminalUserc                 C   s*   t j | |¡ tj | ¡ tj| jd< d S )Ns   session)r
   ÚAdapterr   r   Ú	ConchUserr	   Ú
SSHSessionÚchannelLookup)r   r9   ÚavatarIdr   r   r   r   j   s   zTerminalUser.__init__Nr-   r   r   r   r   rJ   i   r.   rJ   c                   @   s8   e Zd ZeZeZeZe	j
Zdd„ Zddd„Zdd„ ZdS )	ÚTerminalRealmc                 C   sN   t  ¡ }|  ||¡}|  |¡}| j|_| j|_| tj|¡ | tj	|¡ |S r   )
r
   ÚComponentizedÚuserFactoryÚsessionFactoryr5   r6   ÚsetComponentr7   r8   ÚISession)r   rO   ÚcompÚuserÚsessr   r   r   Ú
_getAvatarw   s   
zTerminalRealm._getAvatarNc                 C   s   |d ur	|| _ d S d S r   )r5   )r   r5   r   r   r   r   „   s   
ÿzTerminalRealm.__init__c                 G   s4   |D ]}|t ju rt j|  |¡dd„ f  S qtƒ ‚)Nc                   S   rG   r   r   r   r   r   r   r!   ‹   s    z-TerminalRealm.requestAvatar.<locals>.<lambda>)r7   r8   rY   rB   )r   rO   Úmindr   Úir   r   r   ÚrequestAvatarˆ   s
   
ÿzTerminalRealm.requestAvatarr   )r   r   r   rJ   rR   r/   rS   r   r5   r   rI   r6   rY   r   r\   r   r   r   r   rP   p   s    
rP   c                   @   s>   e Zd ZU i Zeeef ed< i Zeeef ed< dd„ ZdS )ÚConchFactoryÚ
publicKeysÚprivateKeysc                 C   s
   || _ d S r   )Úportal)r   r`   r   r   r   r   “   r?   zConchFactory.__init__N)	r   r   r   r^   r   ÚbytesÚ__annotations__r_   r   r   r   r   r   r]   �   s   
 r]   N)r   Útypingr   Úzope.interfacer   Útwisted.conchr   r   r;   r   r7   Útwisted.conch.insultsr   Útwisted.conch.sshr   r	   Útwisted.pythonr
   r   r   rU   rK   r/   rL   rJ   rP   Ú
SSHFactoryr]   r   r   r   r   Ú<module>   s   $ 