o
    Óó·iA	  ã                   @   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   ó
   || _ d S ©N)Úpeer)Úselfr   © r	   úcC:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\twisted/protocols/portforward.pyÚsetPeer   ó   
zProxy.setPeerc                 C   s>   | j d ur| j j ¡  d | _ d S | jrt d|› �¡ d S d S )NzUnable to connect to peer: )r   Ú	transportÚloseConnectionÚnoisyr   Úmsg)r   Úreasonr	   r	   r
   ÚconnectionLost   s   

ÿzProxy.connectionLostc                 C   s   | j j |¡ d S r   )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   r   r   )Úserver)r   r   r	   r	   r
   Ú	setServer2   r   zProxyClientFactory.setServerc                 O   s*   t jj| g|¢R i |¤Ž}| | j¡ |S r   )r   ÚClientFactoryÚbuildProtocolr   r   )r   ÚargsÚkwZprotr	   r	   r
   r   5   s   z ProxyClientFactory.buildProtocolc                 C   s   | j j ¡  d S r   )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 u rd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   B   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 r   )r(   r)   )r   r(   r)   r	   r	   r
   Ú__init__X   s   
zProxyFactory.__init__N)r   r   r   Ú__doc__r#   r   r,   r	   r	   r	   r
   r+   Q   s    r+   N)r-   r&   r   Ztwisted.pythonr   ÚProtocolr   r   r   r   r#   ÚFactoryr+   r	   r	   r	   r
   Ú<module>   s   