
    ,hJ                    &   U d dl 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mZ d dlm	Z	 d dl
mZmZmZmZmZmZmZ d dlZddlmZ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m Z  er(d dl!Z!d dl"m#Z#m$Z$m%Z%m&Z&m'Z' d dl(m)Z) d dl*m+Z+m,Z, ddl-m.Z.m/Z/ ee0e1ejd                  e0   ejd                  e1   f   Z3de4d<   de4d<   erdHdZ5ddlm6Z6m7Z7 n	dZ8	 d dlm5Z5  G d de      ZCe  G d d e!             ZDdddd"	 	 	 	 	 	 	 	 	 	 	 dId#ZEdJd$ZFdJd%ZGd&ddddej                  d'	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dKd(ZI G d) d*ed+      ZJer'ejt                  d,k(  rC G d- d.eJd+      ZKdd/	 	 	 	 	 	 	 dLd0ZLej                  dddddd1	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dMd2ZMy G d3 d4eJd+      ZN G d5 d6eNd+      ZO G d7 d8eOd+      ZP G d9 d:ed+      ZQej                  d;k\  rePZS G d< d=ePeQ      ZTn,ej                  d>k\  reOZS G d? d=eOeQ      ZTneNZS G d@ d=eNeQ      ZTedd/	 	 	 	 	 	 	 	 	 dNdA       ZLedddB	 	 	 	 	 	 	 	 	 dOdC       ZLedd/	 	 	 	 	 	 	 	 	 dPdD       ZMedddB	 	 	 	 	 	 	 	 	 dQdE       ZMyeEZLdFxeL_U        eL_V        eIZMdGxeM_U        eM_V        y# e9$ r ejt                  dk(  rld dl;Z; e;jx                  dd      Z=e;j|                  e=j~                  _@        e;j|                  e;j|                  e;j|                  ge=j~                  _A        dZBdHdZ5ndZ8Y <w xY w)R    )annotationsN)	ExitStack)partial)TYPE_CHECKINGFinalLiteralProtocol	TypedDictUnionoverload   )ClosedResourceError
TaskStatus)StapledStream)create_pipe_from_child_outputcreate_pipe_to_child_stdinwait_child_exiting)Lock)NoPublicConstructorfinal)	AwaitableCallableIterableMappingSequence)TextIOWrapper)	TypeAliasUnpack)ReceiveStream
SendStreamr   StrOrBytesPathboolcan_try_pidfd_openc                     y N )fdflagss     R/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/trio/_subprocess.py
pidfd_openr*   3           )ClosableReceiveStreamClosableSendStreamT)r*   linux)	use_errnoi  c                    t         j                  t        | |      }|dk  r3t        j                         }t        |t        j                  |            |S Nr   )_cdll_for_pidfd_opensyscall__NR_pidfd_openctypes	get_errnoOSErrorosstrerror)r'   r(   resulterrs       r)   r*   r*   W   sF    -55or5QA: **,C!#r{{3'788r,   Fc                      e Zd ZdZddZy)	HasFilenoz;Represents any file-like object that has a file descriptor.c                     y r%   r&   selfs    r)   filenozHasFileno.filenoe   r+   r,   Nreturnint)__name__
__module____qualname____doc__rB   r&   r,   r)   r>   r>   b   s    E r,   r>   c                      e Zd ZU dZdZded<   dZded<   dZded<   dZded	<   	 	 	 	 	 	 	 	 	 	 dd
Z	ddZ
edd       ZddZddZddZddZddZddZy)Processu  A child process. Like :class:`subprocess.Popen`, but async.

    This class has no public constructor. The most common way to get a
    `Process` object is to combine `Nursery.start` with `run_process`::

       process_object = await nursery.start(run_process, ...)

    This way, `run_process` supervises the process and makes sure that it is
    cleaned up properly, while optionally checking the return value, feeding
    it input, and so on.

    If you need more control – for example, because you want to spawn a child
    process that outlives your program – then another option is to use
    `trio.lowlevel.open_process`::

       process_object = await trio.lowlevel.open_process(...)

    Attributes:
      args (str or list): The ``command`` passed at construction time,
          specifying the process to execute and its arguments.
      pid (int): The process ID of the child process managed by this object.
      stdin (trio.abc.SendStream or None): A stream connected to the child's
          standard input stream: when you write bytes here, they become available
          for the child to read. Only available if the :class:`Process`
          was constructed using ``stdin=PIPE``; otherwise this will be None.
      stdout (trio.abc.ReceiveStream or None): A stream connected to
          the child's standard output stream: when the child writes to
          standard output, the written bytes become available for you
          to read here. Only available if the :class:`Process` was
          constructed using ``stdout=PIPE``; otherwise this will be None.
      stderr (trio.abc.ReceiveStream or None): A stream connected to
          the child's standard error stream: when the child writes to
          standard error, the written bytes become available for you
          to read here. Only available if the :class:`Process` was
          constructed using ``stderr=PIPE``; otherwise this will be None.
      stdio (trio.StapledStream or None): A stream that sends data to
          the child's standard input and receives from the child's standard
          output. Only available if both :attr:`stdin` and :attr:`stdout` are
          available; otherwise this will be None.

    Fr   universal_newlinesNencodingerrorsobject_wait_for_exit_datac                   || _         || _        || _        || _        d | _        | j                  1| j                  %t        | j                  | j                        | _        t               | _        d | _        t        r1	 t        | j                   j                  d      }t        |      | _        | j                   j                  | _        | j                   j                  | _        y # t        $ r Y Bw xY wr2   )_procstdinstdoutstderrstdior   r   
_wait_lock_pidfdr#   r*   pidopenr8   args)rA   popenrS   rT   rU   r'   s         r)   __init__zProcess.__init__   s     

FJ
::!dkk&=&tzz4;;?DJ $,0'$TZZ^^Q7 #2h?Czz	

  
 s   > C% %	C10C1c                    | j                   }|d| j                   }n|dk  rd|  }nd| }d| j                  d| dS )Nzrunning with PID r   zexited with signal zexited with status z<trio.Process z: >)
returncoderY   r[   )rA   r`   statuss      r)   __repr__zProcess.__repr__   s[    __
(
3FA~.
{m<.zl;		}Bvha88r,   c                ^    | j                   j                         }|| j                          |S )a  The exit status of the process (an integer), or ``None`` if it's
        still running.

        By convention, a return code of zero indicates success.  On
        UNIX, negative values indicate termination due to a signal,
        e.g., -11 if terminated by signal 11 (``SIGSEGV``).  On
        Windows, a process that exits due to a call to
        :meth:`Process.terminate` will have an exit status of 1.

        Unlike the standard library `subprocess.Popen.returncode`, you don't
        have to call `poll` or `wait` to update this attribute; it's
        automatically updated as needed, and will always give you the latest
        information.

        )rR   poll_close_pidfd)rA   r;   s     r)   r`   zProcess.returncode   s+    " "r,   c                    | j                   Yt        j                  j                  | j                   j	                                | j                   j                          d | _         y y r%   )rX   triolowlevelnotify_closingrB   closer@   s    r)   re   zProcess._close_pidfd   sG    ;;"MM((););)=>KKDK #r,   c                x  K   | j                   4 d{    | j                         | j                  bt        j                  t
              5  t        j                  j                  | j                  j                                d{    ddd       nt        |        d{    | j                  j                          | j                          ddd      d{    | j                  j                  J | j                  j                  S 7 7 # 1 sw Y   uxY w7 |7 D# 1 d{  7  sw Y   TxY ww)z{Block until the process exits.

        Returns:
          The exit status of the process; see :attr:`returncode`.
        N)rW   rd   rX   
contextlibsuppressr   rg   rh   wait_readablerB   r   rR   waitre   r`   r@   s    r)   ro   zProcess.wait   s	     ?? 	$ 	$yy{";;*#,,+ P #mm99$++:L:L:NOOOP P
 -T222 

!!!#!	$ 	$" zz$$00zz$$$%	$ PP P
 3	$ 	$ 	$ 	$sz   D:DD:6D%;DD	DD%$D!%.D%D:D#3D:DD	D%#D:%D7+D.,D73D:c                    | j                   S )a  Returns the exit status of the process (an integer), or ``None`` if
        it's still running.

        Note that on Trio (unlike the standard library `subprocess.Popen`),
        ``process.poll()`` and ``process.returncode`` always give the same
        result. See `returncode` for more details. This method is only
        included to make it easier to port code from `subprocess`.

        )r`   r@   s    r)   rd   zProcess.poll  s     r,   c                :    | j                   j                  |       y)a,  Send signal ``sig`` to the process.

        On UNIX, ``sig`` may be any signal defined in the
        :mod:`signal` module, such as ``signal.SIGINT`` or
        ``signal.SIGTERM``. On Windows, it may be anything accepted by
        the standard library :meth:`subprocess.Popen.send_signal`.
        N)rR   send_signal)rA   sigs     r)   rr   zProcess.send_signal  s     	

s#r,   c                8    | j                   j                          y)af  Terminate the process, politely if possible.

        On UNIX, this is equivalent to
        ``send_signal(signal.SIGTERM)``; by convention this requests
        graceful termination, but a misbehaving or buggy process might
        ignore it. On Windows, :meth:`terminate` forcibly terminates the
        process in the same manner as :meth:`kill`.
        N)rR   	terminater@   s    r)   ru   zProcess.terminate  s     	

r,   c                8    | j                   j                          y)a  Immediately terminate the process.

        On UNIX, this is equivalent to
        ``send_signal(signal.SIGKILL)``.  On Windows, it calls
        ``TerminateProcess``. In both cases, the process cannot
        prevent itself from being killed, but the termination will be
        delivered asynchronously; use :meth:`wait` if you want to
        ensure the process is actually dead before proceeding.
        N)rR   killr@   s    r)   rw   zProcess.kill%  s     	

