wL idZddlZddlZddlZddlZddlmZmZmZm Z m Z ddl m Z deede fdZejfde ee efd eej"geeze zfdeeze zfd Zd Zd Zd ZddZy)zCommon utilities for the various process_* implementations. This file is only meant to be imported by the platform-specific implementations of subprocess utilities, and it contains tools that are common to all of them. N)IOAnyCallableListUnion) py3compatstreamreturncddl} |jS#t$r$}|j|jk7rYd}~yd}~wwxYw)zRead from a pipe ignoring EINTR errors. This is necessary because when reading from pipes with GUI event loops running in the background, often interrupts are raised that stop the command from completing.rN)errnoreadIOErrorEINTR)r r errs c/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/IPython/utils/_process_common.pyread_no_interruptrs@ {{}  99 #  $s A>Acmdcallbackc Rtjjtjjtjdk(r|t j k7rd}nd}t|t}d}|r8tjdk(r%dtjvrtjd}t j|||t j t j ||} ||}|j! |j!|j#|j |j'|S|S#t$rLtdtjjtjjd}YwxYw#t$$rYwxYw#t$$rY|SwxYw#|j1 |j!|j#n#t$$rYnwxYw|j! |j'w#t$$rYwwxYwwxYw) aOpen a command in a shell subprocess and execute a callback. This function provides common scaffolding for creating subprocess.Popen() calls. It creates a Popen object and then calls the callback with it. Parameters ---------- cmd : str or list A command to be executed by the system, using :class:`subprocess.Popen`. If a string is passed, it will be run in the system shell. If a list is passed, it will be used directly as arguments. callback : callable A one-argument function that will be called with the Popen object. stderr : file descriptor number, optional By default this is set to ``subprocess.PIPE``, but you can also pass the value ``subprocess.STDOUT`` to force the subprocess' stderr to go into the same file descriptor as its stdout. This is useful to read stdout and stderr combined in the order they are generated. Returns ------- The return value of the provided callback is returned. win32FTNposixSHELL)shell executablestdinstdoutstderr close_fdsz^C)sysrflushrplatform subprocessPIPE isinstancestrosnameenvironPopenKeyboardInterruptprint returncode terminatepollOSErrorkill)rrrrrrpouts rprocess_handlerr3,s8JJJJ ||w6Z__#<  sC EJ G#2::(=ZZ( E$.) * &#,  .Aqk <<    <<   J3J/  d         J  <<      <<     s-E F/F*AFF:FF: F'&F'* F76F7: H& G)(H&) G52H&4G55H&HH& H"H&!H""H&ct|dtj}|yt|tsJt j |S)aRun a command and return its stdout/stderr as a string. Parameters ---------- cmd : str or list A command to be executed in the system shell. Returns ------- output : str A string containing the combination of stdout and stderr from the subprocess, in whatever order the subprocess originally wrote to its file descriptors (so the order of the information in this string is the correct order as would be seen if running the command in a terminal). c(|jdS)Nr communicater1s rzgetoutput..s);)r3r"STDOUTr$bytesrdecode)rr2s r getoutputr?xsB #;Z=N=N OC { c5 !! !   C  r:ct|ddS)a Return (standard output, standard error) 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 stderr : str N)get_output_error_code)rs rgetoutputerrorrCs ! %bq ))r:ct|d\}}|dd|jfS|\}}tj|tj||jfS)aEReturn (standard output, standard error, return code) 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 stderr : str returncode: int c&|j|fS)Nr6r8s rr9z'get_output_error_code..s!0Dr:r;)r3r,rr>)rout_errr1r2rs rrBrBs[$!&DEJGQ2q||##HC   C )"2"23"7 EEr:ctj||}d|_d|_g} |jt |#t $rY|St $r"|r|j|jY|SwxYw)aSplit a command line's arguments in a shell-like manner. This is a modified version of the standard library's shlex.split() function, but with a default of posix=False for splitting, so that quotes in inputs are respected. if strict=False, then any errors shlex.split would raise will result in the unparsed remainder being the last element of the list, rather than raising. This is because we sometimes use arg_split to parse things other than command-line args. )rTr;)shlexwhitespace_split commentersappendnext StopIteration ValueErrortoken)srstrictlextokenss r arg_splitrTs ++au %CCCN F   MM$s) $    M  MM#)) $  M sA A;&A;:A;)FT)__doc__r&rHr"rtypingrrrrr IPython.utilsrr=rr#r%r)intr3r?rCrBrTr:rrZs   11# bg % $ ??I sDI~ I (()39u+<<=I 3Y IX!.*"F0#r: