Format: application/x-python-code
⬇ Download File (2.7 KB)
   1  o
   2  
   3  ��hK�@sHdZddlZddlmZddlmZGdd�de�ZGdd�de�Z	dS)	a This module contains classes - NamedFileInTemporaryDirectory, TemporaryWorkingDirectory.
   4  
   5  These classes add extra features such as creating a named file in temporary directory and
   6  creating a context manager for the working directory which is also temporary.
   7  �N)�Path)�TemporaryDirectoryc@s2eZdZd
   8  dd�Zdd�ZeZdd	�Zd
   9  d�ZdS)�NamedFileInTemporaryDirectory�w+b�����FcKsFtdi|��|_t|jj�|}d|vrdnd}t||||d�|_dS)aN
  10          Open a file named `filename` in a temporary directory.
  11  
  12          This context manager is preferred over `NamedTemporaryFile` in
  13          stdlib `tempfile` when one needs to reopen the file.
  14  
  15          Arguments `mode` and `bufsize` are passed to `open`.
  16          Rest of the arguments are passed to `TemporaryDirectory`.
  17  
  18          �bNzutf-8)�encoding�)r�_tmpdirr�name�open�file)�self�filename�mode�bufsizeZadd_to_syspath�kwds�pathrr	r	�Kc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/utils/tempdir.py�__init__
  19  sz&NamedFileInTemporaryDirectory.__init__cCs|j��|j��dS�N)r
  20  �closer
  21  �cleanup�rr	r	rrs
  22  z%NamedFileInTemporaryDirectory.cleanupcCs|jSr)r
  23  rr	r	r�	__enter__#sz'NamedFileInTemporaryDirectory.__enter__cCs|��dSr)r)r�type�value�	tracebackr	r	r�__exit__&sz&NamedFileInTemporaryDirectory.__exit__N)rrF)�__name__�
  24  __module__�__qualname__rr�__del__rrr	r	r	rrs
  25  rcs,eZdZdZ�fdd�Z�fdd�Z�ZS)�TemporaryWorkingDirectoryz�
  26      Creates a temporary directory and sets the cwd to that directory.
  27      Automatically reverts to previous cwd upon cleanup.
  28      Usage example:
  29  
  30          with TemporaryWorkingDirectory() as tmpdir:
  31              ...
  32      cs$t��|_t�|j�tt|���Sr)	r�cwd�old_wd�_os�chdirr�superr#rr��	__class__r	rr4s
  33  z#TemporaryWorkingDirectory.__enter__cs t�|j�tt|��|||�Sr)r&r'r%r(r#r)r�excr�tbr)r	rr9sz"TemporaryWorkingDirectory.__exit__)rr r!�__doc__rr�
  34  __classcell__r	r	r)rr#*s	r#)
  35  r-�osr&�pathlibr�tempfiler�objectrr#r	r	r	r�<module>s