Current File : //usr/lib/python3/dist-packages/landscape/lib/__pycache__/twisted_util.cpython-312.pyc
�

�~�e$�	���ddlZddlmZddlmZddlmZddlmZddlmZddl	m
Z
ddlmZdd	lm
Z
dd
lmZddlmZGd�d
e�Zdd�ZGd�de
�Zdidddddddf	d�Zy)�N)�reactor)�Deferred)�DeferredList)�Process)�
ProcessReader)�ProcessProtocol)�
itervalues)�
networkString)�Failure)�
encode_valuesc��eZdZdZy)�SignalErrorz3An error if the process was terminated by a signal.N)�__name__�
__module__�__qualname__�__doc__���</usr/lib/python3/dist-packages/landscape/lib/twisted_util.pyrrs��=rrFc�j�t|d|��}|jd��|jd��|S)N�)�fireOnOneErrback�
consumeErrorsc�2�|D�cgc]}|d��	c}Scc}w)Nrr)�r�xs  r�<lambda>z gather_results.<locals>.<lambda>s��1�-�a�Q�q�T�-���-s�c�.�|jjS�N)�value�
subFailure)�fs rrz gather_results.<locals>.<lambda>s��1�7�7�-�-�r)r�addCallback�
addErrback)�	deferreds�consume_errors�ds   r�gather_resultsr(s6�����$�	�A�
�M�M�-�.��L�L�-�.��Hrc�*�eZdZdZdd�Zd�Zd�Zd�Zy)�AllOutputProcessProtocolz<A process protocol for getting stdout, stderr and exit code.Nc���||_tj�|_tj�|_|jj
|_||_||_d|_	y�Nr)
�deferred�io�BytesIO�outBuf�errBuf�write�errReceived�stdin�
line_received�
_partial_line)�selfr-r4r5s    r�__init__z!AllOutputProcessProtocol.__init__"sL�� ��
��j�j�l����j�j�l����;�;�,�,�����
�*��� ��rc��|j�I|jjt|j��|jj	�yyr)r4�	transportr2r
�
closeStdin)r7s r�connectionMadez'AllOutputProcessProtocol.connectionMade+s<���:�:�!��N�N� � ��t�z�z�!:�;��N�N�%�%�'�"rc��|jj|�|j�y|jd�}|j|dz|d<|j�|_|D]}|j|��y)N�
r)r0r2r5�splitr6�pop)r7�data�lines�lines    r�outReceivedz$AllOutputProcessProtocol.outReceived0sv�������$�����%��
�
�
�5�!���%�%��a��0��a��"�Y�Y�[����	%�D����t�$�	%rc���|jr"|j|j�d|_|jj�}|jj�}|j
}|j}|jr<tt|||j��}|jj|�y|jj|||f�yr,)
r6r5r0�getvaluer1r �exitCode�signalrrr-�errback�callback)r7�reason�out�err�e�code�failures       r�processEndedz%AllOutputProcessProtocol.processEnded@s���������t�1�1�2�!$�D���k�k�"�"�$���k�k�"�"�$���L�L���z�z���8�8��k�#�s�A�H�H�=�>�G��M�M�!�!�'�*��M�M�"�"�C��d�#3�4r)NN)rrrrr8r<rDrQrrrr*r*s��F�!�(�
%� 5rr*rTc

����|g}
|
j|�t�}t||	|��}t|�}t	j
|||
|||||���|s�fd�}
|
�_|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.
    )r4r5)�args�env�path�uid�gid�usePTYc����jr]�jsQt�j�D]2}t|t�r|j�|j
��4i�_tj��y)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)	�pipes�pidr	�
isinstancer�doRead�stopReadingr�maybeCallProcessEnded)�pipe�processs �rr_z,spawn_process.<locals>.maybeCallProcessEnded�s`����}�}�W�[�[�&�w�}�}�5�'�D�!�$�
�6����
��$�$�&�	'�
!#��
��)�)�'�2r)�extendrr*rr�spawnProcessr_)�
executablerSrTrUrVrWrX�
wait_pipesr5r4�	list_args�result�protocolr_ras              @r�
spawn_processriOs����6��I�
���T��
�Z�F�'���#��H�
��
�C��"�"���
��
����	�G��	3�()>��%��Mr)F)r.�twisted.internetr�twisted.internet.deferrr�twisted.internet.processrr�twisted.internet.protocolr�twisted.python.compatr	r
�twisted.python.failurer�landscape.lib.encodingr�	Exceptionrr(r*rirrr�<module>rrsg��	�$�+�/�,�2�5�,�/�*�0�>�)�>�
�-5��-5�d
�
�	
������
�Hr