
    &eK                     b    d Z ddlZddlmZ ddlmZ  G d de          Z G 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                   ,    e Zd Zd	dZd ZeZd Zd ZdS )
NamedFileInTemporaryDirectoryw+bFc                     t          di || _        t          | j        j                  |z  }d|v rdnd}t	          ||||          | _        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bufsizeadd_to_syspathkwdspathr   s           5lib/python3.11/site-packages/IPython/utils/tempdir.py__init__z&NamedFileInTemporaryDirectory.__init__   s]     *11D11DL%&&1$;;44GtWx@@@			    c                 j    | j                                          | j                                         d S N)r   closer   cleanupr   s    r   r   z%NamedFileInTemporaryDirectory.cleanup   s.    	r   c                     | j         S r   )r   r   s    r   	__enter__z'NamedFileInTemporaryDirectory.__enter__#   s
    yr   c                 .    |                                   d S r   )r   )r   typevalue	tracebacks       r   __exit__z&NamedFileInTemporaryDirectory.__exit__&   s    r   N)r   r   F)__name__
__module____qualname__r   r   __del__r!   r&   r   r   r   r   r      s`        A A A A    G      r   r   c                   ,     e Zd ZdZ fdZ fdZ x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                     t          j                    | _        t          j        | j                   t          t          |                                           S r   )	r   cwdold_wd_oschdirr   superr,   r!   )r   	__class__s    r   r!   z#TemporaryWorkingDirectory.__enter__4   s?    hjj	$).55??AAAr   c                     t          j        | j                   t          t          |                               |||          S r   )r0   r1   r/   r2   r,   r&   )r   excr$   tbr3   s       r   r&   z"TemporaryWorkingDirectory.__exit__9   s8    	$+.55>>sE2NNNr   )r'   r(   r)   __doc__r!   r&   __classcell__)r3   s   @r   r,   r,   *   si         B B B B B
O O O O O O O O Or   r,   )
r7   osr0   pathlibr   tempfiler   objectr   r,   r   r   r   <module>r=      s               ' ' ' ' ' '    F   <O O O O O 2 O O O O Or   