
    ^h                         S r SSKrSSKrSSKr\R                  " S5      r " S S\R                  5      r " S S\R                  5      r	S r
S	/rg)
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                       \ rS rSrSrSrSrg)ForwardServer"   T N)__name__
__module____qualname____firstlineno__daemon_threadsallow_reuse_address__static_attributes__r       I/home/james-whalen/.local/lib/python3.13/site-packages/zmq/ssh/forward.pyr   r   "   s    Nr   r   c                       \ rS rSrS rSrg)Handler'   c           	      &    U R                   R                  SU R                  U R                  4U R                  R                  5       5      nUc,  [        R                  SU R                  U R                  5        g [        R                  SU R                  R                  5       < SUR                  5       < SU R                  U R                  4< 35         [        R                  " U R                  U// / 5      u  p4nU R                  U;   a<  U R                  R                  S5      n[        U5      S:X  a  OTUR                  U5        X;   a<  UR                  S5      n[        U5      S:X  a  OU R                  R                  U5        M  UR                  5         U R                  R                  5         [        R                  S5        g ! [         a6  n[        R                  SU R                  U R                  U5         S nAg S nAff = f)	Nzdirect-tcpipz$Incoming request to %s:%d failed: %rz9Incoming request to %s:%d was rejected by the SSH server.zConnected!  Tunnel open z -> i   r   zTunnel closed )ssh_transportopen_channel
chain_host
chain_portrequestgetpeername	Exceptionloggerdebugselectrecvlensendclose)selfchanerwxdatas          r   handleHandler.handle(   s   	%%22$//2((*D <LLK
 &t||'?'?'A&DDIYIYI[H^^bdhdsdsuy  vE  vE  dF  cI  J	
 mmT\\4$8"bAGA!||q ||((.t9>		$yyyt9>!!$'  	

%&C  	LL6	 	s   AG 
H,HHr   N)r   r	   r
   r   r*   r   r   r   r   r   r   '   s    ('r   r   c                 j   ^^^  " UUU4S jS[         5      n[        SU 4U5      R                  5         g )Nc                   (   > \ rS rSr Y r Yr YrSrg)!forward_tunnel.<locals>.SubHanderW   r   N)r   r	   r
   r   r   r   r   r   )remote_hostremote_port	transports   r   	SubHanderr.   W   s     
 
!r   r3   z	127.0.0.1)r   r   serve_forever)
local_portr0   r1   r2   r3   s    ``` r   forward_tunnelr6   S   s.    " "G "
 ;
+Y7EEGr   r6   )__doc__loggingr   socketserver	getLoggerr   ThreadingTCPServerr   BaseRequestHandlerr   r6   __all__r   r   r   <module>r>      sZ   &   			5	!L33 
)'l-- )'X	H 
r   