o
    ;'ho  ã                   @  s*  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jdkrWd 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;d5d6„Z"eeedddd ddddddd7œd<d9d:„Z#dS )=é    )Ú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ÚumaskÚcommandú)StrOrBytesPath | Sequence[StrOrBytesPath]r   úbytes | Noner   úint | IO[Any] | Noner   r   r   Úboolr    úStrOrBytesPath | Noner!   úMapping[str, str] | Noner"   r   r#   Úintr$   r%   úSequence[int]r&   ústr | int | Noner'   r(   úIterable[str | int] | Noner)   ÚreturnúCompletedProcess[bytes]c                ƒ  sx  �d‡ fdd„}|d	ur|d	urt d
ƒ‚t| |rtn|||||||	|
|||||d�I d	H 4 I d	H š_}d	d	g‰ tƒ 4 I d	H š>}|jrI| ||jd¡ |jrT| ||jd¡ |jrj|rj|j |¡I d	H  |j 	¡ I d	H  | 
¡ I d	H  W d	  ƒI d	H  n1 I d	H s�w   Y  W d	  ƒI d	H  n1 I d	H s–w   Y  ˆ \}}|r±|jdkr±ttt|jƒ| ||ƒ‚t| tt|jƒ||ƒS )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

    ÚstreamúAsyncIterable[bytes]Úindexr1   r5   ÚNonec                 “  s6   �t ƒ }| 2 z3 d H W }| |¡ q6 | ¡ ˆ |< d S )N)r   ÚwriteÚgetvalue)r7   r9   ÚbufferÚchunk©Zstream_contentsr   úOC:\Users\shubh\Videos\agent\nova\Lib\site-packages\anyio/_core/_subprocesses.pyÚdrain_streamQ   s   €ÿz!run_process.<locals>.drain_streamNz&only one of stdin and input is allowed©r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r   r   )r7   r8   r9   r1   r5   r:   )Ú
ValueErrorÚopen_processr	   r   r   Z
start_soonr   r   ÚsendÚacloseÚwaitÚ
returncoder
   r   r1   r   )r*   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   rA   ÚprocessÚtgÚoutputÚerrorsr   r?   r@   Úrun_process   sJ   €;
ò
*õ(ïrM   rB   r   c                Ã  st   �i }|
dur|
|d< |dur||d< |dur||d< |dkr#||d< t ƒ j| f|||||||||	dœ	|¤ŽI dH S )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   rD   )r*   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   Úkwargsr   r   r@   rD   €   s2   €1ÿöõrD   )"r*   r+   r   r,   r   r-   r   r-   r   r-   r   r.   r    r/   r!   r0   r"   r   r#   r1   r$   r.   r%   r2   r&   r3   r'   r3   r(   r4   r)   r1   r5   r6   )r*   r+   r   r-   r   r-   r   r-   r    r/   r!   r0   r"   r   r#   r1   r$   r.   r%   r2   r&   r3   r'   r3   r(   r4   r)   r1   r5   r   )$Ú
__future__r   ÚsysÚcollections.abcr   r   r   r   Úior   Úosr   Ú
subprocessr	   r
   r   Útypingr   r   r   r   Úabcr   Z
_eventloopr   Ú_tasksr   Úversion_infor   Ztyping_extensionsÚstrÚbytesr   Ú__annotations__rM   rD   r   r   r   r@   Ú<module>   sX    
ïmñ