Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/twisted/internet/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/twisted/internet/__pycache__/utils.cpython-37.pyc

B

:��]� �@sdZddlmZmZddlZddlZddlmZddlm	Z	m
Z
ddlmZddl
mZddlmZd d
d�ZGdd
�d
e�ZGdd�de	j�Zd	idddfdd�ZGdd�de	j�Zd	iddfdd�ZGdd�de	j�Zd	idddfdd�Zdd�Zdd�Zdd�ZdddddgZdS)!z
Utility methods.
�)�division�absolute_importN)�wraps)�protocol�defer)�failure)�reraise)�BytesIO�c	CsJ|dkrddlm}t��}||f|��}|�|||ft|�||�|S)Nr)�reactor)�twisted.internetrr�DeferredZspawnProcess�tuple)	r�
executable�args�env�pathr�	protoArgs�d�pr
r
�I/opt/alt/python37/lib64/python3.7/site-packages/twisted/internet/utils.py�_callProtocolWithDeferredsrc@seZdZdZdd�ZdS)�_UnexpectedErrorOutputay
    Standard error data was received where it was not expected.  This is a
    subclass of L{IOError} to preserve backward compatibility with the previous
    error behavior of L{getProcessOutput}.

    @ivar processEnded: A L{Deferred} which will fire when the process which
        produced the data on stderr has ended (exited and all file descriptors
        closed).
    cCst�|d|f�||_dS)Nzgot stderr: %r)�IOError�__init__�processEnded)�self�textrr
r
rr-sz_UnexpectedErrorOutput.__init__N)�__name__�
__module__�__qualname__�__doc__rr
r
r
rr"s	rc@s:eZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�
_BackRelaya�
    Trivial protocol for communicating with a process and turning its output
    into the result of a L{Deferred}.

    @ivar deferred: A L{Deferred} which will be called back with all of stdout
        and, if C{errortoo} is true, all of stderr as well (mixed together in
        one string).  If C{errortoo} is false and any bytes are received over
        stderr, this will fire with an L{_UnexpectedErrorOutput} instance and
        the attribute will be set to L{None}.

    @ivar onProcessEnded: If C{errortoo} is false and bytes are received over
        stderr, this attribute will refer to a L{Deferred} which will be called
        back when the process ends.  This C{Deferred} is also associated with
        the L{_UnexpectedErrorOutput} which C{deferred} fires with earlier in
        this case so that users can determine when the process has actually
        ended, in addition to knowing when bytes have been received via stderr.
    rcCs(||_t�|_|r|j|_n|j|_dS)N)�deferredr	�s�errReceivedIsGood�errReceived�errReceivedIsBad)rr#�errortoor
r
rrFs

z_BackRelay.__init__cCsF|jdk	rBt��|_t||j�}|j�t�|��d|_|j�	�dS)N)
r#rr
�onProcessEndedr�errbackrZFailure�	transportZloseConnection)rr�errr
r
rr'Ns

z_BackRelay.errReceivedIsBadcCs|j�|�dS)N)r$�write)rrr
r
rr%Vsz_BackRelay.errReceivedIsGoodcCs|j�|�dS)N)r$r-)rrr
r
r�outReceivedYsz_BackRelay.outReceivedcCs8|jdk	r|j�|j���n|jdk	r4|j�|�dS)N)r#�callbackr$�getvaluer)r*)r�reasonr
r
rr\s

z_BackRelay.processEndedN)r)	rrr r!rr'r%r.rr
r
r
rr"3s
r"cst�fdd�|||||�S)a�
    Spawn a process and return its output as a deferred returning a L{bytes}.

    @param executable: The file name to run and get the output of - the
                       full path should be used.

    @param args: the command line arguments to pass to the process; a
                 sequence of strings. The first string should B{NOT} be the
                 executable's name.

    @param env: the environment variables to pass to the process; a
                dictionary of strings.

    @param path: the path to run the subprocess in - defaults to the
                 current directory.

    @param reactor: the reactor to use - defaults to the default reactor

    @param errortoo: If true, include stderr in the result.  If false, if
        stderr is received the returned L{Deferred} will errback with an
        L{IOError} instance with a C{processEnded} attribute.  The
        C{processEnded} attribute refers to a L{Deferred} which fires when the
        executed process ends.
    cst|�d�S)N)r()r")r)r(r
