Current File : //usr/lib/python2.7/site-packages/paramiko/proxy.pyo
�
=OXc@s�ddlmZddlZddlmZddlZddlmZddlZddlZddl	m
Z
ddlmZdefd��YZ
dS(	i����(tdatetimeN(tsplit(tselect(tProxyCommandFailure(tClosingContextManagertProxyCommandcBsYeZdZd�Zd�Zd�Zd�Zed��Zed��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
Cs\ddlm}m}t|�|_||jd|d|d|dd�|_d|_dS(	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����(tPopentPIPEtstdintstdouttstderrtbufsizeiN(t
subprocessRRtshlsplittcmdtprocesstNonettimeout(tselftcommand_lineRR((s2/usr/lib/python2.7/site-packages/paramiko/proxy.pyt__init__+s

cCsUy|jjj|�Wn1tk
rJ}tdj|j�|j��nXt|�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 (	RRtwritetIOErrorRtjoinRtstrerrortlen(Rtcontentte((s2/usr/lib/python2.7/site-packages/paramiko/proxy.pytsend;s
"c
CsPy�d}tj�}x�t|�|kr�d}|jdk	r}tj�|}||jkrmtj��n|j|}nt|jjggg|�\}}}|r|d|jjkr|tj	|jjj
�|t|��7}qqW|SWnQtjk
r|r|S�n1tk
rK}	tdj
|j�|	j��nXdS(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
        tiRN(ttimeRRRtsocketRRR	tostreadtfilenoRRRRR(
Rtsizetbuffertstarttselect_timeouttelapsedtrtwtxR((s2/usr/lib/python2.7/site-packages/paramiko/proxy.pytrecvLs,$	*cCstj|jjtj�dS(N(R!tkillRtpidtsignaltSIGTERM(R((s2/usr/lib/python2.7/site-packages/paramiko/proxy.pytclosemscCs|jjdk	S(N(Rt
returncodeR(R((s2/usr/lib/python2.7/site-packages/paramiko/proxy.pytclosedpscCs|jS(N(R3(R((s2/usr/lib/python2.7/site-packages/paramiko/proxy.pyt_closedtscCs
||_dS(N(R(RR((s2/usr/lib/python2.7/site-packages/paramiko/proxy.pyt
settimeoutys(t__name__t
__module__t__doc__RRR,R1tpropertyR3R4R5(((s2/usr/lib/python2.7/site-packages/paramiko/proxy.pyR s
			!	(RR!tshlexRR
R/RR Rtparamiko.ssh_exceptionRt
paramiko.utilRR(((s2/usr/lib/python2.7/site-packages/paramiko/proxy.pyt<module>s