Current File : //usr/lib/python2.7/site-packages/paramiko/proxy.pyo |
�
=OXc @ s� d d l m Z d d l Z d d l m Z d d l Z d d l m Z d d l Z d d l Z d d l m
Z
d d l m Z d e f d � � YZ
d S( i����( t datetimeN( t split( t select( t ProxyCommandFailure( t ClosingContextManagert ProxyCommandc B sY e Z d Z d � Z d � Z d � Z d � Z e d � � Z e d � � Z d � Z
RS( s�
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\ d d l m } m } t | � | _ | | j d | d | d | d d �| _ d | _ d S( s
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.
i����( t Popent PIPEt stdint stdoutt stderrt bufsizei N( t
subprocessR R t shlsplitt cmdt processt Nonet timeout( t selft command_lineR R ( ( s2 /usr/lib/python2.7/site-packages/paramiko/proxy.pyt __init__+ s
c C sU y | j j j | � Wn1 t k
rJ } t d j | j � | j � � n Xt | � S( s�
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
t ( R R t writet IOErrorR t joinR t strerrort len( R t contentt e( ( s2 /usr/lib/python2.7/site-packages/paramiko/proxy.pyt send; s
"c
C sP y� d } t j � } x� t | � | k r� d } | j d k r} t j � | } | | j k rm t j � � n | j | } n t | j j g g g | � \ } } } | r | d | j j k r | t j | j j j
� | t | � � 7} q q W| SWnQ t j k
r| r| S� n1 t k
rK} t d j
| j � | j � � n Xd S( s�
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
t i R N( t timeR R R t socketR R R t ost readt filenoR R R R R (
R t sizet buffert startt select_timeoutt elapsedt rt wt xR ( ( s2 /usr/lib/python2.7/site-packages/paramiko/proxy.pyt recvL s, $ *c C s t j | j j t j � d S( N( R! t killR t pidt signalt SIGTERM( R ( ( s2 /usr/lib/python2.7/site-packages/paramiko/proxy.pyt closem s c C s | j j d k S( N( R t
returncodeR ( R ( ( s2 /usr/lib/python2.7/site-packages/paramiko/proxy.pyt closedp s c C s | j S( N( R3 ( R ( ( s2 /usr/lib/python2.7/site-packages/paramiko/proxy.pyt _closedt s c C s
| | _ d S( N( R ( R R ( ( s2 /usr/lib/python2.7/site-packages/paramiko/proxy.pyt
settimeouty s ( t __name__t
__module__t __doc__R R R, R1 t propertyR3 R4 R5 ( ( ( s2 /usr/lib/python2.7/site-packages/paramiko/proxy.pyR s
! ( R R! t shlexR R
R/ R R R t paramiko.ssh_exceptionR t
paramiko.utilR R ( ( ( s2 /usr/lib/python2.7/site-packages/paramiko/proxy.pyt <module> s