o
    0׾gD                    @   s  d Z ddlmZmZ ddlZddlZddlZddlZddlZddl	Z	zddl
mZ W n ey5   dZY nw zddlZW n eyG   dZY nw zddlZW n eyY   dZY nw ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZmZmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl m!Z! ddl m"Z" ddl#m$Z$m%Z% e$j&Z&ddl'Z(g dZ)ej*+dse),d dZ-dZ.g dZ/g dZ0e/g d7 Z/e01d e01d e),d e),d e01d ze2dZ3W n   dZ3Y e01d e/,d e/4g d  e)4d!g d"d! Z5d#Z6e(j6r+e)4d$g ne/4d$g erDdZ7e)4ej*dkrAd%gng  e"e(e8 e/d&d'Z9e04e:e/;e:e9 e9Z/[9e<e(d(e!Z=e<e(d)e!Z>e(e=e>gZ?e@e0D ]1ZAeAe8 v r{qqe!ZBe?D ]ZCe<eCeAe!ZBeBe!ur nqeBe!u re01eA qqeBe8 eA< qq[?e)e/ ZDd*D ]ZEeEeDvreD,eE qej*dkZFeFrddlGZGG d+d, d,eHZInddlJZJddlKZKdd-lLmMZM eMNd.d/ZOdd0lPmQZQ zeR W n eSy   G d1d2 d2eTZRY nw d3d4 ZUd5d6 ZVd7d8 ZWeX ZYd9e8 vr!dd:lZm[Z\ G d;d9 d9e\Z]e^ed<r+ej_Z`nd=d> Z`d?d@ ZaG dAdB dBeXZbG dCdD dDeXZcdEdF ZdG dGd deXZedHd ZfdIdJ ZgdS )Ka%  
Cooperative ``subprocess`` module.

.. caution:: On POSIX platforms, this module is not usable from native
   threads other than the main thread; attempting to do so will raise
   a :exc:`TypeError`. This module depends on libev's fork watchers.
   On POSIX systems, fork watchers are implemented using signals, and
   the thread to which process-directed signals are delivered `is not
   defined`_. Because each native thread has its own gevent/libev
   loop, this means that a fork watcher registered with one loop
   (thread) may never see the signal about a child it spawned if the
   signal is sent to a different thread.

.. note:: The interface of this module is intended to match that of
   the standard library :mod:`subprocess` module (with many backwards
   compatible extensions from Python 3 backported to Python 2). There
   are some small differences between the Python 2 and Python 3
   versions of that module (the Python 2 ``TimeoutExpired`` exception,
   notably, extends ``Timeout`` and there is no ``SubprocessError``) and between the
   POSIX and Windows versions. The HTML documentation here can only
   describe one version; for definitive documentation, see the
   standard library or the source code.

.. _is not defined: http://www.linuxprogrammingblog.com/all-about-linux-signals?page=11
    )absolute_importprint_functionN)GenericAlias)AsyncResult)_get_hub_noargs)	linkproxy)sleep)
getcurrent)integer_typesstring_typesxrange)PY311)PYPY)fsdecode)fsencode)PathLike)_NONE)copy_globals)Greenletjoinall)Popencall
check_callcheck_outputwin32_posixsubprocesszPIPE should be imported)PIPESTDOUTCalledProcessErrorCREATE_NEW_CONSOLECREATE_NEW_PROCESS_GROUPSTD_INPUT_HANDLESTD_OUTPUT_HANDLESTD_ERROR_HANDLESW_HIDESTARTF_USESTDHANDLESSTARTF_USESHOWWINDOW)MAXFD_eintr_retry_callSTARTUPINFO
pywintypeslist2cmdline_subprocess_winapiWAIT_OBJECT_0WaitForSingleObjectGetExitCodeProcessGetStdHandle
CreatePipeDuplicateHandleGetCurrentProcessDUPLICATE_SAME_ACCESSGetModuleFileName
GetVersionCreateProcessINFINITETerminateProcessSTILL_ACTIVErunCompletedProcess)DEVNULLgetstatusoutput	getoutputSubprocessErrorTimeoutExpiredr<   r=   r'   SC_OPEN_MAX   r)   )
ABOVE_NORMAL_PRIORITY_CLASSBELOW_NORMAL_PRIORITY_CLASSHIGH_PRIORITY_CLASSIDLE_PRIORITY_CLASSNORMAL_PRIORITY_CLASSREALTIME_PRIORITY_CLASSCREATE_NO_WINDOWDETACHED_PROCESSCREATE_DEFAULT_ERROR_MODECREATE_BREAKAWAY_FROM_JOB_use_posix_spawnc                   C      dS )NF rQ   rQ   rQ   [/var/www/html/backend_erp/backend_erp_env/lib/python3.10/site-packages/gevent/subprocess.pyrO         F_USE_POSIX_SPAWN
_fork_execT)
only_namesignore_missing_namesr,   r-   )r<   r=   rB   c                   @   s0   e Zd ZdZdd Zdd Zdd ZeZeZdS )	HandleFc                 C   s   | j sd| _ t|  d S d S NT)closedr-   CloseHandleselfrQ   rQ   rR   Close  s   zHandle.Closec                 C   s   | j s
d| _ t| S td)NTzalready closed)rZ   int
ValueErrorr\   rQ   rQ   rR   Detach  s   zHandle.Detachc                 C   s   dt |  S )Nz
Handle(%d)r_   r\   rQ   rQ   rR   __repr__  s   zHandle.__repr__N)	__name__
__module____qualname__rZ   r^   ra   rc   __del____str__rQ   rQ   rQ   rR   rX     s    rX   )monkeyosfork)fork_and_watchc                   @   s   e Zd ZdZdS )BrokenPipeErrorzNever raised, never caught.N)rd   re   rf   __doc__rQ   rQ   rQ   rR   rm   %  s    rm   c                  O   sh   | dd}t| i |}z|j|ddW W  d   S    |  |   1 s-w   Y  dS )a^  
    call(args, *, stdin=None, stdout=None, stderr=None, shell=False, timeout=None) -> returncode

    Run command with arguments. Wait for command to complete or
    timeout, then return the returncode attribute.

    The arguments are the same as for the Popen constructor.  Example::

        retcode = call(["ls", "-l"])

    .. versionchanged:: 1.2a1
       The ``timeout`` keyword argument is now accepted on all supported
       versions of Python (not just Python 3) and if it expires will raise a
       :exc:`TimeoutExpired` exception (under Python 2 this is a subclass of :exc:`~.Timeout`).
    timeoutNTro   
