Format: application/x-python-code
⬇ Download File (5.6 KB)
   1  o
   2  
   3  ��h[�@sldZddlZddlZddlZddlZddlmZdd�Zejfdd�Z	dd	�Z
   4  d
   5  d�Zdd
   6  �Zddd�Z
   7  dS)z�Common utilities for the various process_* implementations.
   8  
   9  This file is only meant to be imported by the platform-specific implementations
  10  of subprocess utilities, and it contains tools that are common to all of them.
  11  �N)�	py3compatc
  12  CsHddl}z|��WSty#}z|j|jkr�WYd}~dSd}~ww)z�Read from a pipe ignoring EINTR errors.
  13  
  14      This is necessary because when reading from pipes with GUI event loops
  15      running in the background, often interrupts are raised that stop the
  16      command from completing.rN)�errno�read�IOErrorZEINTR)�pr�err�r�Sc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/utils/_process_common.py�read_no_interrupts
  17  ���r
  18  cCsptj��tj��tjdk}t|t�}d}|r'tjdkr'dtj	vr'tj	d}t
  19  j|||t
  20  jt
  21  j||d�}zSz||�}Wnt
  22  yUtd�tj��tj��d}YnwW|jdurpz
  23  |��|��Wn	tyoYnw|jdur�z|��W|Sty�Y|Sw|S|jdur�z
  24  |��|��Wn	ty�Ynw|jdur�z|��Wwty�Ywww)a�Open a command in a shell subprocess and execute a callback.
  25  
  26      This function provides common scaffolding for creating subprocess.Popen()
  27      calls.  It creates a Popen object and then calls the callback with it.
  28  
  29      Parameters
  30      ----------
  31      cmd : str or list
  32          A command to be executed by the system, using :class:`subprocess.Popen`.
  33          If a string is passed, it will be run in the system shell. If a list is
  34          passed, it will be used directly as arguments.
  35      callback : callable
  36          A one-argument function that will be called with the Popen object.
  37      stderr : file descriptor number, optional
  38          By default this is set to ``subprocess.PIPE``, but you can also pass the
  39          value ``subprocess.STDOUT`` to force the subprocess' stderr to go into
  40          the same file descriptor as its stdout.  This is useful to read stdout
  41          and stderr combined in the order they are generated.
  42  
  43      Returns
  44      -------
  45      The return value of the provided callback is returned.
  46      �win32N�posix�SHELL)�shell�
  47  executable�stdin�stdout�stderr�	close_fdsz^C)�sysr�flushr�platform�
  48  isinstance�str�os�name�environ�
  49  subprocess�Popen�PIPE�KeyboardInterrupt�print�
  50  returncode�	terminate�poll�OSError�kill)�cmd�callbackrrrrr�outrrr	�process_handler+sj
  51  
  52  
  53  
  54  
  55  �
  56  
  57  ��
  58  
  59  �
  60  
  61  ��
  62  ��
  63  ��r)cCs(t|dd�tj�}|durdSt�|�S)a�Run a command and return its stdout/stderr as a string.
  64  
  65      Parameters
  66      ----------
  67      cmd : str or list
  68          A command to be executed in the system shell.
  69  
  70      Returns
  71      -------
  72      output : str
  73          A string containing the combination of stdout and stderr from the
  74      subprocess, in whatever order the subprocess originally wrote to its
  75      file descriptors (so the order of the information in this string is the
  76      correct order as would be seen if running the command in a terminal).
  77      cSs|��dS)Nr��communicate�rrrr	�<lambda>��zgetoutput.<locals>.<lambda>N�)r)r�STDOUTr�decode)r&r(rrr	�	getoutputps
  78  r2cCst|�dd�S)a Return (standard output, standard error) of executing cmd in a shell.
  79  
  80      Accepts the same arguments as os.system().
  81  
  82      Parameters
  83      ----------
  84      cmd : str or list
  85          A command to be executed in the system shell.
  86  
  87      Returns
  88      -------
  89      stdout : str
  90      stderr : str
  91      N�)�get_output_error_code)r&rrr	�getoutputerror�sr5cCsFt|dd��\}}|durdd|jfS|\}}t�|�t�|�|jfS)aEReturn (standard output, standard error, return code) of executing cmd
  92      in a shell.
  93  
  94      Accepts the same arguments as os.system().
  95  
  96      Parameters
  97      ----------
  98      cmd : str or list
  99          A command to be executed in the system shell.
 100  
 101      Returns
 102      -------
 103      stdout : str
 104      stderr : str
 105      returncode: int
 106      cSs|��|fS)Nr*r,rrr	r-�r.z'get_output_error_code.<locals>.<lambda>Nr/)r)r!rr1)r&Zout_errrr(rrrr	r4�s
 107  r4FTcCsntj||d�}d|_d|_g}	z	|�t|��Wnty#Y|Sty5|r,�|�|j�Y|Swq)a�Split a command line's arguments in a shell-like manner.
 108  
 109      This is a modified version of the standard library's shlex.split()
 110      function, but with a default of posix=False for splitting, so that quotes
 111      in inputs are respected.
 112  
 113      if strict=False, then any errors shlex.split would raise will result in the
 114      unparsed remainder being the last element of the list, rather than raising.
 115      This is because we sometimes use arg_split to parse things other than
 116      command-line args.
 117      )rTr/)�shlex�whitespace_split�
 118  commenters�append�next�
 119  StopIteration�
 120  ValueError�token)�sr�strict�lex�tokensrrr	�	arg_split�s$
 121  ���rB)FT)�__doc__rr6rrZ
 122  IPython.utilsrr
 123  rr)r2r5r4rBrrrr	�<module>sE