r,   )
r\   zsubprocess.Popen[bytes]rS   zSendStream | NonerT   ReceiveStream | NonerU   rx   rD   None)rD   str)rD   
int | NonerD   ry   rC   )rs   zsignal.Signals | intrD   ry   )rF   rG   rH   rI   rL   __annotations__rM   rN   rP   r]   rb   propertyr`   re   ro   rd   rr   ru   rw   r&   r,   r)   rK   rK   h   s    (V !&%HeFE
 #'&#'&#' !#' %	#'
 %#' 
#'J	9  *%4
$	
r,   rK   )	metaclassrS   rT   rU   c                 K   dD ]"  }|j                  |      st        d| d       t        j                  dk(  rdt	        | t
        t        f      r|j                  d      st        d      t	        | t
        t        f      s|j                  d      rt        d      d}d}d}t               5 }	t               5 }
|t        j                  k(  rHt               \  }}|	j                  t        j                  |       |
j                  |j                         |t        j                  k(  rHt               \  }}|	j                  t        j                  |       |
j                  |j                         |t        j                  k(  r|^|}n[|t        j                  k(  rHt               \  }}|	j                  t        j                  |       |
j                  |j                         t        j                   j#                  t%        t        j&                  | f|||d	|       d{   }|
j)                          ddd       ddd       t*        j-                  |||      S 7 <# 1 sw Y   +xY w# 1 sw Y   /xY ww)
a
  Execute a child program in a new process.

    After construction, you can interact with the child process by writing data to its
    `~trio.Process.stdin` stream (a `~trio.abc.SendStream`), reading data from its
    `~trio.Process.stdout` and/or `~trio.Process.stderr` streams (both
    `~trio.abc.ReceiveStream`\s), sending it signals using `~trio.Process.terminate`,
    `~trio.Process.kill`, or `~trio.Process.send_signal`, and waiting for it to exit
    using `~trio.Process.wait`. See `trio.Process` for details.

    Each standard stream is only available if you specify that a pipe should be created
    for it. For example, if you pass ``stdin=subprocess.PIPE``, you can write to the
    `~trio.Process.stdin` stream, else `~trio.Process.stdin` will be ``None``.

    Unlike `trio.run_process`, this function doesn't do any kind of automatic
    management of the child process. It's up to you to implement whatever semantics you
    want.

    Args:
      command: The command to run. Typically this is a sequence of strings or
          bytes such as ``['ls', '-l', 'directory with spaces']``, where the
          first element names the executable to invoke and the other elements
          specify its arguments. With ``shell=True`` in the ``**options``, or on
          Windows, ``command`` can be a string or bytes, which will be parsed
          following platform-dependent :ref:`quoting rules
          <subprocess-quoting>`. In all cases ``command`` can be a path or a
          sequence of paths.
      stdin: Specifies what the child process's standard input
          stream should connect to: output written by the parent
          (``subprocess.PIPE``), nothing (``subprocess.DEVNULL``),
          or an open file (pass a file descriptor or something whose
          ``fileno`` method returns one). If ``stdin`` is unspecified,
          the child process will have the same standard input stream
          as its parent.
      stdout: Like ``stdin``, but for the child process's standard output
          stream.
      stderr: Like ``stdin``, but for the child process's standard error
          stream. An additional value ``subprocess.STDOUT`` is supported,
          which causes the child's standard output and standard error
          messages to be intermixed on a single standard output stream,
          attached to whatever the ``stdout`` option says to attach it to.
      **options: Other :ref:`general subprocess options <subprocess-options>`
          are also accepted.

    Returns:
      A new `trio.Process` object.

    Raises:
      OSError: if the process spawning fails, for example because the
         specified command could not be found.

    )rL   textrM   rN   bufsizezLtrio.Process only supports communicating over unbuffered byte streams; the 'z' option is not supportedposixshellzQcommand must be a sequence (not a string or bytes) if shell=False on UNIX systemszPcommand must be a string or bytes (not a sequence) if shell=True on UNIX systemsNr   )get	TypeErrorr9   name
isinstancerz   bytesr   
subprocessPIPEr   callbackrj   r   STDOUTrg   	to_threadrun_syncr   Popenpop_allrK   _create)commandrS   rT   rU   optionskey
trio_stdintrio_stdouttrio_stderralways_cleanupcleanup_on_failr\   s               r)   _open_processr   2  sF    v O ;;s1145NP  
ww'gU|,W[[5I.  'C<0W[[5I- 
 -1J04K04K 
 #"	 #"JOO# : <J##BHHe4$$Z%5%56Z__$"?"AK##BHHf5$$[%6%67Z&&& !z&"?"AK##BHHf5$$[%6%67nn--    	
 	
 	!G#" #"J ??5*k;GG	
1#" #" #" #"sN   I<BI<1I0<E)I$%I"&I$:I0 I<"I$$I-	)I00I95I<c           	        K   	 | j                          y # t        $ r0}t        j                  t	        d| d|      d       Y d }~y d }~ww xY ww)NzTerminateProcess on z failed with: r   
stacklevel)ru   r8   warningswarnRuntimeWarningpexcs     r)   _windows_deliver_cancelr     sM     
	 
1!nSGLM	
 	

s*   A A	A&A	A	AAc           	     L  K   	 | j                          t        j                  d       d {    t        j                  t        d| d      d       | j                          y 7 9# t        $ r0}t        j                  t        d| d|      d       Y d }~y d }~ww xY ww)N   zprocess z` ignored SIGTERM for 5 seconds. (Maybe you should pass a custom deliver_cancel?) Trying SIGKILL.r   r   ztried to kill process z, but failed with: )ru   rg   sleepr   r   r   rw   r8   r   s     r)   _posix_deliver_cancelr     s     
	jjm1%  " "
 	
 	
 	  
3A58KC7ST	
 	

