Ë
    ojê!  ã                   ó8  — d Z ddlZddlZddlmZ ddlmZ ddlmZm	Z	 ddl
mZ 	 dd„Z G d	„ d
e«      Z G d„ de	j                  «      Zdi dddfd„Z G d„ de	j                  «      Zdi ddfd„Z G d„ de	j                  «      Zdi dddfd„Zd„ Zd„ Zd„ Zg d¢Zy)z
Utility methods.
é    N©Úwraps)ÚBytesIO)ÚdeferÚprotocol)Úfailure© c                 ó”   — |€ddl m} t        j                  «       } | |g|¢­Ž }|j	                  |||ft        |«      z   ||«       |S )Nr   )Úreactor)Útwisted.internetr   r   ÚDeferredÚspawnProcessÚtuple)	r   Ú
executableÚargsÚenvÚpathr   Ú	protoArgsÚdÚps	            ú8/usr/lib/python3/dist-packages/twisted/internet/utils.pyÚ_callProtocolWithDeferredr      sM   € ð €Ý,ä�‰Ó€AÙ�Ð�YÒ€AØ×Ñ˜˜J¨¨¼¸d»Ñ(CÀSÈ$ÔOØ€Hó    c                   ó   — e Zd ZdZd„ Zy)Ú_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).
    c                 óD   — t         j                  | d|›�«       || _        y )Nzgot stderr: )ÚIOErrorÚ__init__ÚprocessEnded)ÚselfÚtextr   s      r   r   z_UnexpectedErrorOutput.__init__*   s!   € Ü×Ñ˜ ¨d¨XÐ6Ô7Ø(ˆÕr   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r	   r   r   r   r      s   „ ñó)r   r   c                   ó0   — e Zd ZdZdd„Zd„ Zd„ Zd„ Zd„ Zy)	Ú
_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.
    c                 óz   — || _         t        «       | _        |r| j                  | _        y | j
                  | _        y ©N)Údeferredr   ÚsÚerrReceivedIsGoodÚerrReceivedÚerrReceivedIsBad)r    r*   Úerrortoos      r   r   z_BackRelay.__init__B   s1   € Ø ˆŒÜ“ˆŒÙØ#×5Ñ5ˆDÕà#×4Ñ4ˆDÕr   c                 ó  — | j                   �t        j                  «       | _        t	        || j                  «      }| j                   j                  t        j                  |«      «       d | _         | j                  j                  «        y y r)   )
r*   r   r   ÚonProcessEndedr   Úerrbackr   ÚFailureÚ	transportÚloseConnection)r    r!   Úerrs      r   r.   z_BackRelay.errReceivedIsBadJ   sd   € Ø�=‰=Ð$Ü"'§.¡.Ó"2ˆDÔÜ(¨¨t×/BÑ/BÓCˆCØ�M‰M×!Ñ!¤'§/¡/°#Ó"6Ô7Ø ˆDŒMØ�N‰N×)Ñ)Õ+ð %r   c                 ó:   — | j                   j                  |«       y r)   ©r+   Úwrite©r    r!   s     r   r,   z_BackRelay.errReceivedIsGoodR   ó   € Ø�‰�‰�TÕr   c                 ó:   — | j                   j                  |«       y r)   r8   r:   s     r   ÚoutReceivedz_BackRelay.outReceivedU   r;   r   c                 óÔ   — | j                   �4| j                   j                  | j                  j                  «       «       y | j                  �| j                  j                  |«       y y r)   )r*   Úcallbackr+   Úgetvaluer1   r2   ©r    Úreasons     r   r   z_BackRelay.processEndedX   sN   € Ø�=‰=Ð$Ø�M‰M×"Ñ" 4§6¡6§?¡?Ó#4Õ5Ø× Ñ Ð,Ø×Ñ×'Ñ'¨Õ/ð -r   N)r   )	r"   r#   r$   r%   r   r.   r,   r=   r   r	   r   r   r'   r'   /   s    „ ñó$5ò,òòó0r   r'   c                 ó*   ‡— t        ˆfd„| ||||«      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.
    c                 ó   •— t        | ‰¬«      S )N)r/   )r'   )r   r/   s    €r   ú<lambda>z"getProcessOutput.<locals>.<lambda>y   s   ø€ ”*˜Q¨Ô2€ r   )r   )r   r   r   r   r   r/   s        `r   ÚgetProcessOutputrF   _   s    ø€ ô2 %Û2°JÀÀcÈ4ÐQXóð r   c                   ó   — e Zd Zd„ Zd„ Zy)Ú_ValueGetterc                 ó   — || _         y r)   )r*   )r    r*   s     r   r   z_ValueGetter.__init__~   s	   € Ø ˆ�r   c                 ób   — | j                   j                  |j                  j                  «       y r)   )r*   r?   ÚvalueÚexitCoderA   s     r   r   z_ValueGetter.processEnded�   s   € Ø�‰×Ñ˜vŸ|™|×4Ñ4Õ5r   N)r"   r#   r$   r   r   r	   r   r   rH   rH   }   s   „ ò!ó6r   rH   c                 ó*   — t        t        | ||||«      S )z7Spawn a process and return its exit code as a Deferred.)r   rH   )r   r   r   r   r   s        r   ÚgetProcessValuerN   …   s   € ä$¤\°:¸tÀSÈ$ÐPWÓXÐXr   c                   ó    — e Zd Zdd„Zd„ Zd„ Zy)Ú_EverythingGetterNc                 óÈ   — || _         t        «       | _        t        «       | _        | j                  j                  | _        | j                  j                  | _        || _        y r)   )r*   r   ÚoutBufÚerrBufr9   r=   r-   Ú
stdinBytes)r    r*   rT   s      r   r   z_EverythingGetter.__init__‹   sF   € Ø ˆŒÜ“iˆŒÜ“iˆŒØŸ;™;×,Ñ,ˆÔØŸ;™;×,Ñ,ˆÔØ$ˆ�r   c                 óž   — | j                   �A| j                  j                  d| j                   «       | j                  j                  «        y y )Nr   )rT   r4   ÚwriteToChildÚ
closeStdin)r    s    r   ÚconnectionMadez _EverythingGetter.connectionMade“   s;   € Ø�?‰?Ð&Ø�N‰N×'Ñ'¨¨4¯?©?Ô;ð �N‰N×%Ñ%Õ'ð	 'r   c                 óB  — | j                   j                  «       }| j                  j                  «       }|j                  }|j                  }|j
                  r)| j                  j                  |||j
                  f«       y | j                  j                  |||f«       y r)   )	rR   r@   rS   rK   rL   Úsignalr*   r2   r?   )r    rB   Úoutr6   ÚeÚcodes         r   r   z_EverythingGetter.processEndedš   su   € Ø�k‰k×"Ñ"Ó$ˆØ�k‰k×"Ñ"Ó$ˆØ�L‰LˆØ�z‰zˆØ�8Š8Ø�M‰M×!Ñ! 3¨¨Q¯X©XÐ"6Õ7à�M‰M×"Ñ" C¨¨dÐ#3Õ4r   r)   )r"   r#   r$   r   rX   r   r	   r   r   rP   rP   Š   s   „ ó%ò(ó5r   rP   c           	      ó0   — t        t        | |||||f¬«      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   )r   rP   )r   r   r   r   r   rT   s         r   ÚgetProcessOutputAndValuer_   ¥   s(   € ô %ÜØØØØØØ�-ôð r   c                 ór   — |D ]"  }	 t         j                  j                  |«       Œ$ | S # t        $ r Y Œ2w xY wr)   )ÚwarningsÚfiltersÚremoveÚ
ValueError)ÚpassthroughÚaddedFiltersÚfs      r   Ú_resetWarningFiltersrh   ¸   sF   € Øò ˆð	Ü×Ñ×#Ñ# AÕ&ðð
 Ðøô ò 	Ùð	ús   ‡*ª	6µ6c                 ó’  — | D ]  \  }}t        j                  |i |¤Ž Œ t         j                  dt        | «       }	  ||i |¤Ž}t	        |t
        j                  «      r|j                  t        |«       |S t        d|«       |S # t        $ r8 t        j                  «       }t        d|«       |d   j                  |d   «      ‚w xY w)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é   é   )ra   Úfilterwarningsrb   ÚlenÚ
isinstancer   r   ÚaddBothrh   ÚBaseExceptionÚsysÚexc_infoÚwith_traceback)	ÚsuppressedWarningsrg   ÚaÚkwr   Úkwargsrf   Úresultrr   s	            r   ÚrunWithWarningsSuppressedry   Á   sË   € ð4 +ò 1‰ˆˆfÜ×Ñ Ð0¨Ó0ð1ä×#Ñ#Ð$=¤cÐ*<Ó&=Ð>€LðÙ�A�˜‘ˆô �fœeŸn™nÔ-Ø�N‰NÔ/°Ô>ð ˆô !  |Ô4Øˆøô ò 6Ü—<‘<“>ˆÜ˜T <Ô0Ø�q‰k×(Ñ(¨°!©Ó5Ð5ð6ús   ½B ÂACc                 ó2   ‡ ‡— t        ‰ «      ˆ ˆfd„«       }|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.
    c                  ó$   •— t        ‰‰g| ¢­i |¤ŽS r)   )ry   )ru   rv   rg   rt   s     €€r   ÚwarningSuppressingWrapperz3suppressWarnings.<locals>.warningSuppressingWrapperó   s   ø€ ä(Ð);¸QÐIÀÒIÀbÑIÐIr   r   )rg   rt   r|   s   `` r   ÚsuppressWarningsr}   ì   s%   ù€ ô ˆ1ƒXôJó ðJð %Ð$r   )ry   r}   rF   rN   r_   )Nr	   )r%   rq   ra   Ú	functoolsr   Úior   r   r   r   Útwisted.pythonr   r   r   r   ÚProcessProtocolr'   rF   rH   rN   rP   r_   rh   ry   r}   Ú__all__r	   r   r   ú<module>rƒ      sº   ðñ
ó
 Û Ý Ý ç ,Ý "ð DFó	ô)˜Wô )ô -0�×)Ñ)ô -0ð` ')¨b°tÀTÐTUó ô<6�8×+Ñ+ô 6ð &(¨R°dÀDó Yô
5˜×0Ñ0ô 5ð8 ˜R d°DÀTóò&ò(òV%ò�r   