o
    ^i                  
   @   s|   d Z ddlZddlZddlZddlZedZG dd dejZ	G dd dej
Zded	ed
edejddf
ddZdgZdS )a  Sample script showing how to do local port forwarding over paramiko.

This script connects to the requested SSH server and sets up local port
forwarding (the openssh -L option) from a local port through a tunneled
connection to a destination reachable from the SSH server machine.
    Nsshc                   @   s   e Zd ZdZdZdZdS )ForwardServerz#A server to use for ssh forwarding.TN)__name__
__module____qualname____doc__daemon_threadsallow_reuse_address r
   r
   U/home/ubuntu/hpml_nyu/venv/lib/python3.10/site-packages/jupyter_client/ssh/forward.pyr   "   s    r   c                   @   s   e Zd ZdZejdd ZdS )HandlerzA handle for server requests.c              
   C   sN  z| j d| j| jf| j }W n! ty2 } ztd| j| jt	|f  W Y d}~dS d}~ww |du rDtd| j| jf  dS td| j d| d| j| jf 	 t

| j|gg g \}}}| j|v r| jd}t|d	kr{n|| ||v r|d}t|d	krn| j| q\|  | j  td
 dS )zHandle a request.zdirect-tcpipz$Incoming request to %s:%d failed: %sNz9Incoming request to %s:%d was rejected by the SSH server.zConnected!  Tunnel open z -> Ti   r   zTunnel closed )ssh_transportopen_channel
chain_host
chain_portrequestgetpeername	Exceptionloggerdebugreprselectrecvlensendclose)selfchaner_w_xdatar
   r
   r   handle,   sN   

&



zHandler.handleN)r   r   r   r   tno_type_checkr#   r
   r
   r
   r   r   )   s    r   
local_portremote_hostremote_port	transportreturnc                    s.   G  fdddt }td| f|  dS )zForward an ssh tunnel.c                       s   e Zd Z ZZZdS )z!forward_tunnel.<locals>.SubHanderN)r   r   r   r   r   r   r
   r'   r(   r)   r
   r   	SubHander[   s    r,   z	127.0.0.1N)r   r   serve_forever)r&   r'   r(   r)   r,   r
   r+   r   forward_tunnelU   s   r.   )r   loggingr   socketservertypingr$   	getLoggerr   ThreadingTCPServerr   BaseRequestHandlerr   intstrAnyr.   __all__r
   r
   r
   r   <module>   s    
 ,