s>   B$(A( A&8A( %B$&A( (	B!1&BB$B!!B$r,   )rS   capture_stdoutcapture_stderrcheckdeliver_canceltask_statusc                 K   t        |t              rt        d      |t        j                  u ru|t
        j                  u rt        d      |j                  d      t
        j                  u rt        d      |j                  d      t
        j                  u rt        d      t        |t        t        t        f      r|t
        j                  |d<   nd||d<   |r"d|v rt        d	      t
        j                  |d<   |r"d|v rt        d
      t
        j                  |d<   5t        j                  dk(  rt        nt        j                  dk(  sJ t        g }g }	dfd}
	 	 	 	 	 	 dd}t!        | fi | d{   t        j"                         4 d{   }	 8j$                  J |j'                  |
j$                         d_        d_        |r9j*                  J |j'                  |j*                  |       d_        d_        |r2j,                  J |j'                  |j,                  |	       d_        |j/                         j1                          d{    ddd      d{    |rdj9                  |      nd}|rdj9                  |	      nd}j:                  r/|r-t        j<                  j:                  j>                  ||      j:                  J t        j@                  j>                  j:                  ||      S 7 7 7 # t2        $ r t        j4                  d      5  t        j4                  d      dfd}|j'                  |       j1                          d{  7   j7                           # 1 sw Y   nxY wY ?w xY w7 8# 1 d{  7  sw Y   IxY ww)u '  Run ``command`` in a subprocess and wait for it to complete.

    This function can be called in two different ways.

    One option is a direct call, like::

        completed_process_info = await trio.run_process(...)

    In this case, it returns a :class:`subprocess.CompletedProcess` instance
    describing the results. Use this if you want to treat a process like a
    function call.

    The other option is to run it as a task using `Nursery.start` – the enhanced version
    of `~Nursery.start_soon` that lets a task pass back a value during startup::

        process = await nursery.start(trio.run_process, ...)

    In this case, `~Nursery.start` returns a `Process` object that you can use
    to interact with the process while it's running. Use this if you want to
    treat a process like a background task.

    Either way, `run_process` makes sure that the process has exited before
    returning, handles cancellation, optionally checks for errors, and
    provides some convenient shorthands for dealing with the child's
    input/output.

    **Input:** `run_process` supports all the same ``stdin=`` arguments as
    `subprocess.Popen`. In addition, if you simply want to pass in some fixed
    data, you can pass a plain `bytes` object, and `run_process` will take
    care of setting up a pipe, feeding in the data you gave, and then sending
    end-of-file. The default is ``b""``, which means that the child will receive
    an empty stdin. If you want the child to instead read from the parent's
    stdin, use ``stdin=None``.

    **Output:** By default, any output produced by the subprocess is
    passed through to the standard output and error streams of the
    parent Trio process.

    When calling `run_process` directly, you can capture the subprocess's output by
    passing ``capture_stdout=True`` to capture the subprocess's standard output, and/or
    ``capture_stderr=True`` to capture its standard error. Captured data is collected up
    by Trio into an in-memory buffer, and then provided as the
    :attr:`~subprocess.CompletedProcess.stdout` and/or
    :attr:`~subprocess.CompletedProcess.stderr` attributes of the returned
    :class:`~subprocess.CompletedProcess` object. The value for any stream that was not
    captured will be ``None``.

    If you want to capture both stdout and stderr while keeping them
    separate, pass ``capture_stdout=True, capture_stderr=True``.

    If you want to capture both stdout and stderr but mixed together
    in the order they were printed, use: ``capture_stdout=True, stderr=subprocess.STDOUT``.
    This directs the child's stderr into its stdout, so the combined
    output will be available in the `~subprocess.CompletedProcess.stdout`
    attribute.

    If you're using ``await nursery.start(trio.run_process, ...)`` and want to capture
    the subprocess's output for further processing, then use ``stdout=subprocess.PIPE``
    and then make sure to read the data out of the `Process.stdout` stream. If you want
    to capture stderr separately, use ``stderr=subprocess.PIPE``. If you want to capture
    both, but mixed together in the correct order, use ``stdout=subprocess.PIPE,
    stderr=subprocess.STDOUT``.

    **Error checking:** If the subprocess exits with a nonzero status
    code, indicating failure, :func:`run_process` raises a
    :exc:`subprocess.CalledProcessError` exception rather than
    returning normally. The captured outputs are still available as
    the :attr:`~subprocess.CalledProcessError.stdout` and
    :attr:`~subprocess.CalledProcessError.stderr` attributes of that
    exception.  To disable this behavior, so that :func:`run_process`
    returns normally even if the subprocess exits abnormally, pass ``check=False``.

    Note that this can make the ``capture_stdout`` and ``capture_stderr``
    arguments useful even when starting `run_process` as a task: if you only
    care about the output if the process fails, then you can enable capturing
    and then read the output off of the `~subprocess.CalledProcessError`.

    **Cancellation:** If cancelled, `run_process` sends a termination
    request to the subprocess, then waits for it to fully exit. The
    ``deliver_cancel`` argument lets you control how the process is terminated.

    .. note:: `run_process` is intentionally similar to the standard library
       `subprocess.run`, but some of the defaults are different. Specifically, we
       default to:

       - ``check=True``, because `"errors should never pass silently / unless
         explicitly silenced" <https://www.python.org/dev/peps/pep-0020/>`__.

       - ``stdin=b""``, because it produces less-confusing results if a subprocess
         unexpectedly tries to read from stdin.

       To get the `subprocess.run` semantics, use ``check=False, stdin=None``.

    Args:
      command (list or str): The command to run. Typically this is a
          sequence of strings such as ``['ls', '-l', 'directory with spaces']``,
          where the first element names the executable to invoke and the other
          elements specify its arguments. With ``shell=True`` in the
          ``**options``, or on Windows, ``command`` may alternatively
          be a string, which will be parsed following platform-dependent
          :ref:`quoting rules <subprocess-quoting>`.

      stdin (:obj:`bytes`, subprocess.PIPE, file descriptor, or None): The
          bytes to provide to the subprocess on its standard input stream, or
          ``None`` if the subprocess's standard input should come from the
          same place as the parent Trio process's standard input. As is the
          case with the :mod:`subprocess` module, you can also pass a file
          descriptor or an object with a ``fileno()`` method, in which case
          the subprocess's standard input will come from that file.

          When starting `run_process` as a background task, you can also use
          ``stdin=subprocess.PIPE``, in which case `Process.stdin` will be a
          `~trio.abc.SendStream` that you can use to send data to the child.

      capture_stdout (bool): If true, capture the bytes that the subprocess
          writes to its standard output stream and return them in the
          `~subprocess.CompletedProcess.stdout` attribute of the returned
          `subprocess.CompletedProcess` or `subprocess.CalledProcessError`.

      capture_stderr (bool): If true, capture the bytes that the subprocess
          writes to its standard error stream and return them in the
          `~subprocess.CompletedProcess.stderr` attribute of the returned
          `~subprocess.CompletedProcess` or `subprocess.CalledProcessError`.

      check (bool): If false, don't validate that the subprocess exits
          successfully. You should be sure to check the
          ``returncode`` attribute of the returned object if you pass
          ``check=False``, so that errors don't pass silently.

      deliver_cancel (async function or None): If `run_process` is cancelled,
          then it needs to kill the child process. There are multiple ways to
          do this, so we let you customize it.

          If you pass None (the default), then the behavior depends on the
          platform:

          - On Windows, Trio calls ``TerminateProcess``, which should kill the
            process immediately.

          - On Unix-likes, the default behavior is to send a ``SIGTERM``, wait
            5 seconds, and send a ``SIGKILL``.

          Alternatively, you can customize this behavior by passing in an
          arbitrary async function, which will be called with the `Process`
          object as an argument. For example, the default Unix behavior could
          be implemented like this::

             async def my_deliver_cancel(process):
                 process.send_signal(signal.SIGTERM)
                 await trio.sleep(5)
                 process.send_signal(signal.SIGKILL)

          When the process actually exits, the ``deliver_cancel`` function
          will automatically be cancelled – so if the process exits after
          ``SIGTERM``, then we'll never reach the ``SIGKILL``.

          In any case, `run_process` will always wait for the child process to
          exit before raising `Cancelled`.

      **options: :func:`run_process` also accepts any :ref:`general subprocess
          options <subprocess-options>` and passes them on to the
          :class:`~trio.Process` constructor. This includes the
          ``stdout`` and ``stderr`` options, which provide additional
          redirection possibilities such as ``stderr=subprocess.STDOUT``,
          ``stdout=subprocess.DEVNULL``, or file descriptors.

    Returns:

      When called normally – a `subprocess.CompletedProcess` instance
      describing the return code and outputs.

      When called via `Nursery.start` – a `trio.Process` instance.

    Raises:
      UnicodeError: if ``stdin`` is specified as a Unicode string, rather
          than bytes
      ValueError: if multiple redirections are specified for the same
          stream, e.g., both ``capture_stdout=True`` and
          ``stdout=subprocess.DEVNULL``
      subprocess.CalledProcessError: if ``check=False`` is not passed
          and the process exits with a nonzero exit status
      OSError: if an error is encountered starting or communicating with
          the process
      ExceptionGroup: if exceptions occur in ``deliver_cancel``,
          or when exceptions occur when communicating with the subprocess.
          If strict_exception_groups is set to false in the global context,
          which is deprecated, then single exceptions will be collapsed.

    .. note:: The child process runs in the same process group as the parent
       Trio process, so a Ctrl+C will be delivered simultaneously to both
       parent and child. If you don't want this behavior, consult your
       platform's documentation for starting child processes in a different
       process group.

    z$process stdin must be bytes, not strzstdout=subprocess.PIPE is only valid with nursery.start, since that's the only way to access the pipe; use nursery.start or pass the data you want to write directlyrT   zestdout=subprocess.PIPE is only valid with nursery.start, since that's the only way to access the piperU   zestderr=subprocess.PIPE is only valid with nursery.start, since that's the only way to access the piperS   Nz,can't specify both stdout and capture_stdoutz,can't specify both stderr and capture_stderrntr   c                   K   | 4 d {    	 J | j                         d {    d d d       d {    y 7 37 # t        j                  $ r Y *w xY w7 "# 1 d {  7  sw Y   y xY wwr%   )send_allrg   BrokenResourceError)streaminput_s    r)   
feed_inputz _run_process.<locals>.feed_input  sv      	 	))oof---	 	 	 .++ 		 	 	 	sm   A2>A2AAA AA2AA2 AAAAAA2A/#A&$A/+A2c                   K   | 4 d {    | 2 3 d {   }|j                  |       7 !7 6 d d d       d {  7   y # 1 d {  7  sw Y   y xY wwr%   )append)r   chunkschunks      r)   read_outputz!_run_process.<locals>.read_output  sW       	% 	%% % %ee$	%%v	% 	% 	% 	% 	%sX   A+AA/-/AA/AA>AAA	AAT)shieldc                 `   K   5           d {    d d d        y 7 # 1 sw Y   y xY wwr%   r&   )r   killer_cscopeprocs   r)   killerz_run_process.<locals>.killer  s5     & 3,T2223 323 3s    ." "	."+.r,   )outputrU   )r   r    rD   ry   )r   r   r   zlist[bytes | bytearray]rD   ry   r|   )!r   rz   UnicodeErrorrg   TASK_STATUS_IGNOREDr   r   
ValueErrorr   r   	bytearray
memoryviewr9   r   r   r   open_processopen_nurseryrS   
start_soonrV   rT   rU   startedro   BaseExceptionCancelScopecanceljoinr`   CalledProcessErrorr[   CompletedProcess)r   rS   r   r   r   r   r   r   stdout_chunksstderr_chunksr   r   nurseryr   rT   rU   r   r   r   s        `          @@@r)   _run_processr     s    ^ %ABBd...JOO#> 
 ;;x JOO3?  ;;x JOO3?  %%J78%??
  wKLL&OOwKLL&OO77d?4N77g%%2N-/M-/M%%'% 
