Format: application/x-python-code
⬇ Download File (4.8 KB)
   1  o
   2  
   3  ��hB�@s�dZddlZddlZddlZddlZddlmZddlmZddl	m
   4  Z
   5  ddlmZm
   6  Z
   7  Gdd	�d	e�Zdd
   8  d�Zdd
   9  d�Ze
  10  dd��Ze
  11  dd��ZdS)z
  12  IO related utilities.
  13  �N)�Path)�warn)�undoc�)�
  14  CapturedIO�capture_outputc@sBeZdZdZddd�Zdd�Zdd	�Zd
  15  d�Zdd
  16  �Zdd�Z	dS)�Teez�A class to duplicate an output stream to stdout/err.
  17  
  18      This works in a manner very similar to the Unix 'tee' command.
  19  
  20      When the object is closed or deleted, it closes the original file given to
  21      it for duplication.
  22      �w�stdoutcCsx|dvr
  23  td|��t|d�rt|d�r||_nd|vrdnd}t|||d�|_||_tt|�|_tt||�d	|_	dS)
  24  aNConstruct a new Tee object.
  25  
  26          Parameters
  27          ----------
  28          file_or_name : filename or open filehandle (writable)
  29              File that will be duplicated
  30          mode : optional, valid mode for open().
  31              If a filename was give, open with this mode.
  32          channel : str, one of ['stdout', 'stderr']
  33          )r
  34  �stderrzInvalid channel spec %s�write�seek�bN�utf-8��encodingF)
  35  �
  36  ValueError�hasattr�file�open�channel�getattr�sys�ostream�setattr�_closed)�selfZfile_or_name�moderr�r�Fc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/utils/io.py�__init__ s
  37  zTee.__init__cCs,|��tt|j|j�|j��d|_dS)z'Close the file and restore the channel.TN)�flushrrrrr�closer�rrrrr"8s
  38  
  39  z	Tee.closecCs&|j�|�|j�|�|j��dS)zWrite data to both channels.N)rrrr!)r�datarrrr?sz	Tee.writecCs|j��|j��dS)zFlush both channels.N)rr!rr#rrrr!Es
  40  z	Tee.flushcCs|js	|��dSdS)N)rr"r#rrr�__del__Js�zTee.__del__cCsdS)NFrr#rrr�isattyNsz
  41  Tee.isattyN)r	r
  42  )
  43  �__name__�
  44  __module__�__qualname__�__doc__r r"rr!r%r&rrrrrs
  45  
  46  rcCs�ddddd�}d}||��vrJzt|d���}|s|}Wn&ty.|r(|}td�YntyC||��vr@|}t�n�Ynw||��vs||S)a�Asks a question and returns a boolean (y/n) answer.
  47  
  48      If default is given (one of 'y','n'), it is used if the user input is
  49      empty. If interrupt is given (one of 'y','n'), it is used if the user
  50      presses Ctrl-C. Otherwise the question is repeated until an answer is
  51      given.
  52  
  53      An EOF is treated as the default answer.  If there is no default, an
  54      exception is raised to prevent infinite loops.
  55  
  56      Valid answers are: y/yes/n/no (match is not case sensitive).TF)�y�n�yes�noN� �
  57  )�keys�input�lower�KeyboardInterrupt�print�EOFError)�prompt�defaultZ	interruptZanswersZansrrr�
  58  ask_yes_noQs*
  59  ����r9�.pycCsXt�|�d}tt|�ddd��}|�|�|��Wd�|S1s%wY|S)a�Make a temporary python file, return filename and filehandle.
  60  
  61      Parameters
  62      ----------
  63      src : string or list of strings (no need for ending newlines if list)
  64          Source code to be written to the file.
  65      ext : optional, string
  66          Extension for the generated file.
  67  
  68      Returns
  69      -------
  70      (filename, open filehandle)
  71          It is the caller's responsibility to close the open file and unlink it.
  72      rr	rrN)�tempfile�mkstemprrrr!)�src�ext�fname�frrr�temp_pyfiless
  73  
  74  
  75  ��rAcO�@tdtdd�t||�dd�|�dd�tjd��tj��d	S)
  76  zRDEPRECATED: Raw print to sys.__stdout__, otherwise identical interface to print().z@IPython.utils.io.raw_print has been deprecated since IPython 7.0���
  77  stacklevel�sepr/�end�
  78  �rFrGrN)r�DeprecationWarningr5�getr�
  79  __stdout__r!��args�kwrrr�	raw_print��
  80  �rPcOrB)
  81  zRDEPRECATED: Raw print to sys.__stderr__, otherwise identical interface to print().zDIPython.utils.io.raw_print_err has been deprecated since IPython 7.0rCrDrFr/rGrHrIN)rrJr5rKr�
  82  __stderr__r!rMrrr�
  83  raw_print_err�rQrS)NN)r:)r*�atexit�osrr;�pathlibr�warningsrZIPython.utils.decoratorsr�capturerr�objectrr9rArPrSrrrr�<module>s 	
  84  <
  85  "
  86