Format: application/x-python-code
⬇ Download File (5.1 KB)
   1  o
   2  
   3  ��h��@s dZddlZddlZddlZddlZddlmZmZddlmZm	Z	ddl
   4  mZmZddl
   5  mZddlmZmZmZdd	lmZdd
   6  lmZGdd�de�Zd
   7  d�Zdd�Zdd�Zz$ejjjZeee�ge_ ee�e_!ejj"j#Z#e	e#_$e	ge#_ ddd�ZWne%y�eZYnwdd�Z&dS)zWindows-specific implementation of process utilities.
   8  
   9  This file is only meant to be imported by process.py, not by end-users.
  10  �N)�c_int�POINTER)�LPCWSTR�HLOCAL)�STDOUT�TimeoutExpired)�Thread�)�read_no_interrupt�process_handler�	arg_split)�	py3compat)�DEFAULT_ENCODINGc@s eZdZdZdd�Zdd�ZdS)�AvoidUNCPatha�A context manager to protect command execution from UNC paths.
  11  
  12      In the Win32 API, commands can't be invoked with the cwd being a UNC path.
  13      This context manager temporarily changes directory to the 'C:' drive on
  14      entering, and restores the original working directory on exit.
  15  
  16      The context manager returns the starting working directory *if* it made a
  17      change and None otherwise, so that users can apply the necessary adjustment
  18      to their system calls in the event of a change.
  19  
  20      Examples
  21      --------
  22      ::
  23          cmd = 'dir'
  24          with AvoidUNCPath() as path:
  25              if path is not None:
  26                  cmd = '"pushd %s &&"%s' % (path, cmd)
  27              os.system(cmd)
  28      cCs2t��|_|j�d�|_|jrt�d�|jSdS)Nz\\zC:)�os�getcwd�path�
  29  startswith�is_unc_path�chdir)�self�r�Rc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/utils/_process_win32.py�	__enter__9s
  30  
  31  zAvoidUNCPath.__enter__cCs|jrt�|j�dSdS)N)rrrr)r�exc_type�	exc_value�	tracebackrrr�__exit__Es�zAvoidUNCPath.__exit__N)�__name__�
  32  __module__�__qualname__�__doc__rrrrrrr%srcs`t���fdd�}��fdd�}t|d���t|d���	���}|dur-t�d�n|Sq)	zCallback for _system.c�2t�j���D]}|��d�}t|tjd�qdS�N�replace)�file)r
  33  �stdout�
  34  splitlines�decode�print�sys��line��enc�prr�stdout_readN��z!_system_body.<locals>.stdout_readcr"r#)r
  35  �stderrr'r(r)r*r+r-rr�stderr_readSr1z!_system_body.<locals>.stderr_read)�targetTNg{�G�z�?)rr�start�poll�time�sleep)r/r0r3�resultrr-r�_system_bodyJs�r:cCsHt��}|durd||f}t|t�Wd�S1swYdS)a7Win32 version of os.system() that works with network shares.
  36  
  37      Note that this implementation returns None, as meant for use in IPython.
  38  
  39      Parameters
  40      ----------
  41      cmd : str or list
  42          A command to be executed in the system shell.
  43  
  44      Returns
  45      -------
  46      int : child process' exit code.
  47      N�"pushd %s &&"%s)rrr:)�cmdrrrr�systemfs
  48  $�r=cCs`t��}|durd||f}t|dd�t�}Wd�n1s wY|dur+d}t�|�S)z�Return standard output of executing cmd in a shell.
  49  
  50      Accepts the same arguments as os.system().
  51  
  52      Parameters
  53      ----------
  54      cmd : str or list
  55          A command to be executed in the system shell.
  56  
  57      Returns
  58      -------
  59      stdout : str
  60      Nr;cSs|��dS)Nr)�communicate)r/rrr�<lambda>�szgetoutput.<locals>.<lambda>�)rrrr
  61  r()r<r�outrrr�	getoutput~s�
  62  rBFTcCsn|��dkrgS|st|||d�St�}t|��t�|��}t|j}dd�|�	t�
  63  |j��D�}t|�}|S)a4Split a command line's arguments in a shell-like manner.
  64  
  65          This is a special version for windows that use a ctypes call to CommandLineToArgvW
  66          to do the argv splitting. The posix parameter is ignored.
  67  
  68          If strict=False, process_common.arg_split(...strict=False) is used instead.
  69          �)�posix�strictcSsg|]}|�qSrr)�.0�argrrr�
  70  <listcomp>�szarg_split.<locals>.<listcomp>)
  71  �strip�py_arg_splitr�CommandLineToArgvW�lstrip�ctypes�byrefr�value�from_address�	addressof�contents�	LocalFree)ZcommandlinerDrEZargvnZresult_pointerZresult_array_typer9�retvalrrrr�s	
  72  rcCsttjj�dd|��S)Nr	r)�boolrM�windll�kernel32�OpenProcess)�pidrrr�	check_pid�srZ)FT)'r!rr*rMr7rrZctypes.wintypesrr�
  73  subprocessrr�	threadingrZ_process_commonr
  74  rrrJrCr
  75  �encodingr�objectrr:r=rBrV�shell32rKZ	arg_types�restyperWrSZres_type�AttributeErrorrZrrrr�<module>s8%
  76  
  77  
  78  