U
    ¸~HjK  ã                   @   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   ú=/tmp/pip-unpacked-wheel-ewod1tgb/twisted/conch/manhole_ssh.pyÚ__init__   s    z_Glue.__init__c                 C   s   t | jd|ƒ‚d S )Nzhas no attribute)ÚAttributeErrorÚname)r   r   r   r   r   Ú__getattr__    s    z_Glue.__getattr__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r      s   r   c                   @   s   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   )ÚconnZ	sendCloser   )r   ÚprotoSessionr   r   Ú<lambda>/   ó    z3TerminalSessionTransport.__init__.<locals>.<lambda>zSSH Proto Transport)ÚwriteÚloseConnectionr   c                      s   ˆ j  ¡  d S r   )Úprotor!   r   ©r   r   r   r!   4   s    z9TerminalSessionTransport.__init__.<locals>.loseConnectionzChained Proto Transport)
r"   r   ÚchainedProtocolr	   ZmakeConnectionr   ZdataReceivedr    ZterminalProtocolZ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   $   s   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   ZtermZ
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¡‚d S )NzCannot execute commands)ÚeconchZ
ConchError)r   r"   Úcmdr   r   r   ÚexecCommandY   s    zTerminalSession.execCommandc                 C   s   t dƒ‚d S )Nz,Unimplemented: TerminalSession.windowChanged©ÚNotImplementedError)r   ZnewWindowSizer   r   r   ÚwindowChanged\   s    zTerminalSession.windowChangedc                 C   s   t dƒ‚d S )Nz*Unimplemented: TerminalSession.eofReceivedr5   r#   r   r   r   ÚeofReceived`   s    zTerminalSession.eofReceivedc                 C   s   d S r   r   r#   r   r   r   Úclosedd   s    zTerminalSession.closedN)r   r   r   r   r,   r   ÚServerProtocolr-   r+   r1   r4   r7   r8   r9   r   r   r   r   r(   H   s   	r(   c                   @   s   e Zd Zdd„ ZdS )ÚTerminalUserc                 C   s*   t j | |¡ tj | ¡ tj| jd< d S )Ns   session)r
   ÚAdapterr   r   Ú	ConchUserr	   Z
SSHSessionZchannelLookup)r   r0   ÚavatarIdr   r   r   r   j   s    zTerminalUser.__init__Nr'   r   r   r   r   r;   i   s   r;   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
   ZComponentizedÚuserFactoryÚsessionFactoryr,   r-   ZsetComponentr.   r/   ÚISession)r   r>   ÚcompÚuserÚsessr   r   r   Ú
_getAvatarw   s    
zTerminalRealm._getAvatarNc                 C   s   |d k	r|| _ d S r   )r,   )r   r,   r   r   r   r   „   s    zTerminalRealm.__init__c                 G   s8   |D ](}|t jkrt j|  |¡dd„ f  S qtƒ ‚d S )Nc                   S   s   d S r   r   r   r   r   r   r   ‹   r   z-TerminalRealm.requestAvatar.<locals>.<lambda>)r.   r/   rF   r6   )r   r>   Zmindr   Úir   r   r   ÚrequestAvatarˆ   s    
zTerminalRealm.requestAvatar)N)r   r   r   r;   r@   r(   rA   r   r,   r   r:   r-   rF   r   rH   r   r   r   r   r?   p   s   
r?   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   rL   r   r   r   r   “   s    zConchFactory.__init__N)	r   r   r   rJ   r   ÚbytesÚ__annotations__rK   r   r   r   r   r   rI   �   s   
rI   N)r   Útypingr   Zzope.interfacer   Ztwisted.conchr   r   r2   r   r.   Ztwisted.conch.insultsr   Ztwisted.conch.sshr   r	   Ztwisted.pythonr
   r   r   rB   r<   r(   r=   r;   r?   Z
SSHFactoryrI   r   r   r   r   Ú<module>   s   $ 