r�<lambda>~sz"getProcessOutput.<locals>.<lambda>)r)rrrrrr(r
)r(r�getProcessOutputdsr3c@seZdZdd�Zdd�ZdS)�_ValueGettercCs
||_dS)N)r#)rr#r
r
rr�sz_ValueGetter.__init__cCs|j�|jj�dS)N)r#r/�value�exitCode)rr1r
r
rr�sz_ValueGetter.processEndedN)rrr rrr
r
r
rr4�sr4cCstt|||||�S)z7Spawn a process and return its exit code as a Deferred.)rr4)rrrrrr
r
r�getProcessValue�sr7c@s&eZdZddd�Zdd�Zdd�ZdS)	�_EverythingGetterNcCs4||_t�|_t�|_|jj|_|jj|_||_dS)N)r#r	�outBuf�errBufr-r.r&�
stdinBytes)rr#r;r
r
rr�s

z_EverythingGetter.__init__cCs(|jdk	r$|j�d|j�|j��dS)Nr)r;r+ZwriteToChildZ
closeStdin)rr
r
r�connectionMade�s
z _EverythingGetter.connectionMadecCsR|j��}|j��}|j}|j}|jr<|j�|||jf�n|j�|||f�dS)N)	r9r0r:r5r6�signalr#r*r/)rr1�outr,�e�coder
r
rr�s

z_EverythingGetter.processEnded)N)rrr rr<rr
r
r
rr8�s
r8c	Cstt||||||fd�S)a.Spawn a process and returns a Deferred that will be called back with
    its output (from stdout and stderr) and it's exit code as (out, err, code)
    If a signal is raised, the Deferred will errback with the stdout and
    stderr up to that point, along with the signal, as (out, err, signalNum)
    )r)rr8)rrrrrr;r
r
r�getProcessOutputAndValue�srAc	Cs8x2|D]*}ytj�|�Wqtk
r.YqXqW|S)N)�warnings�filters�remove�
ValueError)Zpassthrough�addedFilters�fr
r
r�_resetWarningFilters�s

rHc	Os�x|D]\}}tj||�qWtjdt|��}y|||�}Wn0t��}td|�t|d|d�Yn*Xt|t	j
�r�|�t|�n
td|�|SdS)a%Run the function C{f}, but with some warnings suppressed.

    @param suppressedWarnings: A list of arguments to pass to filterwarnings.
                               Must be a sequence of 2-tuples (args, kwargs).
    @param f: A callable, followed by its arguments and keyword arguments
    N��)rB�filterwarningsrC�len�sys�exc_inforHr�
isinstancerr
ZaddBoth)	�suppressedWarningsrG�a�kwr�kwargsrF�resultrNr
r
r�runWithWarningsSuppressed�s

rUcst����fdd��}|S)z�
    Wrap C{f} in a callable which suppresses the indicated warnings before
    invoking C{f} and unsuppresses them afterwards.  If f returns a Deferred,
    warnings will remain suppressed until the Deferred fires.
    cst��f|�|�S)N)rU)rQrR)rGrPr
r�warningSuppressingWrapper�sz3suppressWarnings.<locals>.warningSuppressingWrapper)r)rGrPrVr
)rGrPr�suppressWarnings�srW)Nr
)r!�
__future__rrrMrB�	functoolsrrrrZtwisted.pythonrZtwisted.python.compatr�ior	rrrZProcessProtocolr"r3r4r7r8rArHrUrW�__all__r
r
r
r�<module>s,
1