wL iXdZddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z m Z Gdd Zd d Zd d Zy)z IO related utilities. N)Path)warn)undoc) CapturedIOcapture_outputc6eZdZdZd dZdZdZdZdZdZ y) TeezA class to duplicate an output stream to stdout/err. This works in a manner very similar to the Unix 'tee' command. When the object is closed or deleted, it closes the original file given to it for duplication. c|dvrtd|zt|drt|dr||_nd|vrdnd}t||||_||_t t ||_tt ||d |_ y) aNConstruct a new Tee object. Parameters ---------- file_or_name : filename or open filehandle (writable) File that will be duplicated mode : optional, valid mode for open(). If a filename was give, open with this mode. channel : str, one of ['stdout', 'stderr'] )stdoutstderrzInvalid channel spec %swriteseekbNutf-8encodingF) ValueErrorhasattrfileopenchannelgetattrsysostreamsetattr_closed)self file_or_namemoderrs V/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/IPython/utils/io.py__init__z Tee.__init__!s} . .6@A A < )glF.K$DI"d{tH\4(CDI sG, Wd# c|jtt|j|j|j j d|_y)z'Close the file and restore the channel.TN)flushrrrrrcloserrs r!r&z Tee.close9s4 T\\4<<0  r#c|jj||jj||jjy)zWrite data to both channels.N)rrrr%)rdatas r!rz Tee.write@s4  4  r#cl|jj|jjy)zFlush both channels.N)rr%rr's r!r%z Tee.flushFs   r#c>|js|jyy)N)rr&r's r!__del__z Tee.__del__Ks|| JJLr#cy)NFr's r!isattyz Tee.isattyOsr#N)wr ) __name__ __module__ __qualname____doc__r"r&rr%r,r/r.r#r!r r s%0  r#r c:ddddd}d}||jvr4 t|dzj}|s|}||jvr4||S#t$r|r|}t dY2t $r#||jvr |}t nY\wxYw)aAsks a question and returns a boolean (y/n) answer. If default is given (one of 'y','n'), it is used if the user input is empty. If interrupt is given (one of 'y','n'), it is used if the user presses Ctrl-C. Otherwise the question is repeated until an answer is given. An EOF is treated as the default answer. If there is no default, an exception is raised to prevent infinite loops. Valid answers are: y/yes/n/no (match is not case sensitive).TF)ynyesnoN  )keysinputlowerKeyboardInterruptprintEOFError)promptdefault interruptanswersanss r! ask_yes_norGRsE%8G C W\\^ # s #))+C W\\^ # 3<!  $K ',,.( s AB/(BBctj|d}tt|dd5}|j ||j ddd|S#1swY|SxYw)aMake a temporary python file, return filename and filehandle. Parameters ---------- src : string or list of strings (no need for ending newlines if list) Source code to be written to the file. ext : optional, string Extension for the generated file. Returns ------- (filename, open filehandle) It is the caller's responsibility to close the open file and unlink it. rr0rrN)tempfilemkstemprrrr%)srcextfnamefs r! temp_pyfilerOts]   S !! $E d5k3 1Q     L Ls "AA&)NN)z.py)r4atexitosrrIpathlibrwarningsrIPython.utils.decoratorsrcapturerrr rGrOr.r#r!rVs: */::xDr#