U
    -eK                     @   sH   d Z ddlZddlmZ ddlmZ G dd deZG dd deZ	dS )	a   This module contains classes - NamedFileInTemporaryDirectory, TemporaryWorkingDirectory.

These classes add extra features such as creating a named file in temporary directory and
creating a context manager for the working directory which is also temporary.
    N)Path)TemporaryDirectoryc                   @   s2   e Zd ZdddZdd ZeZdd	 Zd
d ZdS )NamedFileInTemporaryDirectoryw+bFc                 K   sB   t f || _t| jj| }d|kr(dnd}t||||d| _dS )aN  
        Open a file named `filename` in a temporary directory.

        This context manager is preferred over `NamedTemporaryFile` in
        stdlib `tempfile` when one needs to reopen the file.

        Arguments `mode` and `bufsize` are passed to `open`.
        Rest of the arguments are passed to `TemporaryDirectory`.

        bNzutf-8)encoding)r   _tmpdirr   nameopenfile)selffilenamemodebufsizeZadd_to_syspathkwdspathr    r   V/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/IPython/utils/tempdir.py__init__   s    z&NamedFileInTemporaryDirectory.__init__c                 C   s   | j   | j  d S N)r   closer	   cleanupr   r   r   r   r      s    
z%NamedFileInTemporaryDirectory.cleanupc                 C   s   | j S r   )r   r   r   r   r   	__enter__#   s    z'NamedFileInTemporaryDirectory.__enter__c                 C   s   |    d S r   )r   )r   typevalue	tracebackr   r   r   __exit__&   s    z&NamedFileInTemporaryDirectory.__exit__N)r   r   F)__name__
__module____qualname__r   r   __del__r   r   r   r   r   r   r      s
   
r   c                       s,   e Zd ZdZ fddZ fddZ  ZS )TemporaryWorkingDirectoryz
    Creates a temporary directory and sets the cwd to that directory.
    Automatically reverts to previous cwd upon cleanup.
    Usage example:

        with TemporaryWorkingDirectory() as tmpdir:
            ...
    c                    s$   t  | _t| j tt|  S r   )	r   cwdold_wd_oschdirr
   superr#   r   r   	__class__r   r   r   4   s    
z#TemporaryWorkingDirectory.__enter__c                    s    t | j tt| |||S r   )r&   r'   r%   r(   r#   r   )r   excr   tbr)   r   r   r   9   s    z"TemporaryWorkingDirectory.__exit__)r   r    r!   __doc__r   r   __classcell__r   r   r)   r   r#   *   s   	r#   )
r-   osr&   pathlibr   tempfiler   objectr   r#   r   r   r   r   <module>   s
   