wL iw *dZddlZddlZddlZddlZddlZddlmZmZddlm Z m Z ddlm Z ddl m Z ddlmZddlmZmZd d lmZd d lmZd d lmZmZd d lmZGddZdej:defdZde deefdZ!de de fdZ" ejFZ#e#jHjJZ%e eege%_&ee e%_'e#jPjRZ)e e)_*e ge)_& dde de+de+dee fdZdede+fdZ-y#e,$reZYwxYw)zWindows-specific implementation of process utilities. This file is only meant to be imported by process.py, not by end-users. N)POINTERc_int)HLOCALLPCWSTR)STDOUT)Thread) TracebackType)ListOptional) py3compat) arg_split)process_handlerread_no_interrupt)DEFAULT_ENCODINGcLeZdZdZdeefdZdeeedeede ddfdZ y) AvoidUNCPathaA 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) returnctj|_|jjd|_|jr!tj d|jSy)Nz\\zC:)osgetcwdpath startswith is_unc_pathchdir)selfs b/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/IPython/utils/_process_win32.py __enter__zAvoidUNCPath.__enter__.sIIIK 99//6    HHTN99 exc_type exc_value tracebackNc\|jr tj|jyy)N)rrrr)rr r!r"s r__exit__zAvoidUNCPath.__exit__:s"    HHTYY  r) __name__ __module__ __qualname____doc__r strrtype BaseExceptionr r$rrrrsQ( 8C=  4 ./ M* !    rrprc8tdfd }dfd }t|}t|}|j|j j}|t j dnn*|j |j |S)zCallback for _system.c6 jJtjjD]/}|jd}t |t j1y#t $r(}t d|t jYd}~yd}~wwxYw)NreplacefilezError reading stdout: )stdoutr splitlinesdecodeprintsys Exceptionstderr byte_linelineeencr-s r stdout_readz!_system_body..stdout_readK A88' ''.qxx8CCE -  ''Y7d, - A *1#.SZZ @ @ AA#A'' B0BBc6 jJtjjD]/}|jd}t |t j1y#t $r(}t d|t jYd}~yd}~wwxYw)Nr0r1zError reading stderr: )r9rr4r5r6r7r8r:s r stderr_readz!_system_body..stderr_readTr@rA)targetg{Gz?)rN)rrstartpolltimesleepjoin)r-r?rC stdout_thread stderr_threadresultr>s` @r _system_bodyrMDs C AA+.M+.M  > JJt    Mrcmdct5}|d|d|}t|t}t|tt dzsJ|cdddS#1swYyxYw)a7Win32 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  &&")rrrM isinstanceintr*)rNrress rsystemrUts]& 4  '+S1Cc<0#sT$Z/000  s :AAct5}|d|d|}t|dt}dddd}tj|S#1swY"xYw)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 NrPrQc(|jdS)Nr) communicate)r-s rzgetoutput..sQ]]_Q-?rr)rrrr r5)rNrouts r getoutputr[s` I4  '+S1Cc#?HI  {   C  IIs A  A commandlineposixstrictc|jdk(rgS|st|||St}t|j t j |} t|jz}|jt j|jDcgc]}||}}t|}|Scc}w#t|}wxYw)a4Split 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. )r]r^) strip py_arg_splitrCommandLineToArgvWlstripctypesbyrefrvalue from_address addressofcontents LocalFree) r\r]r^argvnresult_pointerresult_array_typeargrL_s rrrs    " $I 5H H+K,>,>,@&,,uBUV * '%++ 5 -99$$^%<%<=? F.)A .)AsAC! B;,C;C C pidcVttjjdd|S)Nr r)boolwindllkernel32 OpenProcess)rqs r check_pidrws" ++Aq#6 77r)FT).r(rer subprocessr7rGrrctypes.wintypesrrr threadingrtypesr typingr r r`r _process_commonrrbrrencodingrrPopenrSrMr)rUr[rtshell32rc arg_typesrestyperurkres_typersAttributeErrorrwr,rrrs@   !+!6?&( ( V-J$$--` 8!3!3!2) ]]F::$+WU^#< !(!1))II!(I?C!%7; cF83848 Is A4DDD