§
    Ètºfê!  ã                   ó4  — 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dS )z
Utility methods.
é    N©Úwraps)ÚBytesIO)ÚdeferÚprotocol)Úfailure© c                 ó¢   — |€ddl m} t          j        ¦   «         } | |g|¢R Ž }|                     |||ft          |¦  «        z   ||¦  «         |S )Nr   )Úreactor)Útwisted.internetr   r   ÚDeferredÚspawnProcessÚtuple)	r   Ú
executableÚargsÚenvÚpathr   Ú	protoArgsÚdÚps	            úU/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/internet/utils.pyÚ_callProtocolWithDeferredr      sm   € ð €Ø,Ð,Ð,Ð,Ð,Ð,åŒÑÔ€AØˆ�Ð�YÐÐÐ€AØ×Ò˜˜J¨¨½¸d¹¼Ñ(CÀSÈ$ÑOÔOÐOØ€Hó    c                   ó   — e Zd ZdZd„ ZdS )Ú_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                 óP   — t                                | d|›�¦  «         || _        d S )Nzgot stderr: )ÚIOErrorÚ__init__ÚprocessEnded)ÚselfÚtextr   s      r   r   z_UnexpectedErrorOutput.__init__*   s/   € Ý×Ò˜Ð6¨dÐ6Ð6Ñ7Ô7Ð7Ø(ˆÔÐÐr   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r	   r   r   r   r      s-   € € € € € ðð ð)ð )ð )ð )ð )r   r   c                   ó2   — e Zd ZdZd	d„Zd„ Zd„ Zd„ Zd„ Zd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.
    r   c                 ór   — || _         t          ¦   «         | _        |r| j        | _        d S | j        | _        d S ©N)Údeferredr   ÚsÚerrReceivedIsGoodÚerrReceivedÚerrReceivedIsBad)r    r*   Úerrortoos      r   r   z_BackRelay.__init__B   s>   € Ø ˆŒÝ‘”ˆŒØð 	5Ø#Ô5ˆDÔÐÐà#Ô4ˆDÔÐÐr   c                 ó
  — | j         �{t          j        ¦   «         | _        t	          || j        ¦  «        }| j                              t          j        |¦  «        ¦  «         d | _         | j         	                    ¦   «          d S d S r)   )
