o
    #6dq                     @  s   d dl mZ d dlmZ d dlmZ d dlmZmZm	Z	m
Z
 d dlmZmZmZmZmZmZ ddlmZ dd	lmZ dd
lmZ deedddddd&dd Zeeedddd!d'd$d%ZdS )(    )annotations)BytesIO)PathLike)DEVNULLPIPECalledProcessErrorCompletedProcess)IOAnyAsyncIterableMappingSequencecast   )Process   )get_asynclib)create_task_groupNTF)inputstdoutstderrcheckcwdenvstart_new_sessioncommand#str | bytes | Sequence[str | bytes]r   bytes | Noner   int | IO[Any] | Noner   r   boolr   "str | bytes | PathLike[str] | Noner   Mapping[str, str] | Noner   returnCompletedProcess[bytes]c             
     sp  d fdd}t | |rtnt|||||d	I d
H 4 I d
H n}	d
d
g zRt 4 I d
H >}
|	jr7|
||	jd |	jrB|
||	jd |	jrX|rX|	j|I d
H  |	j	 I d
H  |	
 I d
H  W d
  I d
H  n1 I d
H sow   Y  W n ty   |	   w W d
  I d
H  n1 I d
H sw   Y   \}}|r|	jdkrt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 stdout: either :data:`subprocess.PIPE` or :data:`subprocess.DEVNULL`
    :param stderr: one of :data:`subprocess.PIPE`, :data:`subprocess.DEVNULL` or
        :data:`subprocess.STDOUT`
    :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 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)
    :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]indexintr"   Nonec                   s6   t  }| 2 z3 d H W }|| q6 |  |< d S )N)r   writegetvalue)r$   r&   bufferchunkZstream_contents pC:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\anyio/_core/_subprocesses.pydrain_stream7   s   z!run_process.<locals>.drain_streamstdinr   r   r   r   r   Nr   r   )r$   r%   r&   r'   r"   r(   )open_processr   r   r   r   Z
start_soonr   r2   sendaclosewaitBaseExceptionkill
returncoder   r   r'   r   )r   r   r   r   r   r   r   r   r0   processtgoutputerrorsr.   r-   r/   run_process   sF   #

(
(r>   r1   r2   r   c             
     s.   t | t}t j| |||||||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 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)
    :return: an asynchronous process object

    )shellr2   r   r   r   r   r   N)
isinstancestrr   r3   )r   r2   r   r   r   r   r   r?   r.   r.   r/   r3   ^   s   
r3   )r   r   r   r   r   r   r   r   r   r   r   r    r   r!   r   r   r"   r#   )r   r   r2   r   r   r   r   r   r   r    r   r!   r   r   r"   r   )
__future__r   ior   osr   
subprocessr   r   r   r   typingr	   r
   r   r   r   r   abcr   Z
_eventloopr   _tasksr   r>   r3   r.   r.   r.   r/   <module>   s.     	M