
    a$                         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d dl
mZ d dlmZ  G d de      Zy# e$ rZ	e	ZY dZ	[	$dZ	[	ww xY w)    N)select)NN)ProxyCommandFailure)ClosingContextManagerc                   N    e Zd ZdZd Zd Zd Zd Zed        Z	ed        Z
d Zy	)
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| _        y)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     .lib/python3.12/site-packages/paramiko/proxy.py__init__zProxyCommand.__init__3   sZ     ));;|,!''HH//????
     c                     	 | j                   j                  j                  |       t        |      S # t        $ r4}t	        dj                  | j                        |j                        d}~ww xY w)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   s`    	FLL$$W- 7|  	F
 &chhtxx&8!**EE	Fs   %2 	A//A**A/c                    	 d}t        j                          }t        |      |k  rd}| j                  It        j                          |z
  }|| j                  k\  rt        j                         | j                  |z
  }t	        | j
                  j                  gg g |      \  }}}|rc|d   | j
                  j                  k(  rG|t        j                  | j
                  j                  j                         |t        |      z
        z  }t        |      |k  r|S # t        j                  $ r r|cY S  t        $ r4}	t        dj                  | 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   s7   	FFIIKEf+$!%<<+"iikE1G$,,.$nn..%)\\G%;N $,,"5"5!6BO1a1!4!44bgg++224dS[6H F f+$ M~~ 	 	F%chhtxx&8!**EE	Fs$   DD D E03	E0</E++E0c                 t    t        j                  | j                  j                  t        j
                         y N)r(   killr   pidsignalSIGTERMr   s    r   closezProxyCommand.closey   s    
  &..1r   c                 2    | 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                     || _         y 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   '   sJ    	("FB2 3 3  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 /_( _    s   = AA		A