
    7g(                         d dl Z d dlZd dlZd dlmZ d dlZd dlZd\  ZZ	 d dlZn# e$ rZ	e	ZY dZ	[	ndZ	[	ww xY wd dl
mZ d dlmZ  G d de          ZdS )    N)select)NN)ProxyCommandFailure)ClosingContextManagerc                   \    e Zd ZdZd Zd Zd Zd Zed             Z	ed             Z
d Zd	S )
ProxyCommanda  
    Wraps a subprocess running ProxyCommand-driven programs.

    This class implements a the socket-like interface needed by the
    `.Transport` and `.Packetizer` classes. Using this class instead of a
    regular socket makes it possible to talk with a Popen'd command that will
    proxy traffic between the client and a server hosted in another machine.

    Instances of this class may be used as context managers.
    c                     t           t          t          j        |          | _        t          j        | j        t           j        t           j        t           j        d          | _        d| _        dS )a  
        Create a new CommandProxy instance. The instance created by this
        class can be passed as an argument to the `.Transport` class.

        :param str command_line:
            the command that should be executed and used as the proxy.
        Nr   )stdinstdoutstderrbufsize)	
subprocesssubprocess_import_errorshlexsplitcmdPopenPIPEprocesstimeout)selfcommand_lines     H/var/www/html/syslog/venv/lib/python3.11/site-packages/paramiko/proxy.py__init__zProxyCommand.__init__3   s^     ));|,,!'H/??
 
 
     c                     	 | j         j                            |           n?# t          $ r2}t	          d                    | j                  |j                  d}~ww xY wt          |          S )z
        Write the content received from the SSH client to the standard
        input of the forked command.

        :param str content: string to be sent to the forked command
         N)	r   r	   writeIOErrorr   joinr   strerrorlen)r   contentes      r   sendzProxyCommand.sendG   sw    	FL$$W---- 	F 	F 	F
 &chhtx&8&8!*EEE	F 7||s   " 
A-AAc                    	 d}t          j                     }t          |          |k     rd}| j        >t          j                     |z
  }|| j        k    rt          j                    | j        |z
  }t	          | j        j        gg g |          \  }}}|rZ|d         | j        j        k    rD|t          j        | j        j        	                                |t          |          z
            z  }t          |          |k     |S # t          j        $ r |r|cY S  t          $ r2}	t          d                    | j                  |	j                  d}	~	ww xY w)z
        Read from the standard output of the forked program.

        :param int size: how many chars should be read

        :return: the string of bytes read, which may be shorter than requested
        r   Nr   r   )timer!   r   socketr   r   r
   osreadfilenor   r   r   r   r    )
r   sizebufferstartselect_timeoutelapsedrwxr#   s
             r   recvzProxyCommand.recvX   sg   	FFIKKEf++$$!%<+"ikkE1G$,..$n...%)\G%;N $,"5!6BOO1a 1!444bg+2244dS[[6H  F f++$$ M~ 	 	 	  	F 	F 	F%chhtx&8&8!*EEE	Fs   D D E
E"-EEc                 X    t          j        | j        j        t          j                   d S N)r(   killr   pidsignalSIGTERMr   s    r   closezProxyCommand.closey   s!    
 &.11111r   c                     | j         j        d uS r5   )r   
returncoder:   s    r   closedzProxyCommand.closed|   s    |&d22r   c                     | j         S r5   )r>   r:   s    r   _closedzProxyCommand._closed   s     {r   c                     || _         d S r5   )r   )r   r   s     r   
settimeoutzProxyCommand.settimeout   s    r   N)__name__
__module____qualname____doc__r   r$   r3   r;   propertyr>   r@   rB    r   r   r   r   '   s        	 	  (  "F F FB2 2 2 3 3 X3   X    r   r   )r(   r   r8   r   r'   r&   r   r   ImportErrorr#   paramiko.ssh_exceptionr   paramiko.utilr   r   rH   r   r   <module>rL      s   ( 
			           '1 #
#         7 6 6 6 6 6 / / / / / /_ _ _ _ _( _ _ _ _ _s   & 727