HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/self/root/lib/python3/dist-packages/landscape/lib/__pycache__/twisted_util.cpython-38.pyc
U

���c|�	@s�ddlZddlmZmZddlmZddlmZmZddl	m
Z
ddlmZddl
mZmZddlmZGd	d
�d
e�Zddd
�ZGdd�de�Zdidddddddf	dd�ZdS)�N)�DeferredList�Deferred)�ProcessProtocol)�Process�
ProcessReader)�reactor)�Failure)�
itervalues�
networkString)�
encode_valuesc@seZdZdZdS)�SignalErrorz3An error if the process was terminated by a signal.N)�__name__�
__module__�__qualname__�__doc__�rr�</usr/lib/python3/dist-packages/landscape/lib/twisted_util.pyr
srFcCs.t|d|d�}|�dd��|�dd��|S)N�)ZfireOnOneErrbackZ
consumeErrorscSsdd�|D�S)NcSsg|]}|d�qS)rr)�.0�xrrr�
<listcomp>sz4gather_results.<locals>.<lambda>.<locals>.<listcomp>r)�rrrr�<lambda>�z gather_results.<locals>.<lambda>cSs|jjS�N)�valueZ
subFailure)�frrrrr)rZaddCallbackZ
addErrback)Z	deferredsZconsume_errors�drrr�gather_resultss�rc@s2eZdZdZddd�Zdd�Zdd�Zd	d
�ZdS)�AllOutputProcessProtocolz<A process protocol for getting stdout, stderr and exit code.NcCs:||_t��|_t��|_|jj|_||_||_d|_	dS�Nr)
�deferred�io�BytesIO�outBuf�errBuf�writeZerrReceived�stdin�
line_received�
_partial_line)�selfr!r'r(rrr�__init__s


z!AllOutputProcessProtocol.__init__cCs*|jdk	r&|j�t|j��|j��dSr)r'Z	transportr&r
Z
closeStdin)r*rrr�connectionMade%s
z'AllOutputProcessProtocol.connectionMadecCsX|j�|�|jdkrdS|�d�}|j|d|d<|��|_|D]}|�|�qDdS)N�
r)r$r&r(�splitr)�pop)r*�data�lines�linerrr�outReceived*s


z$AllOutputProcessProtocol.outReceivedcCst|jr|�|j�d|_|j��}|j��}|j}|j}|jr^tt	|||j��}|j
�|�n|j
�|||f�dSr )
r)r(r$�getvaluer%rZexitCode�signalrrr!Zerrback�callback)r*�reason�out�err�e�codeZfailurerrr�processEnded:s

z%AllOutputProcessProtocol.processEnded)NN)r
rrrr+r,r3r<rrrrrs

	rrTc

s`|g}
|
�|�t�}t||	|d�}t|�}tj|||
|||||d��|s\�fdd�}
|
�_|S)a�
    Spawn a process using Twisted reactor.

    Return a deferred which will be called with process stdout, stderr and exit
    code.

    @param wait_pipes: if set to False, don't wait for stdin/stdout pipes to
        close when process ends.
    @param line_received: an optional callback called with every line of
        output from the process as parameter.

    @note: compared to reactor.spawnProcess, this version does NOT require the
    executable name as first element of args.
    )r'r()�args�env�path�uid�gid�usePTYcsJ�jr<�js<t�j�D]}t|t�r,|��|��qi�_t���dS)a�A less strict version of Process.maybeCallProcessEnded.

            This behaves exactly like the original method, but in case the
            process has ended already and sent us a SIGCHLD, it doesn't wait
            for the stdin/stdout pipes to close, because the child process
            itself might have passed them to its own child processes.

            @note: Twisted 8.2 now has a processExited hook that could
                be used in place of this workaround.
            N)	Zpipes�pidr	�
isinstancerZdoReadZstopReadingr�maybeCallProcessEnded)�pipe�ZprocessrrrEhs

z,spawn_process.<locals>.maybeCallProcessEnded)�extendrrrrZspawnProcessrE)�
executabler=r>r?r@rArBZ
wait_pipesr(r'Z	list_args�resultZprotocolrErrGr�
spawn_processIs$
�
�rK)F)r"Ztwisted.internet.deferrrZtwisted.internet.protocolrZtwisted.internet.processrrZtwisted.internetrZtwisted.python.failurerZtwisted.python.compatr	r
Zlandscape.lib.encodingr�	ExceptionrrrrKrrrr�<module>s 
0
