
    ^h                        S r SSKrSSKrSSKrSSKrSSKJrJr  SSKJrJ	r	  SSK
JrJr  SSKJr  SSKJrJrJr  SS	KJr  SS
KJr   " S S\5      rS rS rS r \R:                  R<                  R>                  r\\" \5      /\l         \" \5      \l!        \R:                  RD                  RF                  r#\	\#l$        \	/\#l         SS jrS r&g! \% a    \r Nf = f)zWindows-specific implementation of process utilities.

This file is only meant to be imported by process.py, not by end-users.
    N)c_intPOINTER)LPCWSTRHLOCAL)STDOUTTimeoutExpired)Thread   )read_no_interruptprocess_handler	arg_split)	py3compat)DEFAULT_ENCODINGc                   $    \ rS rSrSrS rS rSrg)AvoidUNCPath%   a  A context manager to protect command execution from UNC paths.

In the Win32 API, commands can't be invoked with the cwd being a UNC path.
This context manager temporarily changes directory to the 'C:' drive on
entering, and restores the original working directory on exit.

The context manager returns the starting working directory *if* it made a
change and None otherwise, so that users can apply the necessary adjustment
to their system calls in the event of a change.

Examples
--------
::
    cmd = 'dir'
    with AvoidUNCPath() as path:
        if path is not None:
            cmd = '"pushd %s &&"%s' % (path, cmd)
        os.system(cmd)
c                     [         R                  " 5       U l        U R                  R                  S5      U l        U R                  (       a"  [         R
                  " S5        U R                  $ g )Nz\\zC:)osgetcwdpath
startswithis_unc_pathchdir)selfs    V/home/james-whalen/.local/lib/python3.13/site-packages/IPython/utils/_process_win32.py	__enter__AvoidUNCPath.__enter__9   sI    IIK	99//6HHTN99     c                 h    U R                   (       a!  [        R                  " U R                  5        g g )N)r   r   r   r   )r   exc_type	exc_value	tracebacks       r   __exit__AvoidUNCPath.__exit__E   s     HHTYY r   )r   r   N)__name__
__module____qualname____firstlineno____doc__r   r#   __static_attributes__ r   r   r   r   %   s    &
 r   r   c                    ^ ^ [         mUU 4S jnUU 4S jn[        US9R                  5         [        US9R                  5          T R                  5       nUc  [        R
                  " S5        OU$ M.  )zCallback for _system.c                     > [        TR                  5      R                  5        H-  n U R                  TS5      n [	        U [
        R                  S9  M/     g Nreplace)file)r   stdout
splitlinesdecodeprintsyslineencps    r   stdout_read!_system_body.<locals>.stdout_readN   =    %ahh/::<D;;sI.D$SZZ( =r   c                     > [        TR                  5      R                  5        H-  n U R                  TS5      n [	        U [
        R                  S9  M/     g r.   )r   stderrr2   r3   r4   r5   r6   s    r   stderr_read!_system_body.<locals>.stderr_readS   r<   r   )targetg{Gz?)r   r	   startpolltimesleep)r9   r:   r?   resultr8   s   `   @r   _system_bodyrG   J   sa    
C)
)
 +$$&
+$$&
 >JJtM r   c                     [        5        nUb
  SU< SU < 3n [        U [        5      sSSS5        $ ! , (       d  f       g= f)a  Win32 version of os.system() that works with network shares.

Note that this implementation returns None, as meant for use in IPython.

Parameters
----------
cmd : str or list
    A command to be executed in the system shell.

Returns
-------
int : child process' exit code.
N"pushd  &&")r   r   rG   )cmdr   s     r   systemrL   f   s/    & 
4'+S1CsL1 
s	   2
A c                     [        5        nUb
  SU< SU < 3n [        U S [        5      nSSS5        Wc  Sn[        R                  " U5      $ ! , (       d  f       N)= f)zReturn standard output of executing cmd in a shell.

Accepts the same arguments as os.system().

Parameters
----------
cmd : str or list
    A command to be executed in the system shell.

Returns
-------
stdout : str
NrI   rJ   c                 (    U R                  5       S   $ )Nr   )communicate)r9   s    r   <lambda>getoutput.<locals>.<lambda>   s    Q]]_Q-?r   r   )r   r   r   r   r3   )rK   r   outs      r   	getoutputrS   ~   sT     
4'+S1Cc#?H 

 {C   
s    A
Ac                    U R                  5       S:X  a  / $ U(       d
  [        XUS9$ [        5       n[        [        R
                  " U R                  5       5      [        R                  " U5      5      n[        UR                  -  nUR                  [        R                  " UR                  5      5       Vs/ s H  ofPM     nn[        U5      nU$ s  snf )a  Split a command line's arguments in a shell-like manner.

This is a special version for windows that use a ctypes call to CommandLineToArgvW
to do the argv splitting. The posix parameter is ignored.

If strict=False, process_common.arg_split(...strict=False) is used instead.
 )posixstrict)strippy_arg_splitr   CommandLineToArgvWr   cast_unicodelstripctypesbyrefr   valuefrom_address	addressofcontents	LocalFree)	commandlinerV   rW   argvnresult_pointerresult_array_typeargrF   retvals	            r   r   r      s     "$IHH+I,B,B;CUCUCW,XZ`ZfZfglZmn#ekk1!2!?!?@P@PQ_QhQh@i!jk!j##!jk>* ls   8Cc                 j    [        [        R                  R                  R	                  SSU 5      5      $ )Nr
   r   )boolr]   windllkernel32OpenProcess)pids    r   	check_pidrp      s(     &&221Qs;<<r   )FT)'r)   r   r5   r]   rD   r   r   ctypes.wintypesr   r   
subprocessr   r   	threadingr	   _process_commonr   r   r   rY   rU   r   encodingr   objectr   rG   rL   rS   rl   shell32rZ   	arg_typesrestyperm   rc   res_typeAttributeErrorrp   r+   r   r   <module>r|      s   " 
 
   ! + -  [ Z  &" 6 " J820!0..AA$+WU^#< !(!1&&00II!(I.=  Is   A0C CC