U
vf(
@ s d dl Z d dlZd dlZd dlmZ d dlZd dlZd\ZZzd dlZW n& ek
rn Z ze ZW 5 dZ [ X Y nX d dl
mZ d dlm
Z
G dd de
ZdS ) N)select)NN)ProxyCommandFailure)ClosingContextManagerc @ sP e Zd ZdZdd Zdd Zdd Zdd Zed
d Z edd
Z
dd ZdS )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 C s@ t dkrtt|| _t j| jt jt jt jdd| _d| _dS )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 )stdinstdoutstderrbufsize)
subprocesssubprocess_import_errorshlexsplitcmdPopenPIPEprocesstimeout)selfZcommand_line r ?/opt/alt/python38/lib/python3.8/site-packages/paramiko/proxy.py__init__3 s zProxyCommand.__init__c
C sR z| j j| W n6 tk
rH } ztd| j|jW 5 d}~X Y nX 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 writeIOErrorr joinr strerrorlen)r contenter r r sendG s
&zProxyCommand.sendc
C s zd}t }t||k rd}| jdk rPt | }|| jkrFt | j| }t| jjgg g |\}}}|r|d | jjkr|t| jj |t| 7 }q|W S tjk
r |r| Y S Y n8 t
k
r } ztd| j
| jW 5 d} ~ X Y nX dS )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
Nr r )timer r socketr r r osreadfilenor r r r r )
r sizebufferstartZselect_timeoutelapsedrwxr r r r recvX s.
zProxyCommand.recvc C s t | jjtj d S N)r# killr pidsignalSIGTERMr r r r closey s zProxyCommand.closec C s | j jd k S r. )r
returncoder3 r r r closed| s zProxyCommand.closedc C s | j S r. )r6 r3 r r r _closed s zProxyCommand._closedc C s
|| _ d S r. )r )r r r r r
settimeout s zProxyCommand.settimeoutN)__name__
__module____qualname____doc__r r r- r4 propertyr6 r7 r8 r r r r r ' s !
r )r# r r1 r r" r! r
r ImportErrorr Zparamiko.ssh_exceptionr Z
paramiko.utilr r r r r r