r*   r   r   ÚonProcessEndedr   Úerrbackr   ÚFailureÚ	transportÚloseConnection)r    r!   Úerrs      r   r.   z_BackRelay.errReceivedIsBadJ   su   € ØŒ=Ð$Ý"'¤.Ñ"2Ô"2ˆDÔÝ(¨¨tÔ/BÑCÔCˆCØŒM×!Ò!¥'¤/°#Ñ"6Ô"6Ñ7Ô7Ð7Ø ˆDŒMØŒN×)Ò)Ñ+Ô+Ð+Ð+Ð+ð %Ð$r   c                 ó:   — | j                              |¦  «         d S r)   ©r+   Úwrite©r    r!   s     r   r,   z_BackRelay.errReceivedIsGoodR   ó   € ØŒ�Š�TÑÔÐÐÐr   c                 ó:   — | j                              |¦  «         d S r)   r8   r:   s     r   ÚoutReceivedz_BackRelay.outReceivedU   r;   r   c                 óÀ   — | j         �3| j                              | j                             ¦   «         ¦  «         d S | j        �| j                             |¦  «         d S d S r)   )r*   Úcallbackr+   Úgetvaluer1   r2   ©r    Úreasons     r   r   z_BackRelay.processEndedX   s`   € ØŒ=Ð$ØŒM×"Ò" 4¤6§?¢?Ñ#4Ô#4Ñ5Ô5Ð5Ð5Ð5ØÔ Ð,ØÔ×'Ò'¨Ñ/Ô/Ð/Ð/Ð/ð -Ð,r   N)r   )	r"   r#   r$   r%   r   r.   r,   r=   r   r	   r   r   r'   r'   /   sn   € € € € € ðð ð$5ð 5ð 5ð 5ð,ð ,ð ,ðð ð ðð ð ð0ð 0ð 0ð 0ð 0r   r'   c                 ó2   ‡— 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Ñ2Ô2€ r   )r   )r   r   r   r   r   r/   s        `r   ÚgetProcessOutputrF   _   s.   ø€ õ2 %Ø2Ð2Ð2Ð2°JÀÀcÈ4ÐQXñô ð r   c                   ó   — e Zd Zd„ Zd„ ZdS )Ú_ValueGetterc                 ó   — || _         d S r)   )r*   )r    r*   s     r   r   z_ValueGetter.__init__~   s   € Ø ˆŒˆˆr   c                 óN   — | j                              |j        j        ¦  «         d S r)   )r*   r?   ÚvalueÚexitCoderA   s     r   r   z_ValueGetter.processEnded�   s#   € ØŒ×Ò˜vœ|Ô4Ñ5Ô5Ð5Ð5Ð5r   N)r"   r#   r$   r   r   r	   r   r   rH   rH   }   s2   € € € € € ð!ð !ð !ð6ð 6ð 6ð 6ð 6r   rH   c                 ó4   — 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ÔXÐXr   c                   ó"   — e Zd Zdd„Zd„ Zd„ ZdS )Ú_EverythingGetterNc                 ó²   — || _         t          ¦   «         | _        t          ¦   «         | _        | j        j        | _        | j        j        | _        || _        d S r)   )r*   r   ÚoutBufÚerrBufr9   r=   r-   Ú
stdinBytes)r    r*   rT   s      r   r   z_EverythingGetter.__init__‹   sD   € Ø ˆŒÝ‘i”iˆŒÝ‘i”iˆŒØœ;Ô,ˆÔØœ;Ô,ˆÔØ$ˆŒˆˆr   c                 óŠ   — | j         �;| j                             d| j         ¦  «         | j                             ¦   «          d S d S )Nr   )rT   r4   ÚwriteToChildÚ
closeStdin)r    s    r   ÚconnectionMadez _EverythingGetter.connectionMade“   sH   € ØŒ?Ð&ØŒN×'Ò'¨¨4¬?Ñ;Ô;Ð;ð ŒN×%Ò%Ñ'Ô'Ð'Ð'Ð'ð	 'Ð&r   c                 ó  — | j                              ¦   «         }| j                             ¦   «         }|j        }|j        }|j        r$| j                             |||j        f¦  «         d S | j                             |||f¦  «         d S r)   )	rR   r@   rS   rK   rL   Úsignalr*   r2   r?   )r    rB   Úoutr6   ÚeÚcodes         r   r   z_EverythingGetter.processEndedš   sˆ   € ØŒk×"Ò"Ñ$Ô$ˆØŒk×"Ò"Ñ$Ô$ˆØŒLˆØŒzˆØŒ8ð 	5ØŒM×!Ò! 3¨¨Q¬XÐ"6Ñ7Ô7Ð7Ð7Ð7àŒM×"Ò" C¨¨dÐ#3Ñ4Ô4Ð4Ð4Ð4r   r)   )r"   r#   r$   r   rX   r   r	   r   r   rP   rP   Š   sF   € € € € € ð%ð %ð %ð %ð(ð (ð (ð5ð 5ð 5ð 5ð 5r   rP   c           	      ó:   — 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_   ¥   s2   € õ %ÝØØØØØØ�-ðñ ô ð r   c                 óp   — |D ]2}	 t           j                             |¦  «         Œ## t          $ r Y Œ/w xY w| S r)   )ÚwarningsÚfiltersÚremoveÚ
ValueError)ÚpassthroughÚaddedFiltersÚfs      r   Ú_resetWarningFiltersrh   ¸   sV   € Øð ð ˆð	ÝÔ×#Ò# AÑ&Ô&Ð&Ð&øÝð 	ð 	ð 	ØˆDð	øøøàÐs   †&¦
3²3c                 ó¼  — | D ]\  }}t          j        |i |¤Ž Œt           j        dt          | ¦  «        …         }	  ||i |¤Ž}t	          |t
          j        ¦  «        r|                     t          |¦  «         nt          d|¦  «         |S # t          $ rE t          j        ¦   «         }t          d|¦  «         |d                              |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ð 1‰ˆˆfÝÔ Ð0¨Ð0Ð0Ð0Ð0ÝÔ#Ð$=¥cÐ*<Ñ&=Ô&=Ð$=Ô>€LðØ��A�˜��ˆõ �f�eœnÑ-Ô-ð 	5Ø�NŠNÕ/°Ñ>Ô>Ð>Ð>å   |Ñ4Ô4Ð4Øˆøõ ð 6ð 6ð 6Ý”<‘>”>ˆÝ˜T <Ñ0Ô0Ð0Ø�qŒk×(Ò(¨°!¬Ñ5Ô5Ð5ð6øøøs   ¼B ÂACc                 ó@   ‡ ‡— 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| ¢R i |¤ŽS r)   )ry   )ru   rv   rg   rt   s     €€r   ÚwarningSuppressingWrapperz3suppressWarnings.<locals>.warningSuppressingWrapperó   s$   ø€ å(Ð);¸QÐIÀÐIÐIÐIÀbÐIÐIÐIr   r   )rg   rt   r|   s   `` r   ÚsuppressWarningsr}   ì   sB   øø€ õ ˆ1�X„XðJð Jð Jð Jð Jñ „Xð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ð -0ð -0ð -0�Ô)ñ -0ô -0ð -0ð` ')¨b°tÀTÐTUð ð ð ð ð<6ð 6ð 6ð 6ð 6�8Ô+ñ 6ô 6ð 6ð &(¨R°dÀDð Yð Yð Yð Yð
5ð 5ð 5ð 5ð 5˜Ô0ñ 5ô 5ð 5ð8 ˜R d°DÀTðð ð ð ð&ð ð ð(ð (ð (ðV%ð %ð %ðð ð €€€r   