
    ^hA                         S r SSKJr  SSKrSSKrSSKr SSK	J
r
   " S S	\5      r " S
 S\
5      rg! \ a    SSK	JrJr   " S S\5      r
 N2f = f)zTemporaryDirectory class, copied from Python 3

This is copied from the stdlib and will be standard in Python 3.2 and onwards.
    )print_functionN)TemporaryDirectory)mkdtemptemplatec                   V   \ rS rSrSrS\S4S jrS rSS jrS r	S	 r
\" \R                  5      r\" \R                  R                   5      r\" \R                  R$                  5      r\" \R(                  5      r\" \R,                  5      r\R0                  r\R6                  rS
 rSrg)r      a  Create and return a temporary directory.  This has the same
behavior as mkdtemp but can be used as a context manager.  For
example:

    with TemporaryDirectory() as tmpdir:
        ...

Upon exiting the context, the directory and everthing contained
in it are removed.
 Nc                 4    [        XU5      U l        SU l        g NF)r   name_closed)selfsuffixprefixdirs       R/home/james-whalen/.local/lib/python3.13/site-packages/ipython_genutils/tempdir.py__init__TemporaryDirectory.__init__#   s    4DI DL    c                     U R                   $ N)r   r   s    r   	__enter__TemporaryDirectory.__enter__'   s    99r   c                    U R                   (       ac  U R                  (       dQ   U R                  U R                   5        SU l        U(       a&  U R                  SR                  U 5      [        5        g g g g ! [        [        4 aA  nS[        U5      ;  a  e [        SR                  X 5      [        R                  S9   S nAg S nAff = f)NNonez"ERROR: {!r} while cleaning up {!r}fileTzImplicitly cleaning up {!r})r   r   _rmtree	TypeErrorAttributeErrorstrprintformat_sysstderr_warnWarning)r   r'   exs      r   cleanupTemporaryDirectory.cleanup*   s    yy
LL+  $JJ<CCDI&(  ".y ">2  SW,>EEbP#{{,s   A6 6C7CCc                 $    U R                  5         g r   r*   )r   excvaluetbs       r   __exit__TemporaryDirectory.__exit__<   s    LLNr   c                 "    U R                  SS9  g )NT)r'   r-   r   s    r   __del__TemporaryDirectory.__del__?   s    LLtL$r   c                    U R                  U5       HR  nU R                  X5      n U R                  U5      nU(       a  U R	                  U5        M@   U R                  U5        MT      U R                  U5        g ! U R                   a    Sn NWf = f! U R                   a     M  f = f! U R                   a     g f = fr   )_listdir
_path_join_isdir	_os_errorr   _remove_rmdir)r   pathr   fullnameisdirs        r   r   TemporaryDirectory._rmtreeP   s     d+??46" KK1E LL*X. ,D! ~~ "!E"  >>  >> s5   A;B)B* ;BBB'&B'*B=<B=)r   r   )F)__name__
__module____qualname____firstlineno____doc__r   r   r   r*   r1   r4   staticmethod_oslistdirr7   r=   joinr8   r?   r9   remover;   rmdirr<   errorr:   	_warningswarnr'   r   __static_attributes__ r   r   r   r      s    		 #%X4 	!		($		%  ,!#((--0
chhnn-szz*cii(II		r   r   c                   4    \ rS rSrSS jrS r\rS rS rSr	g)	NamedFileInTemporaryDirectoryg   c                     [        S0 UD6U l        [        R                  R	                  U R                  R
                  U5      n[        XRU5      U l        g)a  
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`.

NrP   )r   _tmpdirrG   r=   rI   r   openr   )r   filenamemodebufsizekwdsr=   s         r   r   &NamedFileInTemporaryDirectory.__init__i   s?     *1D1xx}}T\\..9W-	r   c                 l    U R                   R                  5         U R                  R                  5         g r   )r   closerU   r*   r   s    r   r*   %NamedFileInTemporaryDirectory.cleanupx   s     		r   c                     U R                   $ r   r   r   s    r   r   'NamedFileInTemporaryDirectory.__enter__~   s    yyr   c                 $    U R                  5         g r   r-   )r   typer/   	tracebacks       r   r1   &NamedFileInTemporaryDirectory.__exit__   s    r   )rU   r   N)zw+b)
rA   rB   rC   rD   r   r*   r4   r   r1   rO   rP   r   r   rR   rR   g   s    . Gr   rR   c                   8   ^  \ rS rSrSrU 4S jrU 4S jrSrU =r$ )TemporaryWorkingDirectory   z
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                    > [         R                  " 5       U l        [         R                  " U R                  5        [
        [        U ]  5       $ r   )rG   getcwdold_wdchdirr   superrg   r   )r   	__class__s    r   r   #TemporaryWorkingDirectory.__enter__   s1    jjl		$)).?AAr   c                 l   > [         R                  " U R                  5        [        [        U ]  XU5      $ r   )rG   rl   rk   rm   rg   r1   )r   r.   r/   r0   rn   s       r   r1   "TemporaryWorkingDirectory.__exit__   s(    		$++.>s2NNr   )rk   )	rA   rB   rC   rD   rE   r   r1   rO   __classcell__)rn   s   @r   rg   rg      s    B
O Or   rg   )rE   
__future__r   osrG   warningsrM   sysr%   tempfiler   ImportErrorr   r   objectrR   rg   rP   r   r   <module>rz      sb    &   R+jF <O 2 Oc  O*LV LOs   3 AA