% g111D  "  g	!zz--"":tzz:!
!
{{.."";]K"!
{{.."";]K"%))+# > )7SXXm$DF(6SXXm$DF5++OOII	
 	
 ****499doovvVVY 2"  	!!. 
 $ 0 0 =3 ""6*iik!!$$&
 
 
	%   s   E=OL'O L*!O$N>&CL/3L-4L/8ON;B$O*O-L//N8AN(N
N((N1-N84N>7N88N>;O>OOOOc                  N    e Zd ZU dZded<   ded<   ded<   ded<   d	ed
<   ded<   y)GeneralProcessArgsz"Arguments shared between all runs.int | HasFileno | NonerT   rU   r"   	close_fdszStrOrBytesPath | NonecwdzMapping[str, str] | Noneenv
executableNrF   rG   rH   rI   r}   r&   r,   r)   r   r   $  s(    ,""""O		!!%%r,   r   )totalwin32c                  0    e Zd ZU dZded<   ded<   ded<   y)	WindowsProcessArgsz*Arguments shared between all Windows runs.r"   r   zsubprocess.STARTUPINFO | NonestartupinforE   creationflagsNr   r&   r,   r)   r   r   2  s    <K66r,   r   )rS   c                  K   yw)a  Execute a child program in a new process.

            After construction, you can interact with the child process by writing data to its
            `~trio.Process.stdin` stream (a `~trio.abc.SendStream`), reading data from its
            `~trio.Process.stdout` and/or `~trio.Process.stderr` streams (both
            `~trio.abc.ReceiveStream`\s), sending it signals using `~trio.Process.terminate`,
            `~trio.Process.kill`, or `~trio.Process.send_signal`, and waiting for it to exit
            using `~trio.Process.wait`. See `trio.Process` for details.

            Each standard stream is only available if you specify that a pipe should be created
            for it. For example, if you pass ``stdin=subprocess.PIPE``, you can write to the
            `~trio.Process.stdin` stream, else `~trio.Process.stdin` will be ``None``.

            Unlike `trio.run_process`, this function doesn't do any kind of automatic
            management of the child process. It's up to you to implement whatever semantics you
            want.

            Args:
              command (list or str): The command to run. Typically this is a
                  sequence of strings such as ``['ls', '-l', 'directory with spaces']``,
                  where the first element names the executable to invoke and the other
                  elements specify its arguments. With ``shell=True`` in the
                  ``**options``, or on Windows, ``command`` may alternatively
                  be a string, which will be parsed following platform-dependent
                  :ref:`quoting rules <subprocess-quoting>`.
              stdin: Specifies what the child process's standard input
                  stream should connect to: output written by the parent
                  (``subprocess.PIPE``), nothing (``subprocess.DEVNULL``),
                  or an open file (pass a file descriptor or something whose
                  ``fileno`` method returns one). If ``stdin`` is unspecified,
                  the child process will have the same standard input stream
                  as its parent.
              stdout: Like ``stdin``, but for the child process's standard output
                  stream.
              stderr: Like ``stdin``, but for the child process's standard error
                  stream. An additional value ``subprocess.STDOUT`` is supported,
                  which causes the child's standard output and standard error
                  messages to be intermixed on a single standard output stream,
                  attached to whatever the ``stdout`` option says to attach it to.
              **options: Other :ref:`general subprocess options <subprocess-options>`
                  are also accepted.

            Returns:
              A new `trio.Process` object.

            Raises:
              OSError: if the process spawning fails, for example because the
                 specified command could not be found.

            Nr&   )r   rS   kwargss      r)   r   r   9  s     p    )r   rS   r   r   r   r   c                  K   yw)u*  Run ``command`` in a subprocess and wait for it to complete.

            This function can be called in two different ways.

            One option is a direct call, like::

                completed_process_info = await trio.run_process(...)

            In this case, it returns a :class:`subprocess.CompletedProcess` instance
            describing the results. Use this if you want to treat a process like a
            function call.

            The other option is to run it as a task using `Nursery.start` – the enhanced version
            of `~Nursery.start_soon` that lets a task pass back a value during startup::

                process = await nursery.start(trio.run_process, ...)

            In this case, `~Nursery.start` returns a `Process` object that you can use
            to interact with the process while it's running. Use this if you want to
            treat a process like a background task.

            Either way, `run_process` makes sure that the process has exited before
            returning, handles cancellation, optionally checks for errors, and
            provides some convenient shorthands for dealing with the child's
            input/output.

            **Input:** `run_process` supports all the same ``stdin=`` arguments as
            `subprocess.Popen`. In addition, if you simply want to pass in some fixed
            data, you can pass a plain `bytes` object, and `run_process` will take
            care of setting up a pipe, feeding in the data you gave, and then sending
            end-of-file. The default is ``b""``, which means that the child will receive
            an empty stdin. If you want the child to instead read from the parent's
            stdin, use ``stdin=None``.

            **Output:** By default, any output produced by the subprocess is
            passed through to the standard output and error streams of the
            parent Trio process.

            When calling `run_process` directly, you can capture the subprocess's output by
            passing ``capture_stdout=True`` to capture the subprocess's standard output, and/or
            ``capture_stderr=True`` to capture its standard error. Captured data is collected up
            by Trio into an in-memory buffer, and then provided as the
            :attr:`~subprocess.CompletedProcess.stdout` and/or
            :attr:`~subprocess.CompletedProcess.stderr` attributes of the returned
            :class:`~subprocess.CompletedProcess` object. The value for any stream that was not
            captured will be ``None``.

            If you want to capture both stdout and stderr while keeping them
            separate, pass ``capture_stdout=True, capture_stderr=True``.

            If you want to capture both stdout and stderr but mixed together
            in the order they were printed, use: ``capture_stdout=True, stderr=subprocess.STDOUT``.
            This directs the child's stderr into its stdout, so the combined
            output will be available in the `~subprocess.CompletedProcess.stdout`
            attribute.

            If you're using ``await nursery.start(trio.run_process, ...)`` and want to capture
            the subprocess's output for further processing, then use ``stdout=subprocess.PIPE``
            and then make sure to read the data out of the `Process.stdout` stream. If you want
            to capture stderr separately, use ``stderr=subprocess.PIPE``. If you want to capture
            both, but mixed together in the correct order, use ``stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT``.

            **Error checking:** If the subprocess exits with a nonzero status
            code, indicating failure, :func:`run_process` raises a
            :exc:`subprocess.CalledProcessError` exception rather than
            returning normally. The captured outputs are still available as
            the :attr:`~subprocess.CalledProcessError.stdout` and
            :attr:`~subprocess.CalledProcessError.stderr` attributes of that
            exception.  To disable this behavior, so that :func:`run_process`
            returns normally even if the subprocess exits abnormally, pass ``check=False``.

            Note that this can make the ``capture_stdout`` and ``capture_stderr``
            arguments useful even when starting `run_process` as a task: if you only
            care about the output if the process fails, then you can enable capturing
            and then read the output off of the `~subprocess.CalledProcessError`.

            **Cancellation:** If cancelled, `run_process` sends a termination
            request to the subprocess, then waits for it to fully exit. The
            ``deliver_cancel`` argument lets you control how the process is terminated.

            .. note:: `run_process` is intentionally similar to the standard library
               `subprocess.run`, but some of the defaults are different. Specifically, we
               default to:

               - ``check=True``, because `"errors should never pass silently / unless
                 explicitly silenced" <https://www.python.org/dev/peps/pep-0020/>`__.

               - ``stdin=b""``, because it produces less-confusing results if a subprocess
                 unexpectedly tries to read from stdin.

               To get the `subprocess.run` semantics, use ``check=False, stdin=None``.

            Args:
              command (list or str): The command to run. Typically this is a
                  sequence of strings such as ``['ls', '-l', 'directory with spaces']``,
                  where the first element names the executable to invoke and the other
                  elements specify its arguments. With ``shell=True`` in the
                  ``**options``, or on Windows, ``command`` may alternatively
                  be a string, which will be parsed following platform-dependent
                  :ref:`quoting rules <subprocess-quoting>`.

              stdin (:obj:`bytes`, subprocess.PIPE, file descriptor, or None): The
                  bytes to provide to the subprocess on its standard input stream, or
                  ``None`` if the subprocess's standard input should come from the
                  same place as the parent Trio process's standard input. As is the
                  case with the :mod:`subprocess` module, you can also pass a file
                  descriptor or an object with a ``fileno()`` method, in which case
                  the subprocess's standard input will come from that file.

                  When starting `run_process` as a background task, you can also use
                  ``stdin=subprocess.PIPE``, in which case `Process.stdin` will be a
                  `~trio.abc.SendStream` that you can use to send data to the child.

              capture_stdout (bool): If true, capture the bytes that the subprocess
                  writes to its standard output stream and return them in the
                  `~subprocess.CompletedProcess.stdout` attribute of the returned
                  `subprocess.CompletedProcess` or `subprocess.CalledProcessError`.

              capture_stderr (bool): If true, capture the bytes that the subprocess
                  writes to its standard error stream and return them in the
                  `~subprocess.CompletedProcess.stderr` attribute of the returned
                  `~subprocess.CompletedProcess` or `subprocess.CalledProcessError`.

              check (bool): If false, don't validate that the subprocess exits
                  successfully. You should be sure to check the
                  ``returncode`` attribute of the returned object if you pass
                  ``check=False``, so that errors don't pass silently.

              deliver_cancel (async function or None): If `run_process` is cancelled,
                  then it needs to kill the child process. There are multiple ways to
                  do this, so we let you customize it.

                  If you pass None (the default), then the behavior depends on the
                  platform:

                  - On Windows, Trio calls ``TerminateProcess``, which should kill the
                    process immediately.

                  - On Unix-likes, the default behavior is to send a ``SIGTERM``, wait
                    5 seconds, and send a ``SIGKILL``.

                  Alternatively, you can customize this behavior by passing in an
                  arbitrary async function, which will be called with the `Process`
                  object as an argument. For example, the default Unix behavior could
                  be implemented like this::

                     async def my_deliver_cancel(process):
                         process.send_signal(signal.SIGTERM)
                         await trio.sleep(5)
                         process.send_signal(signal.SIGKILL)

                  When the process actually exits, the ``deliver_cancel`` function
                  will automatically be cancelled – so if the process exits after
                  ``SIGTERM``, then we'll never reach the ``SIGKILL``.

                  In any case, `run_process` will always wait for the child process to
                  exit before raising `Cancelled`.

              **options: :func:`run_process` also accepts any :ref:`general subprocess
                  options <subprocess-options>` and passes them on to the
                  :class:`~trio.Process` constructor. This includes the
                  ``stdout`` and ``stderr`` options, which provide additional
                  redirection possibilities such as ``stderr=subprocess.STDOUT``,
                  ``stdout=subprocess.DEVNULL``, or file descriptors.

            Returns:

              When called normally – a `subprocess.CompletedProcess` instance
              describing the return code and outputs.

              When called via `Nursery.start` – a `trio.Process` instance.

            Raises:
              UnicodeError: if ``stdin`` is specified as a Unicode string, rather
                  than bytes
              ValueError: if multiple redirections are specified for the same
                  stream, e.g., both ``capture_stdout=True`` and
                  ``stdout=subprocess.DEVNULL``
              subprocess.CalledProcessError: if ``check=False`` is not passed
                  and the process exits with a nonzero exit status
              OSError: if an error is encountered starting or communicating with
                  the process

            .. note:: The child process runs in the same process group as the parent
               Trio process, so a Ctrl+C will be delivered simultaneously to both
               parent and child. If you don't want this behavior, consult your
               platform's documentation for starting child processes in a different
               process group.

            Nr&   )r   r   rS   r   r   r   r   r   s           r)   run_processr   s  s     T r   c                  b    e Zd ZU dZded<   ded<   ded<   ded<   d	ed
<   ded<   d	ed<   ded<   y)UnixProcessArgs3_9z'Arguments shared between all Unix runs.zCallable[[], object] | None
preexec_fnr"   restore_signalsstart_new_sessionzSequence[int]pass_fdszstr | int | NonegroupzIterable[str | int] | Noneextra_groupsuserrE   umaskNr   r&   r,   r)   r   r   D  s6    933!!#### $#44""Jr,   r   c                      e Zd ZU dZded<   y)UnixProcessArgs3_10z0Arguments shared between all Unix runs on 3.10+.rE   pipesizeNr   r&   r,   r)   r   r   R  s
    BMr,   r   c                      e Zd ZU dZded<   y)UnixProcessArgs3_11z0Arguments shared between all Unix runs on 3.11+.r{   process_groupNr   r&   r,   r)   r   r   W  s    B%%r,   r   c                  D    e Zd ZU dZded<   ded<   ded<   ded<   ded	<   y
)UnixRunProcessMixinz(Arguments unique to run_process on Unix.TaskStatus[Process]r   r"   r   r   r   z+Callable[[Process], Awaitable[None]] | Noner   Nr   r&   r,   r)   r   r   \  s"    :,,    KGGr,   r   )      c                      e Zd ZdZy)UnixRunProcessArgsz,Arguments for run_process on Unix with 3.11+NrF   rG   rH   rI   r&   r,   r)   r   r   j      Br,   r   )r   
   c                      e Zd ZdZy)r   z,Arguments for run_process on Unix with 3.10+Nr   r&   r,   r)   r   r   p  r  r,   c                      e Zd ZdZy)r   z+Arguments for run_process on Unix with 3.9+Nr   r&   r,   r)   r   r   v  s    Ar,   c                  K   y wr%   r&   r   rS   r   r   s       r)   r   r   y        r   )rS   r   c                  K   y wr%   r&   r  s       r)   r   r     r  r   c                  K   y wr%   r&   r  s       r)   r   r           25r   c                  K   y wr%   r&   r  s       r)   r   r     r
  r   r   r   )r'   rE   r(   rE   rD   rE   )r   )StrOrBytesPath | Sequence[StrOrBytesPath]rS   r   rT   r   rU   r   r   rO   rD   rK   )r   rK   rD   ry   )r   r  rS   7bytes | bytearray | memoryview | int | HasFileno | Noner   r"   r   r"   r   r"   r   -Callable[[Process], Awaitable[object]] | Noner   r   r   rO   rD   "subprocess.CompletedProcess[bytes])r   r  rS   r   r   Unpack[WindowsProcessArgs]rD   trio.Process)r   r  r   r   rS   r  r   r"   r   r"   r   r"   r   r  r   r  rD   r  )
r   r!   rS   r   r   Literal[True]r   Unpack[UnixProcessArgs]rD   r  )
r   Sequence[StrOrBytesPath]rS   r   r   r"   r   r  rD   r  )
r   r!   rS   r  r   r  r   Unpack[UnixRunProcessArgs]rD   r  )
r   r  rS   r  r   r"   r   r  rD   r  )W
__future__r   rl   r9   r   sysr   r   	functoolsr   typingr   r   r   r	   r
   r   r   rg   _corer   r   _highlevel_genericr   _subprocess_platformr   r   r   _syncr   _utilr   r   signalcollections.abcr   r   r   r   r   ior   typing_extensionsr   r   _abcr   r    rz   r   PathLiker!   r}   r*   r-   r.   r#   ImportErrorplatformr6   CDLLr3   c_longr4   restypeargtypesr5   r>   rK   r   r   r   r   r   r   r   r   r   r   r   r   r   version_infoUnixProcessArgsr   rF   rH   r&   r,   r)   <module>r-     s8   "  	  
        2 - 
  -PP 3/ "#ubkk#.>E@R"RS	 S
  3OO &'!P! ! F+ F FX %)%)%)|H6|H "|H #	|H
 #|H |H |H@

2 FI  DH'+'?'?~W6~W C~W 	~W
 ~W ~W B~W %~W ~W (~Wd
&% & 
||w	!35 	 -18	>8	 *8	 1	8	
 8	z 04/G/GMQ#(#(LPJ	>J	 -J	 K	J	
 !J	 !J	 J	 JJ	 1J	 0J	b	!35 		"4E 	
	&"5U 	&
	H)5 	H w&1OC%8:M C (1OC%8:M C 1OB%79L B 
 -1	#	 *	 !		
 .	 	 
	 
 -1		-	 *	 		
 .	 	 
	 
 NR	5#	5 K	5 !		5
 1	5 0	5 
	5 
 NR		5-	5 K	5 		5
 1	5 0	5 
	5 !L8FFLL5K6CCK;3Q#  $'<<7" #.6;;tt#D 39== ((0 5 ((1
 "O "'I$'s   J
 
BLL