a
    lc                     @   s   d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl	m
Z
 ddlmZmZ eejdd	d
Zeej G dd deZdddZdddZe
dd Ze
dd ZdS )z
IO related utilities.
    N)Path)warn)undoc   )
CapturedIOcapture_outputwutf-8encodingc                   @   s:   e Zd ZdZdddZdd Zdd	 Zd
d Zdd ZdS )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.
    r   stdoutc                 C   sx   |dvrt d| t|dr0t|dr0|| _n d|v r<dnd}t|||d| _|| _tt|| _tt||  d	| _	dS )
aN  Construct 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']
        )r   stderrzInvalid channel spec %swriteseekbNr	   r
   F)

ValueErrorhasattrfileopenchannelgetattrsysostreamsetattr_closed)selfZfile_or_namemoder   r    r   L/var/www/html/django/DPS/env/lib/python3.9/site-packages/IPython/utils/io.py__init__%   s    zTee.__init__c                 C   s,   |    tt| j| j | j  d| _dS )z'Close the file and restore the channel.TN)flushr   r   r   r   r   closer   r   r   r   r   r"   =   s    
z	Tee.closec                 C   s&   | j | | j| | j  dS )zWrite data to both channels.N)r   r   r   r!   )r   datar   r   r   r   D   s    z	Tee.writec                 C   s   | j   | j  dS )zFlush both channels.N)r   r!   r   r#   r   r   r   r!   J   s    
z	Tee.flushc                 C   s   | j s|   d S )N)r   r"   r#   r   r   r   __del__O   s    zTee.__del__N)r   r   )	__name__
__module____qualname____doc__r    r"   r   r!   r%   r   r   r   r   r      s   

r   c                 C   s   ddddd}d}||  vrzt| d  }|s8|}W q ty\   |rP|}td Y q ty   ||  v r|}t  n Y q0 q|| S )a  Asks 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)ynyesnoN )keysinputlowerKeyboardInterruptprintEOFError)promptdefault	interruptZanswersansr   r   r   
ask_yes_noT   s"    
r:   .pyc                 C   sV   t |d }tt|ddd"}||  |  W d   n1 sH0    Y  |S )a  Make 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.
    r   r   r	   r
   N)tempfilemkstempr   r   r   r!   )srcextfnamefr   r   r   temp_pyfilev   s
    
&rB   c                  O   s@   t dtdd t| |dd|ddtjd tj  d	S )
zRDEPRECATED: Raw print to sys.__stdout__, otherwise identical interface to print().z@IPython.utils.io.raw_print has been deprecated since IPython 7.0   
stacklevelsepr.   end
rF   rG   r   N)r   DeprecationWarningr4   getr   
__stdout__r!   argskwr   r   r   	raw_print   s
    rP   c                  O   s@   t dtdd t| |dd|ddtjd tj  d	S )
zRDEPRECATED: Raw print to sys.__stderr__, otherwise identical interface to print().zDIPython.utils.io.raw_print_err has been deprecated since IPython 7.0rC   rD   rF   r.   rG   rH   rI   N)r   rJ   r4   rK   r   
__stderr__r!   rM   r   r   r   raw_print_err   s
    rR   )NN)r;   )r)   atexitosr   r<   pathlibr   warningsr   IPython.utils.decoratorsr   capturer   r   r   devnullregisterr"   objectr   r:   rB   rP   rR   r   r   r   r   <module>   s"   	:
"