_raise_exc)popr   waitkill)	popenargskwargsro   prQ   rQ   rR   r   )  s   r   c                  O   s:   t | i |}|r|d}|du r| d }t||dS )a  
    check_call(args, *, stdin=None, stdout=None, stderr=None, shell=False, timeout=None) -> 0

    Run command with arguments.  Wait for command to complete.  If
    the exit code was zero then return, otherwise raise
    :exc:`CalledProcessError`.  The ``CalledProcessError`` object will have the
    return code in the returncode attribute.

    The arguments are the same as for the Popen constructor.  Example::

        retcode = check_call(["ls", "-l"])
    argsNr   )r   getr   )ru   rv   retcodecmdrQ   rQ   rR   r   B  s   

r   c               	   O   s  | dd}d|v rtdd|v rtdd|v r.d|v r"td	|d }|d= t|d< nd}t| dti|G}z|j||d
\}}W n$ ty^   |  | \}}t|j||d   |  |   |	 }|rxt
||j|dW d   |S 1 sw   Y  |S )a  
    check_output(args, *, input=None, stdin=None, stderr=None, shell=False, universal_newlines=False, timeout=None) -> output

    Run command with arguments and return its output.

    If the exit code was non-zero it raises a :exc:`CalledProcessError`.  The
    ``CalledProcessError`` object will have the return code in the returncode
    attribute and output in the output attribute.


    The arguments are the same as for the Popen constructor.  Example::

        >>> check_output(["ls", "-1", "/dev/null"])
        '/dev/null\n'

    The ``stdout`` argument is not allowed as it is used internally.

    To capture standard error in the result, use ``stderr=STDOUT``::

        >>> output = check_output(["/bin/sh", "-c",
        ...               "ls -l non_existent_file ; exit 0"],
        ...              stderr=STDOUT).decode('ascii').strip()
        >>> print(output.rsplit(':', 1)[1].strip())
        No such file or directory

    There is an additional optional argument, "input", allowing you to
    pass a string to the subprocess's stdin.  If you use this argument
    you may not also use the Popen constructor's "stdin" argument, as
    it too will be used internally.  Example::

        >>> check_output(["sed", "-e", "s/foo/bar/"],
        ...              input=b"when in the course of fooman events\n")
        'when in the course of barman events\n'

    If ``universal_newlines=True`` is passed, the return value will be a
    string rather than bytes.

    .. versionchanged:: 1.2a1
       The ``timeout`` keyword argument is now accepted on all supported
       versions of Python (not just Python 3) and if it expires will raise a
       :exc:`TimeoutExpired` exception (under Python 2 this is a subclass of :exc:`~.Timeout`).
    .. versionchanged:: 1.2a1
       The ``input`` keyword argument is now accepted on all supported
       versions of Python, not just Python 3
    .. versionchanged:: 22.08.0
       Passing the ``check`` keyword argument is forbidden, just as in Python 3.11.
    ro   Nstdoutz3stdout argument not allowed, it will be overridden.checkz2check argument not allowed, it will be overridden.inputstdin/stdin and input arguments may not both be used.ro   output)rr   r`   r   r   communicaterB   rt   rx   rs   pollr   )ru   rv   ro   	inputdataprocessr   
unused_errrz   rQ   rQ   rR   r   W  s>   0

r   rB   )Timeoutc                   @   s.   e Zd ZdZd	ddZedd Zdd ZdS )
rB   a  
        This exception is raised when the timeout expires while waiting for
        a child process in `communicate`.

        Under Python 2, this is a gevent extension with the same name as the
        Python 3 class for source-code forward compatibility. However, it extends
        :class:`gevent.timeout.Timeout` for backwards compatibility (because
        we used to just raise a plain ``Timeout``); note that ``Timeout`` is a
        ``BaseException``, *not* an ``Exception``.

        .. versionadded:: 1.2a1
        Nc                 C   s"   t | d  || _|| _|| _d S N)_Timeout__init__r{   secondsr   )r]   r{   ro   r   rQ   rQ   rR   r     s   
zTimeoutExpired.__init__c                 C   s   | j S r   )r   r\   rQ   rQ   rR   ro     s   zTimeoutExpired.timeoutc                 C   s   d| j | jf S )Nz'Command '%s' timed out after %s seconds)r{   ro   r\   rQ   rQ   rR   rh     s   
zTimeoutExpired.__str__r   )rd   re   rf   rn   r   propertyro   rh   rQ   rQ   rQ   rR   rB     s    

set_inheritablec                 C   rP   rY   rQ   )ivrQ   rQ   rR   <lambda>  s    r   c                  O   s   ddl m} |t d< ||  S )Nr   )
FileObjectr   )gevent.fileobjectr   globals)rx   rv   _FileObjectrQ   rQ   rR   r     s   
r   c                   @   sL   e Zd ZdZdd Zdd Zdd ZeZdd	 Ze	d
d Z
e	dd ZdS )_CommunicatingGreenlets)r   r|   stderr_all_greenletsc                 C   s   d  | _  | _| _|j rt| j|j || _ |jr t| j|j| _|jr+t| j|j| _g }| j | j| jfD ]}|d ur@|| q5t|| _d S r   )	r   r|   r   spawn_write_and_close_read_and_closeappendtupler   )r]   popen
input_dataall_greenletsgrQ   rQ   rR   r     s   
z _CommunicatingGreenlets.__init__c                 C   
   t | jS r   )iterr   r\   rQ   rQ   rR   __iter__	     
z _CommunicatingGreenlets.__iter__c                 C   r   r   )boolr   r\   rQ   rQ   rR   __bool__  r   z _CommunicatingGreenlets.__bool__c                 C   r   r   )lenr   r\   rQ   rQ   rR   __len__  r   z_CommunicatingGreenlets.__len__c                 C   s   zRz|r|  | t| dr|   W n, ttfy? } zt|tr+|jd u r+tj|_|jtjtjfvr5 W Y d }~nd }~ww W z| 	  W d S  t
yR   Y d S w z| 	  W w  t
yb   Y w w )Nflush)writehasattrr   OSErrorrm   
isinstanceerrnoEPIPEEINVALcloseEnvironmentError)fobjdataexrQ   rQ   rR   r     s2   

	z(_CommunicatingGreenlets._write_and_closec                 C   sJ   z|   W z|   W S  ty   Y S w z|   W w  ty$   Y w w r   )readr   r   )r   rQ   rQ   rR   r   *  s   z'_CommunicatingGreenlets._read_and_closeN)rd   re   rf   	__slots__r   r   r   __nonzero__r   staticmethodr   r   rQ   rQ   rQ   rR   r     s    

r   c                   @   s  e Zd ZdZedureeZdZddddddedddddddddddddddddddfd	d
Z	dd Z
dd Zdd Zdd ZdZdMddZdd Zdd Zdd ZdNddZerdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. ZdNd/d0Zd1d2 Zd3d4 Z e Z!dS d5d* Zd6d ZdOd7d8Z"d9d: Z#d;d< Z$d=Z%ed>d? Z&ed@dA Z'edBdC Z(dDd& Ze)j*e)j+e)j,e)j-e)j.e)j/fdEdFZ0dGd( ZdNdHd0ZdId2 ZdJd4 Z dKdL Z!dS )Pr   a  
    The underlying process creation and management in this module is
    handled by the Popen class. It offers a lot of flexibility so that
    developers are able to handle the less common cases not covered by
    the convenience functions.

    .. seealso:: :class:`subprocess.Popen`
       This class should have the same interface as the standard library class.

    .. caution::

       The default values of some arguments, notably ``buffering``, differ
       between Python 2 and Python 3. For the most consistent behaviour across
       versions, it's best to explicitly pass the desired values.

    .. caution::

       On Python 2, the ``read`` method of the ``stdout`` and ``stderr`` attributes
       will not be buffered unless buffering is explicitly requested (e.g., `bufsize=-1`).
       This is different than the ``read`` method of the standard library attributes,
       which will buffer internally even if no buffering has been requested. This
       matches the Python 3 behaviour. For portability, please explicitly request
       buffering if you want ``read(n)`` to return all ``n`` bytes, making more than
       one system call if needed. See `issue 1701 <https://github.com/gevent/gevent/issues/1701>`_
       for more context.

    .. versionchanged:: 1.2a1
       Instances can now be used as context managers under Python 2.7. Previously
       this was restricted to Python 3.

    .. versionchanged:: 1.2a1
       Instances now save the ``args`` attribute under Python 2.7. Previously this was
       restricted to Python 3.

    .. versionchanged:: 1.2b1
        Add the ``encoding`` and ``errors`` parameters for Python 3.

    .. versionchanged:: 1.3a1
       Accept "path-like" objects for the *cwd* parameter on all platforms.
       This was added to Python 3.6. Previously with gevent, it only worked
       on POSIX platforms on 3.6.

    .. versionchanged:: 1.3a1
       Add the ``text`` argument as a synonym for ``universal_newlines``,
       as added on Python 3.7.

    .. versionchanged:: 1.3a2
       Allow the same keyword arguments under Python 2 as Python 3:
       ``pass_fds``, ``start_new_session``, ``restore_signals``, ``encoding``
       and ``errors``. Under Python 2, ``encoding`` and ``errors`` are ignored
       because native handling of universal newlines is used.

    .. versionchanged:: 1.3a2
       Under Python 2, ``restore_signals`` defaults to ``False``. Previously it
       defaulted to ``True``, the same as it did in Python 3.

    .. versionchanged:: 20.6.0
       Add the *group*, *extra_groups*, *user*, and *umask* arguments. These
       were added to Python 3.9, but are available in any gevent version, provided
       the underlying platform support is present.

    .. versionchanged:: 20.12.0
       On Python 2 only, if unbuffered binary communication is requested,
       the ``stdin`` attribute of this object will have a ``write`` method that
       actually performs internal buffering and looping, similar to the standard library.
       It guarantees to write all the data given to it in a single call (but internally
       it may make many system calls and/or trips around the event loop to accomplish this).
       See :issue:`1711`.

    .. versionchanged:: 21.12.0
       Added the ``pipesize`` argument for compatibility with Python 3.10.
       This is ignored on all platforms.

    .. versionchanged:: 22.08.0
       Added the ``process_group`` and ``check`` arguments for compatibility with
       Python 3.11.
    N    Fr   TrQ   c           +      C   s  || _ || _t }|d u rd}t|tstdtr6|d ur"td|tu r(d}|d u r/|j	}|| _	d| _
n0|tu r<d}|rL|sLdd l}|dt d}|d urTtd|dkr\td	|d u sbJ |j| _|d urz|d urzt|t|krztd
|| _d | _d | _d | _d | _d | _|| _t | _| |||\}}} }!}"}#tr|dkrt| d}| dkrt|  d} |"dkrt|" d}"| j p| jp|p|}$|$s|rd| _|  |||\}%}&}'|dkr|$rt!|d|| j | jd| _nt!|d|| _| dkr|s|$rt!| d|| j | jd| _nt!| d|| _|"dkr7|s%|$r0t!|"d|||d| _nt!|"d|| _d| _"|
d urCt#|
nd }
z| $||||||
|||||	||| |!|"|#||&|'|%||| W d S    t%d | j| j| jfD ]}(z|(&  W qs t'y   Y qsw | j"sg })|t(kr|))| |t(kr|))|! |t(kr|))|# t*| dr|))| j+ |)D ]}*zt,&|* W q t'y   Y qw  )Nr   zbufsize must be an integerz0preexec_fn is not supported on Windows platformsTFr   zpass_fds overriding close_fds.z2startupinfo is only supported on Windows platformsz4creationflags is only supported on Windows platformszlCannot disambiguate when both text and universal_newlines are supplied but different. Pass one or the other. w)encodingerrorswbrrb_devnull)-r   r   get_hubr   r
   	TypeError	mswindowsr`   _PLATFORM_DEFAULT_CLOSE_FDS
threadpool_waitingwarningswarnRuntimeWarningloop_loopr   rA   rx   r   r|   r   pid
returncodeuniversal_newlinesr   result_get_handlesmsvcrtopen_osfhandlera   _communicate_empty_value_Popen__handle_uidsr   _closed_child_pipe_fdsr   _execute_childfilterr   r   r   r   r   r   rj   )+r]   rx   bufsize
executabler   r|   r   
preexec_fn	close_fdsshellcwdenvr   startupinfocreationflagsrestore_signalsstart_new_sessionpass_fdsr   r   textgroupextra_groupsuserumaskpipesizeprocess_groupr   hubr   p2creadp2cwritec2preadc2pwriteerrreaderrwrite	text_modeuidgidgidsfto_closefdrQ   rQ   rR   r     s   



	


	





zPopen.__init__c           	      C   s  d }|d ur>t tdstdt|tr#td u rtdt|j}nt|tr+|}n	t	d
t||dk r>td| d }|d urt tdsMtdt|trVtd	g }|D ]4}t|trstd u ritd
|t|j qZt|tr|dkrtd|| qZt	d
t||D ]}|dk rtd|f qd }|d urt tdstdt|trtd u rtdt|j}nt|tr|}nt	d|dk rtd|f |||fS )Nsetregidz>The 'group' parameter is not supported on the current platformzHThe group parameter cannot be a string on systems without the grp modulez,Group must be a string or an integer, not {}r   z#Group ID cannot be negative, got %s	setgroupszEThe 'extra_groups' parameter is not supported on the current platformz#Groups must be a list, not a stringzIItems in extra_groups cannot be strings on systems without the grp modulel            z!Item in extra_groups is too largez9Items in extra_groups must be a string or integer, not {}setreuidz=The 'user' parameter is not supported on the current platformzGThe user parameter cannot be a string on systems without the pwd modulez#User must be a string or an integerz"User ID cannot be negative, got %s)r   rj   r`   r   strgrpgetgrnamgr_gidr_   r   formattyper   pwdgetpwnampw_uid)	r]   r   r   r   r   r   extra_group	gid_checkr   rQ   rQ   rR   __handle_uidsM  sh   













zPopen.__handle_uidsc                 C   s   d| j jt| | j| jf S )Nz!<%s at 0x%x pid=%r returncode=%r>)	__class__rd   idr   r   r\   rQ   rQ   rR   rc     s   zPopen.__repr__c                 C   sF   |   |j}t|rt| | _nt|| _| j| j d S r   )	stoprstatusrj   WIFSIGNALEDWTERMSIGr   WEXITSTATUSr   set)r]   watcherstatusrQ   rQ   rR   	_on_child  s   
zPopen._on_childc                 C   s"   t | dsttjtj| _| jS )Nr   )r   rj   opendevnullO_RDWRr   r\   rQ   rQ   rR   _get_devnull  s   
zPopen._get_devnullc              	   C   s   | j du rt| || _ | j }|s|dur| j|dd t||d}|D ]}|  q#|dur=t|t| j kr=t| j|| j| j	fD ]}|rWz|
  W qC tyV   Y qCw qC|   |jdu rcdn|j |j	du rodfS |j	 fS )a  
        Interact with process and return its output and error.

        - Send *input* data to stdin.
        - Read data from stdout and stderr, until end-of-file is reached.
        - Wait for process to terminate.

        The optional *input* argument should be a
        string to be sent to the child process, or None, if no data
        should be sent to the child.

        communicate() returns a tuple (stdout, stderr).

        :keyword timeout: Under Python 2, this is a gevent extension; if
           given and it expires, we will raise :exc:`TimeoutExpired`, which
           extends :exc:`gevent.timeout.Timeout` (note that this only extends :exc:`BaseException`,
           *not* :exc:`Exception`)
           Under Python 3, this raises the standard :exc:`TimeoutExpired` exception.

        .. versionchanged:: 1.1a2
           Under Python 2, if the *timeout* elapses, raise the :exc:`gevent.timeout.Timeout`
           exception. Previously, we silently returned.
        .. versionchanged:: 1.1b5
           Honor a *timeout* even if there's no way to communicate with the child
           (stdin, stdout, and stderr are not pipes).
        NTrp   r   )_communicating_greenletsr   rs   r   ry   r   rB   rx   r|   r   r   RuntimeError)r]   r~   ro   	greenletsdonegreenletpiperQ   rQ   rR   r     s0   

zPopen.communicatec                 C   s   |   S )zSCheck if child process has terminated. Set and return :attr:`returncode` attribute.)_internal_pollr\   rQ   rQ   rR   r     s   z
Popen.pollc                 C   s   | S r   rQ   r\   rQ   rQ   rR   	__enter__  rS   zPopen.__enter__c                 C   sX   | j r| j   | jr| j  z| jr | j  W |   d S W |   d S |   w r   )r|   r   r   r   rs   )r]   tr   tbrQ   rQ   rR   __exit__  s   

zPopen.__exit__c                 C   s4   | j j|d}|r|d ur| j  st| j||S )Nr   )r   rs   readyrB   rx   )r]   ro   	raise_excr   rQ   rQ   rR   _gevent_result_wait  s   zPopen._gevent_result_waitc                 C   s~  |du r|du r|du rdS d\}}d\}}d\}}	zt  W n ty*   t }
Y nw t }
|du rJtt}|du rItdd\}}t|}t| n3|t	kr_tdd\}}t|t|}}n||
krkt
|  }nt|trvt
|}nt
| }| |}|du rtt}|du rtdd\}}t|}t| n3|t	krtdd\}}t|t|}}n||
krt
|  }nt|trt
|}nt
| }| |}|du rtt}	|	du rtdd\}}	t|	}	t| n>|t	kr
tdd\}}	t|t|	}}	n(|tkr|}	n ||
krt
|  }	nt|tr+t
|}	nt
| }	| |	}	||||||	fS )|Construct and return tuple with IO objects:
            p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite
            N)r   r   r   r   r   r   r   r   r   )r>   	NameErrorobjectr1   r!   r2   rX   r-   r[   r   r   get_osfhandler  r   r_   fileno_make_inheritabler"   r#   r   )r]   r   r|   r   r   r   r   r   r   r   r   _rQ   rQ   rR   r     s   











zPopen._get_handlesc                 C   s   t t |t ddtS )z2Return a duplicate of handle, which is inheritabler      )r3   r4   r5   )r]   handlerQ   rQ   rR   r0  f  s   
zPopen._make_inheritablec                 C   sV   t jt jtdd}t j|s)t jt jtjd}t j|s)td|S )z-Find and return absolute path to w9xpopen.exer   zw9xpopen.exezZCannot locate w9xpopen.exe, which is needed for Popen to work with your shell or platform.)	rj   pathjoindirnamer6   existssysexec_prefixr  )r]   w9xpopenrQ   rQ   rR   _find_w9xpopenm  s   zPopen._find_w9xpopenc                 C   s   t dd |D S )zFilter out console handles that can't be used
            in lpAttributeList["handle_list"] and make sure the list
            isn't empty. This also removes duplicate handles.c                 S   s,   h | ]}|d @ d kst |t jkr|qS )   )r-   GetFileTypeFILE_TYPE_CHAR).0r3  rQ   rQ   rR   	<setcomp>  s    z,Popen._filter_handle_list.<locals>.<setcomp>)list)r]   handle_listrQ   rQ   rR   _filter_handle_list~  s   zPopen._filter_handle_listc           &   
      s.  |rJ dt |trn&t |tr|rtdt|g}nt |tr.|r(tdt|g}nt|}|dur:t|}t |tsCt|}|	du rKt }	nt	|	drU|	
 }	n	t	|	dr^|	 }	d|||fv}|rw|	 jtO  _||	_||	_||	_t	|	dr|	j}t|od	|v o|d	 }|s|r|r|du ri  }|	_t|d	g  }|d	< |r|t|t|t|g7 }| ||dd< |r|sd
dl}|dt d}|r|	 jtO  _t|	_tjdd}d||}t  dkstj!"|# dkr| $ }d||f }|
t%O }
t&r!t'fdd  fdd}  |  | |   z1t(||ddt| |
||		\}!}"}#}$W dd }%|%| |%| |%| t	| drRt)| j* ndd }%|%| |%| |%| t	| drpt)| j* w w d| _+t	|!ds~t,|!n|!| _-|#| _.t	|"dst/0|" dS |"1  dS )z$Execute program (MS Windows version)z"pass_fds not supported on Windows.z$bytes args is not allowed on Windows0path-like args is not allowed when shell is trueNcopy_copyr   lpAttributeListrB  r   z?startupinfo.lpAttributeList['handle_list'] overriding close_fdsFCOMSPECzcmd.exez
{} /c "{}"l        zcommand.comz"%s" %sc                 S   s.   | sd S t | trdnd}|| v r|dd S )N     z0argument must be a string without NUL characters)r   bytes)serr_kindnulrQ   rQ   rR   
_check_nul  s   z(Popen._execute_child.<locals>._check_nulc                     s>   sd S   D ]\} } |   | d| v rtdqd S )N=z#'=' not allowed in environment keys)itemsr`   )kr   rO  r   rQ   rR   
_check_env   s   z(Popen._execute_child.<locals>._check_envc                 S   s<   | d ur| dkrt | dr|   d S t|  d S d S d S )Nr   r^   )r   r^   r-   r[   )xrQ   rQ   rR   _close%  s
   
z$Popen._execute_child.<locals>._closer   Tr^   )2r   r  rK  r   r+   r   r   r   r)   r   rE  rF  dwFlagsr%   	hStdInput
hStdOutput	hStdErrorrG  r   rA  ry   r_   rC  r   r   r   r&   r$   wShowWindowrj   environr  r7   r4  basenamelowerr;  r   r   r`   r8   r   r   _child_createdrX   _handler   r-   r[   r^   )&r]   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   unused_restore_signals
unused_gidunused_gids
unused_uidunused_umaskunused_start_new_sessionunused_process_groupuse_std_handlesattribute_listhave_handle_listrB  r   comspecr:  rT  hphtr   tidrV  rQ   rS  rR   r     s   









 	&zPopen._execute_childc                 C   s:   | j du rt| jdtkrt| j| _ | j| j  | j S )^Check if child process has terminated.  Returns returncode
            attribute.
            Nr   )r   r/   r`  r.   r0   r   r  r\   rQ   rQ   rR   r"  8  s
   
zPopen._internal_pollc                 C   s8   | j  s| jsd| _t| j | j t||  d S rY   )r   r'  r   r   r   _waitrawlinkr   r]   callbackrQ   rQ   rR   rq  C  s   zPopen.rawlinkc                 C   s   t | jt t| j| _| jS r   )r/   r`  r9   r0   r   r\   rQ   rQ   rR   _blocking_waitJ  s   zPopen._blocking_waitc                 C   s   | j | j| j d S r   )r   r   rt  rq  r   r\   rQ   rQ   rR   rp  P  s   zPopen._waitc                 C   s*   | j du r| jsd| _|   | ||S )zOWait for child process to terminate.  Returns returncode
            attribute.NT)r   r   rp  r)  r]   ro   rq   rQ   rQ   rR   rs   S  s
   
z
Popen.waitc                 C   s`   |t jkr|   dS |t jkrt| jt j dS |t jkr)t| jt j dS td	|))Send a signal to the process
            zUnsupported signal: {}N)
signalSIGTERM	terminateCTRL_C_EVENTrj   rt   r   CTRL_BREAK_EVENTr`   r  r]   sigrQ   rQ   rR   send_signal\  s   


zPopen.send_signalc              
   C   s|   | j durdS z	t| jd W dS  ty= } z!|jdkr t| j}|tkr( || _ | j| j  W Y d}~dS d}~ww )z#Terminates the process
            Nr2     )	r   r:   r`  r   winerrorr0   r;   r   r  )r]   ercrQ   rQ   rR   ry  h  s   


zPopen.terminatec                 C   s   | j t||  d S r   )r   rq  r   rr  rQ   rQ   rR   rq    s   c                 C   sN  d\}}d\}}d\}}	zt  W n ty   t }
Y nw t }
|du r$n |tkr/|  \}}n||
kr8|  }nt|tr@|}n| }|du rIn |tkrT|  \}}n||
kr]|  }nt|tre|}n| }|du rnn1|tkry|  \}}	n&|t	kr|dkr|}	nt
j }	n||
kr|  }	nt|tr|}	n| }	||||||	fS )r*  r+  Nr   )r>   r,  r-  r   pipe_cloexecr  r   r_   r/  r   r8  
__stdout__)r]   r   r|   r   r   r   r   r   r   r   r   rQ   rQ   rR   r     sX   






c                 C   sf   zt j}W n ty   d}Y nw t  |t j}|r&t  |t j||B  d S t  |t j|| @  d S )Nr2  )fcntl
FD_CLOEXECAttributeErrorF_GETFDF_SETFD)r]   r   cloexeccloexec_flagoldrQ   rQ   rR   _set_cloexec_flag  s   
zPopen._set_cloexec_flagc                 C   s*   t  |t jtj @ }t  |t j| d S r   )r  F_GETFLrj   
O_NONBLOCKF_SETFL)r]   r   flagsrQ   rQ   rR   _remove_nonblock_flag  s   zPopen._remove_nonblock_flagc                 C   s(   t  \}}| | | | ||fS )z#Create a pipe with FDs set CLOEXEC.)rj   r!  r  )r]   r   r   rQ   rQ   rR   r    s   

zPopen.pipe_cloexec)z/proc/self/fdz/dev/fdc                 C   s6   | j D ]}tj|r| |||  S q| ||S r   )_POSSIBLE_FD_DIRSrj   r4  isdir_close_fds_from_path_close_fds_brute_force)clskeeperrpipe_writer4  rQ   rQ   rR   
_close_fds  s
   
zPopen._close_fdsc              	   C   s   zdd t |D }W n ttfy   | || Y d S w |D ]}||kr(q!t|d q!|D ]}||v s:|dk r;q0zt | W q0   Y q0d S )Nc                 S   s   g | ]}t |qS rQ   rb   )r?  fnamerQ   rQ   rR   
<listcomp>  s    z.Popen._close_fds_from_path.<locals>.<listcomp>Tr<  )rj   listdirr`   r   r  _set_inheritabler   )r  r4  r  r  fdsr   r   rQ   rQ   rR   r    s"   zPopen._close_fds_from_pathc                 C   s   t tdsJ t|}t|}t|}td| t|d t t||D ]}||v r2t|d q&zt	| W q&   Y q&d S )N
closeranger<  r2  T)
r   rj   sortedminmaxr  r'   r   r  r   )r  r  r  min_keepmax_keepr   rQ   rQ   rR   r    s   
zPopen._close_fds_brute_forcec           ,         s  t |ttfr|g}nt |tr|rtdt|g}nt|}|r7ttdr)dnd}|dg| }|r7||d< |du r?|d } j	
    \}}g }|dk r^|| t|}|dk sP|D ]}t| q`zzt }t  zt j j	d	t _W n
   |rt    jdkrzMz#|d
krt| |d
krt| |d
krt| t| |dkrt|}t|d |dv rt|}t|d |dv sǇ fdd}||d ||d ||d 	 |dur	zt| W n ty }" zd	|"_ d}"~"ww |dkrt| z'|rt| |r%t || |r.t!|| |dur9t"d| W n tyK }" zd	|"_# d}"~"ww |rR|  |rdt|}#|#|  $|#| |rdD ]}$t%t&|$d}$|$dur}t&&|$t&j' qi|rt(  z|du rt)|| ndd |* D }t+||| W n ty }" zd	|"_, d}"~"ww W n!   t- \}%}&}'t./|%|&|'}(d0|(|&_1t2|t34|& Y W t5d nt5d w d	 _6|rt  W t| nt| w t% dd})|d
kr|d
kr||)krt| |d
kr+|d
kr+||)kr+t| |d
kr?|d
kr?||)kr?t| |)durIt|) d	 _7t8|d}|9 }*W z!zt|drc|  nt| W n
 tys   Y nw W d
}n/d
}w z(zt|dr|  n
t| W W d
}w W W d
}w  ty   Y W d
}w w d
}w |*dkr :  t3;|*}+|||fD ]}!|!dur|!d
krt|! qt |+tr||+_<t|+dr||+_<t%|+ddrd|+_<|+dS )zExecute program (POSIX version)rD  getandroidapilevelz/system/bin/shz/bin/shz-cr   Nr<  Tr   F)r   r2  c                    sP   | |kr  | d n
| dkrt| | z | W d S  ty'   Y d S w )NFr   )r  rj   dup2r  r   )existingdesiredr\   rQ   rR   _dup2  s   z#Popen._execute_child.<locals>._dup2r2     )SIGPIPESIGXFZSIGXFSZc                 S   s>   i | ]\}}t |trt|n|t |trt|n|qS rQ   )r   rK  rj   r   )r?  rR  r   rQ   rQ   rR   
<dictcomp>  s
    z(Popen._execute_child.<locals>.<dictcomp>r   r   r   r   r   _failed_chdir_failed_chuser)=r   r  rK  r   r   r   rA  r   r8  r   install_sigchldr  r   rj   dupr   gc	isenableddisablerl   r  rk   r   enabler  r  addchdirr   r  r   r   r   r   setpgidr  r  getattrrw  SIG_DFLsetsidexecvprQ  execvpe_failed_execexc_info	tracebackformat_exceptionr5  child_tracebackr   pickledumps_exitr_  r   r   r   rs   loadsfilename),r]   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   
unix_shellerrpipe_readr  low_fds_to_closelow_fdgc_was_enabledr  rZ   r   r  fds_to_keepr}  exc_type	exc_valuer%  	exc_lines
devnull_fdr   child_exceptionrQ   r\   rR   r   $  sX  






















	









	


c                 C   sN   ||r|| | _ d S ||r||| _ d S ||r#|| | _ d S td)NzUnknown child exit status!)r   r  )r]   sts_WIFSIGNALED	_WTERMSIG
_WIFEXITED_WEXITSTATUS_WIFSTOPPED	_WSTOPSIGrQ   rQ   rR   _handle_exitstatus0  s   zPopen._handle_exitstatusc                 C   s6   | j du rt t urt| jdd}|rtd | j S )ro  Nsig_pendingTgh㈵>)r   r   r	   r  r   r   )r]   r  rQ   rQ   rR   r"  A  s   
c                 C   s   |  ||S )a  
            Wait for child process to terminate.  Returns :attr:`returncode`
            attribute.

            :keyword timeout: The floating point number of seconds to
                wait. Under Python 2, this is a gevent extension, and
                we simply return if it expires. Under Python 3, if
                this time elapses without finishing the process,
                :exc:`TimeoutExpired` is raised.
            )r)  ru  rQ   rQ   rR   rs   L  s   c                 C   s    | j du rt| j| dS dS )rv  N)r   rj   rt   r   r|  rQ   rQ   rR   r~  Y  s   
c                 C      |  tj dS )z/Terminate the process with SIGTERM
            N)r~  rw  rx  r\   rQ   rQ   rR   ry  `     c                 C   r  )z*Kill the process with SIGKILL
            N)r~  rw  SIGKILLr\   rQ   rQ   rR   rt   e  r  z
Popen.killNNrY   )T)1rd   re   rf   rn   r   classmethod__class_getitem__r   r   r   r   rc   r  r  r  r   r   r#  r&  r)  r   r   r0  r;  rC  r   r"  rq  rt  rp  rs   r~  ry  rt   r  r  r  r  r  r  r  rj   r  r  	WIFEXITEDr  
WIFSTOPPEDWSTOPSIGr  rQ   rQ   rQ   rR   r   5  s    N
 BV	
A
O -
	
<



  

r   c                 C   s   | j | _|| _| S r   )r   r|   r   )excr   rQ   rQ   rR   _with_stdout_stderrk  s   r  c                   @   s:   e Zd ZdZedureeZd	ddZdd Zdd Z	dS )
r=   a  
    A process that has finished running.

    This is returned by run().

    Attributes:
      - args: The list or str args passed to run().
      - returncode: The exit code of the process, negative for signals.
      - stdout: The standard output (None if not captured).
      - stderr: The standard error (None if not captured).

    .. versionadded:: 1.2a1
       This first appeared in Python 3.5 and is available to all
       Python versions in gevent.
    Nc                 C   s   || _ || _|| _|| _d S r   )rx   r   r|   r   )r]   rx   r   r|   r   rQ   rQ   rR   r     s   
zCompletedProcess.__init__c                 C   sh   d | jd | jg}| jd ur|d | j | jd ur(|d | j d t| jd|S )Nz	args={!r}zreturncode={!r}zstdout={!r}zstderr={!r}z{}({})z, )	r  rx   r   r|   r   r   r  rd   r5  )r]   rx   rQ   rQ   rR   rc     s   



zCompletedProcess.__repr__c                 C   s$   | j rtt| j | j| j| jdS )z6Raise CalledProcessError if the exit code is non-zero.N)r   r  r   rx   r|   r   r\   rQ   rQ   rR   check_returncode  s   z!CompletedProcess.check_returncoder  )
rd   re   rf   rn   r   r  r  r   rc   r  rQ   rQ   rQ   rR   r=   s  s    
	c            
   
   O   sD  | dd}| dd}| dd}| dd}|dur(d|v r$tdt|d< |r>d	|v s2d
|v r6tdt|d	< t|d
< t| i |M}z|j||d\}}W n' tym   |  | \}}tt|j||d|   |  |	   |
 }	|r|	rtt|	|j||W d   n1 sw   Y  t|j|	||S )am  
    run(args, *, stdin=None, input=None, stdout=None, stderr=None, shell=False, timeout=None, check=False) -> CompletedProcess

    Run command with arguments and return a CompletedProcess instance.

    The returned instance will have attributes args, returncode, stdout and
    stderr. By default, stdout and stderr are not captured, and those attributes
    will be None. Pass stdout=PIPE and/or stderr=PIPE in order to capture them.
    If check is True and the exit code was non-zero, it raises a
    CalledProcessError. The CalledProcessError object will have the return code
    in the returncode attribute, and output & stderr attributes if those streams
    were captured.

    If timeout is given, and the process takes too long, a TimeoutExpired
    exception will be raised.

    There is an optional argument "input", allowing you to
    pass a string to the subprocess's stdin.  If you use this argument
    you may not also use the Popen constructor's "stdin" argument, as
    it will be used internally.
    The other arguments are the same as for the Popen constructor.
    If universal_newlines=True is passed, the "input" argument must be a
    string and stdout/stderr in the returned object will be strings rather than
    bytes.

    .. versionadded:: 1.2a1
       This function first appeared in Python 3.5. It is available on all Python
       versions gevent supports.

    .. versionchanged:: 1.3a2
       Add the ``capture_output`` argument from Python 3.7. It automatically sets
       ``stdout`` and ``stderr`` to ``PIPE``. It is an error to pass either
       of those arguments along with ``capture_output``.
    r~   Nro   r}   Fcapture_outputr   r   r|   r   z@stdout and stderr arguments may not be used with capture_output.r   r   )rr   r`   r   r   r   rB   rt   r  rx   rs   r   r   r=   )
ru   rv   r~   ro   r}   r  r   r|   r   rz   rQ   rQ   rR   r<     s<   #c                 O   s<   ddl m} |rdd l}t|dr|jddd d S d S d S )Nr   )MACset_start_methodrk   T)force)gevent._compatr  multiprocessingr   r  )target_module_args_kwargsr  r  rQ   rQ   rR   _gevent_did_monkey_patch  s   
r  )hrn   
__future__r   r   r   r  rj   rw  r8  r  typesr   ImportErrorr  r  gevent.eventr   
gevent.hubr   r   r   r   r	   r  r
   r   r   r   r   r   r   r   gevent._utilr   r   gevent.greenletr   r   r   
subprocess__subprocess____implements__platform
startswithr   r   r   __imports__	__extra__removesysconfr'   extendrO   rT   rU   r   actually_importedr  
differencer  r,   r-   _attr_resolution_orderrA  namevalueplace__all___xr   r   r_   rX   r  r  geventri   get_originalrk   	gevent.osrl   rm   r,  	Exceptionr   r   r   r-  r   gevent.timeoutr   r   rB   r   r   r  r   r   r   r  r=   r<   r  rQ   rQ   rQ   rR   <module>   s(   

	












OX          @*F