HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/twisted/internet/__pycache__/utils.cpython-38.pyc
U

�b�!�@s�dZddlZddlZddlmZddlmZddlmZm	Z	ddl
mZddd	�ZGd
d�de
�ZGdd
�d
e	j�Zdidddfdd�ZGdd�de	j�Zdiddfdd�ZGdd�de	j�Zdidddfdd�Zdd�Zdd�Zdd�ZdddddgZdS)z
Utility methods.
�N��wraps)�BytesIO)�defer�protocol)�failure�c	CsJ|dkrddlm}t��}||f|��}|�|||ft|�||�|S)Nr)�reactor)�twisted.internetr	r�Deferred�spawnProcess�tuple)	r�
executable�args�env�pathr	�	protoArgs�d�prr�8/usr/lib/python3/dist-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|���||_dS)Nzgot stderr: )�IOError�__init__�processEnded)�self�textrrrrr*sz_UnexpectedErrorOutput.__init__N)�__name__�
__module__�__qualname__�__doc__rrrrrrs
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#�errortoorrrrBs

z_BackRelay.__init__cCsF|jdk	rBt��|_t||j�}|j�t�|��d|_|j�	�dSr")
r#rr�onProcessEndedr�errbackr�Failure�	transport�loseConnection)rr�errrrrr'Js

z_BackRelay.errReceivedIsBadcCs|j�|�dSr"�r$�write�rrrrrr%Rsz_BackRelay.errReceivedIsGoodcCs|j�|�dSr"r/r1rrr�outReceivedUsz_BackRelay.outReceivedcCs8|jdk	r|j�|j���n|jdk	r4|j�|�dSr")r#�callbackr$�getvaluer)r*�r�reasonrrrrXs

z_BackRelay.processEndedN)r)	rrrr rr'r%r2rrrrrr!/s
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!)rr7rr�<lambda>y�z"getProcessOutput.<locals>.<lambda>)r)rrrrr	r(rr7r�getProcessOutput_s
�r:c@seZdZdd�Zdd�ZdS)�_ValueGettercCs
||_dSr")r#)rr#rrrr~sz_ValueGetter.__init__cCs|j�|jj�dSr")r#r3�value�exitCoder5rrrr�sz_ValueGetter.processEndedN)rrrrrrrrrr;}sr;cCstt|||||�S)z7Spawn a process and return its exit code as a Deferred.)rr;)rrrrr	rrr�getProcessValue�sr>c@s&eZdZddd�Zdd�Zdd�ZdS)	�_EverythingGetterNcCs4||_t�|_t�|_|jj|_|jj|_||_dSr")r#r�outBuf�errBufr0r2r&�
stdinBytes)rr#rBrrrr�s

z_EverythingGetter.__init__cCs(|jdk	r$|j�d|j�|j��dS)Nr)rBr,�writeToChild�
closeStdin)rrrr�connectionMade�s
z _EverythingGetter.connectionMadecCsR|j��}|j��}|j}|j}|jr<|j�|||jf�n|j�|||f�dSr")	r@r4rAr<r=�signalr#r*r3)rr6�outr.�e�coderrrr�s

z_EverythingGetter.processEnded)N)rrrrrErrrrrr?�s
r?c	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)rr?)rrrrr	rBrrr�getProcessOutputAndValue�s�rJc	Cs4|D]*}ztj�|�Wqtk
r,YqXq|Sr")�warnings�filters�remove�
ValueError)Zpassthrough�addedFilters�frrr�_resetWarningFilters�srQc	Os�|D]\}}tj||�qtjdt|��}z|||�}Wn8tk
rrt��}td|�|d�|d��Yn*Xt	|t
j�r�|�t|�n
td|�|SdS)a}
    Run the function I{f}, but with some warnings suppressed.

    This calls L{warnings.filterwarnings} to add warning filters before
    invoking I{f}. If I{f} returns a L{Deferred} then the added filters are
    removed once the deferred fires. Otherwise they are removed immediately.

    Note that the list of warning filters is a process-wide resource, so
    calling this function will affect all threads.

    @param suppressedWarnings:
        A list of arguments to pass to L{warnings.filterwarnings}, a sequence
        of (args, kwargs) 2-tuples.

    @param f: A callable, which may return a L{Deferred}.

    @param a: Positional arguments passed to I{f}

    @param kw: Keyword arguments passed to I{f}

    @return: The result of C{f(*a, **kw)}

    @seealso: L{twisted.python.util.runWithWarningsSuppressed}
        functions similarly, but doesn't handled L{Deferred}s.
    N��)
rK�filterwarningsrL�len�
BaseException�sys�exc_inforQ�with_traceback�
isinstancerr�addBoth)	�suppressedWarningsrP�a�kwr�kwargsrO�resultrXrrr�runWithWarningsSuppressed�s

racst����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|�|�Sr")ra)r]r^�rPr\rr�warningSuppressingWrapper�sz3suppressWarnings.<locals>.warningSuppressingWrapperr)rPr\rcrrbr�suppressWarnings�srd)Nr)r rWrK�	functoolsr�iorr
rr�twisted.pythonrrrr�ProcessProtocolr!r:r;r>r?rJrQrard�__all__rrrr�<module>s<�
0�
	+