B
    0²ô`K	  ã               @   sv   d Z ddlmZ ddlmZ G dd„ dejƒZG dd„ deƒZG dd	„ d	ejƒZ	G d
d„ deƒZ
G dd„ dejƒZdS )z
A simple port forwarder.
é    )Úprotocol)Úlogc               @   s,   e Zd ZdZdZdd„ Zdd„ Zdd„ ZdS )	ÚProxyTNc             C   s
   || _ d S )N)Úpeer)Úselfr   © r   úL/home/dcms/DCMS/lib/python3.7/site-packages/twisted/protocols/portforward.pyÚsetPeer   s    zProxy.setPeerc             C   s8   | j d k	r| j j ¡  d | _ n| jr4t d |¡¡ d S )NzUnable to connect to peer: {})r   Ú	transportÚloseConnectionÚnoisyr   ÚmsgÚformat)r   Úreasonr   r   r   ÚconnectionLost   s
    
zProxy.connectionLostc             C   s   | j j |¡ d S )N)r   r
   Úwrite)r   Údatar   r   r   ÚdataReceived   s    zProxy.dataReceived)Ú__name__Ú
__module__Ú__qualname__r   r   r	   r   r   r   r   r   r   r      s
   r   c               @   s   e Zd Zdd„ ZdS )ÚProxyClientc             C   s@   | j  | ¡ | j | j jd¡ | j j | jd¡ | j j ¡  d S )NT)r   r	   r
   ZregisterProducerZresumeProducing)r   r   r   r   ÚconnectionMade!   s    zProxyClient.connectionMadeN)r   r   r   r   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 )ÚProxyClientFactoryc             C   s
   || _ d S )N)Úserver)r   r   r   r   r   Ú	setServer3   s    zProxyClientFactory.setServerc             O   s$   t jj| f|ž|Ž}| | j¡ |S )N)r   ÚClientFactoryÚbuildProtocolr	   r   )r   ÚargsÚkwZprotr   r   r   r   6   s    z ProxyClientFactory.buildProtocolc             C   s   | j j ¡  d S )N)r   r
   r   )r   Z	connectorr   r   r   r   ÚclientConnectionFailed;   s    z)ProxyClientFactory.clientConnectionFailedN)r   r   r   r   r   r   r   r    r   r   r   r   r   /   s   r   c               @   s   e Zd ZeZdZdd„ ZdS )ÚProxyServerNc             C   sT   | j  ¡  |  ¡ }| | ¡ | jd kr8ddlm} || _| j | jj| jj	|¡ d S )Nr   )Úreactor)
r
   ZpauseProducingÚclientProtocolFactoryr   r"   Útwisted.internetZ
connectTCPÚfactoryÚhostÚport)r   Úclientr"   r   r   r   r   D   s    


zProxyServer.connectionMade)r   r   r   r   r#   r"   r   r   r   r   r   r!   ?   s   r!   c               @   s   e Zd ZdZeZdd„ ZdS )ÚProxyFactoryz%
    Factory for port forwarder.
    c             C   s   || _ || _d S )N)r&   r'   )r   r&   r'   r   r   r   Ú__init__Z   s    zProxyFactory.__init__N)r   r   r   Ú__doc__r!   r   r*   r   r   r   r   r)   S   s   r)   N)r+   r$   r   Ztwisted.pythonr   ZProtocolr   r   r   r   r!   ZFactoryr)   r   r   r   r   Ú<module>   s   