CasperSecurity

Current Path : /lib/python3/dist-packages/twisted/internet/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/twisted/internet/__pycache__/utils.cpython-310.pyc

o

�b�!�@s�dZddlZddlZddlmZddlmZddlmZm	Z	ddl
mZ	ddd	�ZGd
d�de
�ZGdd
�d
e	j�Zdidddfdd�ZGdd�de	j�Zdiddfdd�ZGdd�de	j�Zdidddfdd�Zdd�Zdd�Zdd�Zgd�ZdS) z
Utility methods.
�N��wraps)�BytesIO)�defer�protocol)�failure�c	CsL|dur
ddlm}t��}||g|�R�}|�|||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*s
z_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|_dS|j|_dS�N)�deferredr�s�errReceivedIsGood�errReceived�errReceivedIsBad)rr#�errortoorrrrBs
z_BackRelay.__init__cCsJ|jdur#t��|_t||j�}|j�t�|��d|_|j�	�dSdSr")
r#rr�onProcessEndedr�errbackr�Failure�	transport�loseConnection)rr�errrrrr'Js

�z_BackRelay.errReceivedIsBadcC�|j�|�dSr"�r$�write�rrrrrr%R�z_BackRelay.errReceivedIsGoodcCr/r"r0r2rrr�outReceivedUr3z_BackRelay.outReceivedcCs>|jdur|j�|j���dS|jdur|j�|�dSdSr")r#�callbackr$�getvaluer)r*�r�reasonrrrrXs


�z_BackRelay.processEndedN)r)	rrrr rr'r%r4rrrrrr!/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!)rr9rr�<lambda>ysz"getProcessOutput.<locals>.<lambda>)r)rrrrr	r(rr9r�getProcessOutput_s�r;c@seZdZdd�Zdd�ZdS)�_ValueGettercCs
||_dSr")r#)rr#rrrr~s
z_ValueGetter.__init__cCs|j�|jj�dSr")r#r5�value�exitCoder7rrrr�sz_ValueGetter.processEndedN)rrrrrrrrrr<}sr<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�errBufr1r4r&�
stdinBytes)rr#rCrrrr�s


z_EverythingGetter.__init__cCs,|jdur|j�d|j�|j��dSdS)Nr)rCr,�writeToChild�
closeStdin)rrrr�connectionMade�s
�z _EverythingGetter.connectionMadecCsT|j��}|j��}|j}|j}|jr|j�|||jf�dS|j�|||f�dSr")	rAr6rBr=r>�signalr#r*r5)rr8�outr.�e�coderrrr�s

z_EverythingGetter.processEndedr")rrrrrFrrrrrr@�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	rCrrr�getProcessOutputAndValue�s�rKc	Cs0|D]}ztj�|�WqtyYqw|Sr")�warnings�filters�remove�
ValueError)�passthrough�addedFilters�frrr�_resetWarningFilters�s�rSc	Os�|D]\}}tj|i|��qtjdt|��}z	||i|��}Wnty:t��}td|�|d�|d��wt	|t
j�rI|�t|�|Std|�|S)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��)
rL�filterwarningsrM�len�
BaseException�sys�exc_inforS�with_traceback�
isinstancerr�addBoth)	�suppressedWarningsrR�a�kwr�kwargsrQ�resultrZrrr�runWithWarningsSuppressed�s
�
�rccst����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��g|�Ri|��Sr")rc)r_r`�rRr^rr�warningSuppressingWrapper�sz3suppressWarnings.<locals>.warningSuppressingWrapperr)rRr^rerrdr�suppressWarnings�srf)rcrfr;r?rK)Nr)r rYrL�	functoolsr�iorr
rr�twisted.pythonrrrr�ProcessProtocolr!r;r<r?r@rKrSrcrf�__all__rrrr�<module>s*
�0

�	+
Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY