
    ho                       U d dl mZ d dlZd dlmZmZmZ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mZmZmZ dd	lmZ d
dlmZ d
dlmZ ej6                  dk\  rd dlmZ nd dlmZ eeeddf   Z de!d<   ddeeddddd ddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ"eeedddd ddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ#y)    )annotationsN)AsyncIterableIterableMappingSequence)BytesIO)PathLike)PIPECalledProcessErrorCompletedProcess)IOAnyUnioncast   )Process   )get_async_backend)create_task_group)   
   )	TypeAliaszPathLike[str]zPathLike[bytes]r   StrOrBytesPathTF )inputstdinstdoutstderrcheckcwdenvstartupinfocreationflagsstart_new_sessionpass_fdsusergroupextra_groupsumaskc                 K   dfd}||t        d      t        | |rt        n|||||||	|
|||||       d{   4 d{   }ddgt               4 d{   }|j                  r|j                  ||j                  d       |j                  r|j                  ||j                  d       |j                  rG|rE|j                  j                  |       d{    |j                  j                          d{    |j                          d{    ddd      d{    ddd      d{    \  }}|r5j                  dk7  r&t        t        t        |j                        | ||      t        | t        t        j                        ||      S 7 d7 ^7 J7 7 7 7 # 1 d{  7  sw Y   xY w7 # 1 d{  7  sw Y   xY ww)a  
    Run an external command in a subprocess and wait until it completes.

    .. seealso:: :func:`subprocess.run`

    :param command: either a string to pass to the shell, or an iterable of strings
        containing the executable name or path and its arguments
    :param input: bytes passed to the standard input of the subprocess
    :param stdin: one of :data:`subprocess.PIPE`, :data:`subprocess.DEVNULL`,
        a file-like object, or `None`; ``input`` overrides this
    :param stdout: one of :data:`subprocess.PIPE`, :data:`subprocess.DEVNULL`,
        a file-like object, or `None`
    :param stderr: one of :data:`subprocess.PIPE`, :data:`subprocess.DEVNULL`,
        :data:`subprocess.STDOUT`, a file-like object, or `None`
    :param check: if ``True``, raise :exc:`~subprocess.CalledProcessError` if the
        process terminates with a return code other than 0
    :param cwd: If not ``None``, change the working directory to this before running the
        command
    :param env: if not ``None``, this mapping replaces the inherited environment
        variables from the parent process
    :param startupinfo: an instance of :class:`subprocess.STARTUPINFO` that can be used
        to specify process startup parameters (Windows only)
    :param creationflags: flags that can be used to control the creation of the
        subprocess (see :class:`subprocess.Popen` for the specifics)
    :param start_new_session: if ``true`` the setsid() system call will be made in the
        child process prior to the execution of the subprocess. (POSIX only)
    :param pass_fds: sequence of file descriptors to keep open between the parent and
        child processes. (POSIX only)
    :param user: effective user to run the process as (Python >= 3.9, POSIX only)
    :param group: effective group to run the process as (Python >= 3.9, POSIX only)
    :param extra_groups: supplementary groups to set in the subprocess (Python >= 3.9,
        POSIX only)
    :param umask: if not negative, this umask is applied in the child process before
        running the given command (Python >= 3.9, POSIX only)
    :return: an object representing the completed process
    :raises ~subprocess.CalledProcessError: if ``check`` is ``True`` and the process
        exits with a nonzero return code

    c                   K   t               }| 2 3 d {   }|j                  |       7 6 |j                         |<   y w)N)r   writegetvalue)streamindexbufferchunkstream_contentss       >D:\jyotish\venv\Lib\site-packages\anyio/_core/_subprocesses.pydrain_streamz!run_process.<locals>.drain_streamQ   s?     ! 	 %LL	 6 "(!2s   A-+-A-ANz&only one of stdin and input is allowedr   r   r   r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r   r   )r/   zAsyncIterable[bytes]r0   intreturnNone)
ValueErroropen_processr
   r   r   
start_soonr   r   sendaclosewait
returncoder   r   r7   r   )commandr   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r5   processtgoutputerrorsr3   s                        @r4   run_processrF      s    v3 U.ABB!d#+!    
/3Tl$&&"~~lGNNA>~~lGNNA>}}mm((///mm**,,,,,.   '&# < %NFF##q( c7+=+=!>QWXXGT#w/A/A%BFFSSE " ' 0,  '&&&#   s   :GF!GF$G
G	F'G	!A?F2 F*!!F2F,F2F.F2G	*F0+G	/G:G;A'G$G'G	*F2,F2.F20G	2G	8F;9G	 G	G	GGGGr6   c                  K   i }|
|
|d<   |||d<   |||d<   |dk\  r||d<    t               j                  | f|||||||||	d	| d{   S 7 w)a  
    Start an external command in a subprocess.

    .. seealso:: :class:`subprocess.Popen`

    :param command: either a string to pass to the shell, or an iterable of strings
        containing the executable name or path and its arguments
    :param stdin: one of :data:`subprocess.PIPE`, :data:`subprocess.DEVNULL`, a
        file-like object, or ``None``
    :param stdout: one of :data:`subprocess.PIPE`, :data:`subprocess.DEVNULL`,
        a file-like object, or ``None``
    :param stderr: one of :data:`subprocess.PIPE`, :data:`subprocess.DEVNULL`,
        :data:`subprocess.STDOUT`, a file-like object, or ``None``
    :param cwd: If not ``None``, the working directory is changed before executing
    :param env: If env is not ``None``, it must be a mapping that defines the
        environment variables for the new process
    :param creationflags: flags that can be used to control the creation of the
        subprocess (see :class:`subprocess.Popen` for the specifics)
    :param startupinfo: an instance of :class:`subprocess.STARTUPINFO` that can be used
        to specify process startup parameters (Windows only)
    :param start_new_session: if ``true`` the setsid() system call will be made in the
        child process prior to the execution of the subprocess. (POSIX only)
    :param pass_fds: sequence of file descriptors to keep open between the parent and
        child processes. (POSIX only)
    :param user: effective user to run the process as (POSIX only)
    :param group: effective group to run the process as (POSIX only)
    :param extra_groups: supplementary groups to set in the subprocess (POSIX only)
    :param umask: if not negative, this umask is applied in the child process before
        running the given command (POSIX only)
    :return: an asynchronous process object

    Nr'   r(   r)   r   r*   )	r   r   r   r!   r"   r#   r$   r%   r&   )r   r;   )rA   r   r   r   r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   kwargss                  r4   r;   r;      s     b  Fvw!&~zw1"$11#+    s   A
AAA)"rA   )StrOrBytesPath | Sequence[StrOrBytesPath]r   zbytes | Noner   int | IO[Any] | Noner   rJ   r   rJ   r    boolr!   StrOrBytesPath | Noner"   Mapping[str, str] | Noner#   r   r$   r7   r%   rK   r&   Sequence[int]r'   str | int | Noner(   rO   r)   Iterable[str | int] | Noner*   r7   r8   zCompletedProcess[bytes])rA   rI   r   rJ   r   rJ   r   rJ   r!   rL   r"   rM   r#   r   r$   r7   r%   rK   r&   rN   r'   rO   r(   rO   r)   rP   r*   r7   r8   r   )$
__future__r   syscollections.abcr   r   r   r   ior   osr	   
subprocessr
   r   r   typingr   r   r   r   abcr   
_eventloopr   _tasksr   version_infor   typing_extensionsstrbytesr   __annotations__rF   r;   r       r4   <module>ra      s,   " 
 F F   A A ' '  ) %w +!#uo?P"PQ	 Q "&#'#'!%$(# !"/3#gT6gT gT  	gT
 !gT !gT gT 
gT 
"gT gT gT gT gT gT gT  -!gT" #gT$ %gTZ #'#'#'!%$(# !"/3J6J  J !	J
 !J 
J 
"J J J J J J J -J J  !Jr`   