
    F\h                     r   S r / SQrSSKrSSKrSSKrSSKr	 SSK
r\R                  rSSKrSSKJ r!  SSKrSSK"r#SSK$r%SSK&r&\&RN                  r(\	RR                  \	RT                  -  \	RV                  -  r,\-" \	S	5      (       a  \,\	R\                  -  r,\,r/\-" \	S
5      (       a  \/\	R`                  -  r/\-" \	S5      (       a  \	Rb                  r1OSr1Sr2\(" 5       r3S r4S r5S r6 " S S5      r7S r8S r9Sq:S r;S r<S r=S r>S r?S r@SqAS rBS rCS rDS3S jrES4S jrFS \2S4S! jrG " S" S#5      rH " S$ S%5      rI   S5SS&S'.S( jjrJ\	R                  S):w  d  \R                  S*:X  a  \JrMO\-" \	S+5      qN   S6SS,.S- jjrM " S. S/\R                  5      rP " S0 S15      rQg! \ a    SSKrSSKrS rS r\R*                  \R"                  \R,                  \R.                  1\R0                  :*  =(       a9    \R2                  \R4                  ;   =(       a    \R"                  \R6                  ;   rS2SSS.S jjr GNf = f)7a  Temporary files.

This module provides generic, low- and high-level interfaces for
creating temporary files and directories.  All of the interfaces
provided by this module can be used without fear of race conditions
except for 'mktemp'.  'mktemp' is subject to race conditions and
should not be used; it is provided for backward compatibility only.

The default path names are returned as str.  If you supply bytes as
input, all return values will be in bytes.  Ex:

    >>> tempfile.mkstemp()
    (4, '/tmp/tmptpu9nin8')
    >>> tempfile.mkdtemp(suffix=b'')
    b'/tmp/tmppbi8f0hy'

This module also provides some data items to the user:

  TMP_MAX  - maximum number of names that will be tried before
             giving up.
  tempdir  - If this is set to a string before the first use of
             any routine from this module, it will be considered as
             another candidate location to store temporary files.
)NamedTemporaryFileTemporaryFileSpooledTemporaryFileTemporaryDirectorymkstempmkdtempmktempTMP_MAXgettempprefixtempdir
gettempdirgettempprefixbgettempdirb    Nc                   ^ U4S jn[         R                  U SU[         R                  S9nU H  u  pEnU H8  n[         R                  R	                  XG5      n [         R                  U5        M:     U H8  n[         R                  R	                  XG5      n [         R                  U5        M:     M      [         R                  U 5        g ! [         a     M  [         a"  n	T" [         R
                  X5         S n	A	M  S n	A	ff = f! [         a     M  [         a"  n	T" [         R                  X5         S n	A	M  S n	A	ff = f! [         a     g [         a!  n	T" [         R
                  X	5         S n	A	g S n	A	ff = f)Nc                 v   > [        U [        5      (       d#  T" [        R                  U R                  U 5        g g N)
isinstanceFileNotFoundErrorosscandirfilename)erronexcs    /usr/lib/python3.13/tempfile.pyonerror_rmtree_unsafe.<locals>.onerror4   s*    C!233BJJc2 4    F)topdownr   followlinks)	r   walk_walk_symlinks_as_filespathjoinrmdirr   OSErrorunlink)
r"   r   r   resultsdirpathdirnames	filenamesnamefullnamer   s
    `        r   _rmtree_unsafer-   3   s)   3 eW"JdJdeg*1
&'Ydg4h1((8$   dg4h2))H%   +2"%
((4. '  1(001 '  2		8112  
 %
$
$
$%sZ   CD5E 
D	D!C>>D
D>	D>D99D>
E7	E7E22E7c                    U R                  5       u  p#pEUc  UOUR                  n U[        R                  L a  [        R                  U5        g U[        R                  L a  [        R	                  XcS9  g U[        R
                  L d   eUc  [        R                  XcS9nOUR                  SS9n[        R                  n[        R                  U[        R                  [        R                  -  US9n[        R                  R                  n [        R                  R                  U[        R                  U5      5      (       d  [        S5      eU R                  [        R                  X4U45        U R                  [        R                  XU45        [        R                   n[        R!                  U5       n	[#        U	5      n
S S S 5        W
 H  n[        R                  R%                  XKR                  5      n UR'                  SS9(       a$  U R                  [        R
                  XU45        Me    [        R+                  UR                  US9  M     g ! U R                  [        R                  XU45        f = f! , (       d  f       N= f! [(         a     M  [         a     Ntf = f! [(         a     M  [         a#  nU" [        R*                  X5         S nAGM  S nAff = f! [(         a4  nUb  U[        R                  L a  XMl        U" X$U5         S nAg  S nAg S nAf[         a  nXMl        U" X$U5         S nAg S nAff = f)N)dir_fdF)follow_symlinks%Cannot call rmtree on a symbolic link)popr+   r   closer$   lstatstatopenO_RDONLY
O_NONBLOCKr"   islinksamestatfstatr%   appendr   listr#   is_dirr   r&   r   )stackr   funcdirfdr"   
orig_entryr+   orig_sttopfd
scandir_itentriesentryr,   r   s                 r   _rmtree_safe_fdrH   Q   s    ',iik#d4'TZ__d6!RXXhhuoRXXhhth* !
!!4g">g$''$bmm ;E'J%$@WW%%grxx?? GHHllBHHe:>?llBHHe:>?$zz% JZ(g !edJJ7h\\%\8llBHHeu#EF 92))EJJu)5  llBHHe:>? !  '   '  2		8112 %4288#3!lD$$ $4  !,
C
 
 !s   (K, &K, 6BK, A%I 5AK, <J6K, ?6J5K, 9J0K, $J  K, 
JK, 
J-K, !	J-*K, ,J--K, 0
K):K, =	K)K$K, $K))K, ,
M6%L%%M2MM)r   r/   c                  ^ [         R                  SX5        U(       a  S nOTc  Uc  S nOUc  Tc  S nOU4S jn[        (       a  [        U [        5      (       a  [
        R                  U 5      n [
        R                  X@S4/n U(       a  [        XS5        U(       a  M  U(       aH  UR                  5       u  pgpU[
        R                  La  M/   [
        R                  U5        U(       a  MG  ggUb  [        S5      e [
        R                  U 5      n
 [        U
5      (       a  [        S5      e [!        X5      $ ! [         a!  n	U" [
        R                  X	5         Sn	A	N}Sn	A	ff = f! U(       aw  UR                  5       u  pgpU[
        R                  La  M/   [
        R                  U5        O.! [         a!  n	U" [
        R                  X	5         Sn	A	OSn	A	ff = fU(       a  Mv  f f = f! [         a!  n	U" [
        R                  X	5         Sn	A	gSn	A	ff = f! [         a+  n	U" [
        R                  R                  X	5         Sn	A	gSn	A	ff = f)	a  Recursively delete a directory tree.

If dir_fd is not None, it should be a file descriptor open to a directory;
path will then be relative to that directory.
dir_fd may not be implemented on your platform.
If it is unavailable, using it will raise a NotImplementedError.

If ignore_errors is set, errors are ignored; otherwise, if onexc or
onerror is set, it is called to handle the error with arguments (func,
path, exc_info) where func is platform and implementation dependent;
path is the argument to that function that caused it to fail; and
the value of exc_info describes the exception. For onexc it is the
exception instance, and for onerror it is a tuple as returned by
sys.exc_info().  If ignore_errors is false and both onexc and
onerror are None, the exception is reraised.

onerror is deprecated and only remains for backwards compatibility.
If both onerror and onexc are set, onerror is ignored and onexc is used.
ztempfile._rmtreec                      g r    argss    r   r   _rmtree.<locals>.onexc   s    r   Nc                      e r   rK   rL   s    r   r   rN      s    r   c                      e r   rK   rL   s    r   r   rN      s    r   c                  Z   > U u  pnUc  SnO[        U5      X3R                  4nT" XU5      $ )NNNN)type__traceback__)rM   r@   r"   excexc_infor   s        r   r   rN      s7    $(/$c[!1h!%cC1B1B!Bh X66r   z#dir_fd unavailable on this platformr1   )sysaudit_use_fd_functionsr   bytesr   fsdecoder4   rH   r2   r3   r%   NotImplementedError_rmtree_islinkr"   r9   r-   )r"   ignore_errorsr   r   r/   r?   r@   fdrG   r   sts     `        r   _rmtreera      s   * 
ii"D1	?u}=_7 
	e$$[[&dHHfD12%1!%/ E */))+'$D)1hhrl E '(MNN88D>b## GHH $  ,
,% ! 1BHHd001 */))+'$D)1hhrl  1BHHd001 E  BHHd(  BGGNND.s   E, D> G/ H >
E)E$$E),0G,F32G,3
G=GG,G
G,*G,/
H9HH
I'!II)Random
O_NOFOLLOWO_BINARYr	   i'  tmpc                 R     [         R                  " U 5        g! [         a     gf = f)NTF)_osr4   r%   )fns    r   _existsri     s+    		"   s    
&&c                     SnU  H  nUc  M  [        U[        R                  5      (       a  [        R                  " U5      n[        U[        5      (       a  U[
        L a  [        S5      e[        nMn  U[        L a  [        S5      e[
        nM     Uc,  [        b  [        [        [
        5      (       a  [
        $ [        $ U$ )zBLook at the type of all args and divine their implied return type.Nz1Can't mix bytes and non-bytes in path components.)r   rg   PathLikefspathrZ   str	TypeErrorr   )rM   return_typeargs      r   _infer_return_typerq     s    K;c3<<((**S/Cc5!!c! !3 4 4Ke# !3 4 4K! " ?j#66J Lr   c                     [        XU5      nUc  U" 5       nU c*  U[        L a  [        n O[        R                  " [        5      n Uc  U[        L a  [        5       nO
[        5       nXX#4$ )z9Common parameter processing for most APIs in this module.)rq   rm   templaterg   fsencoder   r   )prefixsuffixdiroutput_types       r   _sanitize_paramsry   1  s`    $VS9K~~#F\\(+F
{#,C-C3++r   c                   8    \ rS rSrSrSr\S 5       rS rS r	Sr
g)	_RandomNameSequenceiC  a  An instance of _RandomNameSequence generates an endless
sequence of unpredictable strings which can safely be incorporated
into file names.  Each string is eight characters long.  Multiple
threads can safely use the same instance at the same time.

_RandomNameSequence is an iterator.%abcdefghijklmnopqrstuvwxyz0123456789_c                     [         R                  " 5       nU[        U SS 5      :w  a  [        5       U l        Xl        U R                  $ )N_rng_pid)rg   getpidgetattr_Random_rngr~   )selfcur_pids     r   rng_RandomNameSequence.rngM  s6    **,gdJ55	DI#Myyr   c                     U $ r   rK   r   s    r   __iter___RandomNameSequence.__iter__U  s    r   c                 h    SR                  U R                  R                  U R                  SS95      $ )N    )k)r#   r   choices
charactersr   s    r   __next___RandomNameSequence.__next__X  s)    wwtxx''1'=>>r   )r   r~   N)__name__
__module____qualname____firstlineno____doc__r   propertyr   r   r   __static_attributes__rK   r   r   r{   r{   C  s*    + 9J ?r   r{   c                  $   / n S H3  n[         R                  " U5      nU(       d  M"  U R                  U5        M5     [         R                  S:X  aR  U R	                  [         R
                  R                  S5      [         R
                  R                  S5      SSSS/5        OU R	                  / S	Q5         U R                  [         R                  " 5       5        U $ ! [        [        4 a#    U R                  [         R                  5         U $ f = f)
zWGenerate a list of candidate temporary directories which
_get_default_tempdir will try.)TMPDIRTEMPTMPntz~\AppData\Local\Tempz%SYSTEMROOT%\Tempzc:\tempzc:\tmpz\tempz\tmp)z/tmpz/var/tmpz/usr/tmp)rg   getenvr<   r+   extendr"   
expanduser
expandvarsgetcwdAttributeErrorr%   curdir)dirlistenvnamedirnames      r   _candidate_tempdir_listr   [  s     G +**W%7GNN7+ +
 xx4,,-DE,,-AB#Y'D 	E 	9:#szz|$ N G$ #szz"N#s   6$C /DDc                     [        5       n [        5       nU H  nU[        R                  :w  a  [        R                  R                  U5      n[        S5       H  n[        U 5      n[        R                  R                  X$5      n [        R                  " U[        S5      n  [        R                  " US5        [        R                  " U5         [        R                  " U5        Us  s  $    M     [+        [,        R.                  SU-  5      e! [        R                  " U5        f = f! [        R                  " U5        f = f! [         a     M  [         al    [        R                   S:X  aR  [        R                  R#                  U5      (       a.  [        R$                  " U[        R&                  5      (       a   GMk     GM  [(         a       GM  f = f)a]  Calculate the default directory to use for temporary files.
This routine should be called exactly once.

We determine whether or not a candidate temp dir is usable by
trying to create and write to a file in that directory.  If this
is successful, the test file is deleted.  To prevent denial of
service, the name of the test file must be randomized.d     s   blatr   z)No usable temporary directory found in %s)r{   r   rg   r   r"   abspathrangenextr#   r6   _bin_openflagswriter3   r&   FileExistsErrorPermissionErrorr+   isdiraccessW_OKr%   r   _errnoENOENT)namerr   rw   seqr+   r   r_   s          r   _get_default_tempdirr   v  sM     !E%'G#**((""3'C:C;Dxx}}S/HXXh>)&		"g.		"JJx(
 	 8 FMMG#$% % 		"JJx(" "  HH$)<)<JJsCHH-- sI   E$D;D,ED))D,,EE
GA+G	GGc                      [         c@  [        R                  5          [         c
  [        5       q [        R	                  5         [         $ [         $ ! [        R	                  5         f = f)z7Common setup sequence for all user-callable interfaces.)_name_sequence
_once_lockacquirer{   releaserK   r   r   _get_candidate_namesr     sP     	!%!4!6 >     A A$c                    [         R                  R                  U 5      n [        5       nU[        L a  [        [         R                  U5      n[        [        5       He  n[        U5      n[         R                  R                  XU-   U-   5      n[        R                  " SU5         [         R                  " XS5      n	X4s  $    [        [(        R*                  S5      e! [         a     M  [         ag    [         R                   S:X  aQ  [         R                  R#                  U 5      (       a-  [         R$                  " U [         R&                  5      (       a   M  e f = f)z>Code common to mkstemp, TemporaryFile, and NamedTemporaryFile.ztempfile.mkstempr   r   z#No usable temporary file name found)rg   r"   r   r   rZ   maprt   r   r	   r   r#   _sysrX   r6   r   r   r+   r   r   r   r   EEXIST)
rw   presufflagsrx   namesr   r+   filer_   s
             r   _mkstemp_innerr     s    ((

3
C "EeCLL%(W~E{xx}}S*s"23

%t,	$u-B x! $ &--?A A  	 	 D SXX^^C%8%8

3))	s   'C
E,A+EEc                     U [         R                  ;   a  U " U/UQ7SS06  g [         R                  R                  U5      (       d
  U " U/UQ76   g g )Nr0   F)rg   supports_follow_symlinksr"   r9   )r@   r"   rM   s      r   _dont_follow_symlinksr     sG    s+++T0D0%0XX__T""TD #r   c                      [         R                  n[        XS5        [        [         R                  U S5        g ! [         a     N(f = f)Nr     )rg   chflagsr   r   chmod)r"   r   s     r   _resetpermsr     s@    0++ 	gQ/#))T51	  s   : 
AAc                  6    [         R                  " [        5      $ )z7The default prefix for temporary directories as string.)rg   r[   rs   rK   r   r   r
   r
         <<!!r   c                  6    [         R                  " [        5      $ )z6The default prefix for temporary directories as bytes.)rg   rt   rs   rK   r   r   r   r     r   r   c                      [         c@  [        R                  5          [         c
  [        5       q [        R	                  5         [         $ [         $ ! [        R	                  5         f = f)z&Private accessor for tempfile.tempdir.)r   r   r   r   r   rK   r   r   _gettempdirr     sL     	!.0 N7N  r   c                  >    [         R                  " [        5       5      $ )z Returns tempfile.tempdir as str.)rg   r[   r   rK   r   r   r   r         <<&&r   c                  >    [         R                  " [        5       5      $ )z"Returns tempfile.tempdir as bytes.)rg   rt   r   rK   r   r   r   r     r   r   c                 b    [        XU5      u  pp$U(       a  [        nO[        n[        X!XU5      $ )a@  User-callable function to create and return a unique temporary
file.  The return value is a pair (fd, name) where fd is the
file descriptor returned by os.open, and name is the filename.

If 'suffix' is not None, the file name will end with that suffix,
otherwise there will be no suffix.

If 'prefix' is not None, the file name will begin with that prefix,
otherwise a default prefix is used.

If 'dir' is not None, the file will be created in that directory,
otherwise a default directory is used.

If 'text' is specified and true, the file is opened in text
mode.  Else (the default) the file is opened in binary mode.

If any of 'suffix', 'prefix' and 'dir' are not None, they must be the
same type.  If they are bytes, the returned name will be bytes; str
otherwise.

The file is readable and writable only by the creating user ID.
If the operating system uses permission bits to indicate whether a
file is executable, the file is executable by no one. The file
descriptor is not inherited by children of this process.

Caller is responsible for deleting the file when done with it.
)ry   _text_openflagsr   r   )rv   ru   rw   textrx   r   s         r   r   r      s1    : (8'L$FC#vkBBr   c                    [        XU5      u  pp#[        5       nU[        L a  [        [        R
                  U5      n[        [        5       H  n[        U5      n[        R                  R                  X!U-   U -   5      n[        R                  " SU5         [        R                  " US5        [        R                  R)                  U5      s  $    [        [*        R,                  S5      e! [         a     M  [         ah    [        R                   S:X  aR  [        R                  R#                  U5      (       a.  [        R$                  " U[        R&                  5      (       a   GM  e f = f)ac  User-callable function to create and return a unique temporary
directory.  The return value is the pathname of the directory.

Arguments are as for mkstemp, except that the 'text' argument is
not accepted.

The directory is readable, writable, and searchable only by the
creating user.

Caller is responsible for deleting the directory when done with it.
ztempfile.mkdtempr   r   z(No usable temporary directory name found)ry   r   rZ   r   rg   rt   r   r	   r   r"   r#   r   rX   mkdirr   r   r+   r   r   r   r   r   r   )rv   ru   rw   rx   r   r   r+   r   s           r   r   r   '  s    (8'L$FC "EeCLL%(W~E{xx}}S4-&"89

%t,	IIdE" xx%%! $ &--DF F  	 	 D SXX^^C%8%8

3))	s   C++
E)8A+E)'E)r   c                    Uc
  [        5       n[        5       n[        [        5       HG  n[	        U5      n[
        R                  R                  X!U-   U -   5      n[        U5      (       a  ME  Us  $    [        [        R                  S5      e)a  User-callable function to return a unique temporary file name.  The
file is not created.

Arguments are similar to mkstemp, except that the 'text' argument is
not accepted, and suffix=None, prefix=None and bytes file names are not
supported.

THIS FUNCTION IS UNSAFE AND SHOULD NOT BE USED.  The file name may
refer to a file that did not exist at some point, but by the time
you get around to creating it, someone else may have beaten you to
the punch.
z"No usable temporary filename found)r   r   r   r	   r   rg   r"   r#   ri   r   r   r   )rv   ru   rw   r   r   r+   r   s          r   r   r   O  sr    $ {l "EW~E{xx}}S4-&"89t}}K	  &-->@ @r   c                   r    \ rS rSrSrSrSrSS jr\R                  S:H  \R                  4S jrS rS rS	rg
)_TemporaryFileCloserio  zA separate object allowing proper closing of a temporary file's
underlying file object, without adding a __del__ method to the
temporary file.Fc                 4    Xl         X l        X0l        X@l        g r   )r   r+   deletedelete_on_closer   r   r+   r   r   s        r   __init___TemporaryFileCloser.__init__w  s    		.r   r   c                    U R                   (       dy  SU l          U R                  (       d!  SU l        U R                  R                  5         U R                  (       a-  U(       a  U R
                  (       d   U" U R                  5        g g g g ! [         a     g f = f! U R                  (       a=  U(       a  U R
                  (       d$   U" U R                  5        f ! [         a     f f = ff f = fNT)cleanup_calledclose_calledr   r3   r   r   r+   r   )r   windowsr&   s      r   cleanup_TemporaryFileCloser.cleanup}  s    """&D(((,D%IIOO% ;;D4H4Htyy) 5I; # -  ;;D4H4Htyy),  5I;sA   2B 6B 
BB*C,CC,
C'$C,&C''C,c                 F   U R                   (       dW  SU l          U R                  R                  5         U R                  (       a#  U R                  (       a  U R                  5         g g g g ! U R                  (       a#  U R                  (       a  U R                  5         f f f = fr   )r   r   r3   r   r   r   r   s    r   r3   _TemporaryFileCloser.close  sm       $D#		!;;4#7#7LLN $8; !
 ;;4#7#7LLN $8;s   A* *6B c                 $    U R                  5         g r   )r   r   s    r   __del___TemporaryFileCloser.__del__  s    r   )r   r   r   r   r   r+   NTT)r   r   r   r   r   r   r   r   rg   r+   r&   r   r3   r   r   rK   r   r   r   r   o  s;     NL/  #xx4/  #r   r   c                   @    \ rS rSrSrSS jrS rS rS rS r	S r
S	rg
)_TemporaryFileWrapperi  zTemporary file wrapper

This class provides a wrapper around files opened for
temporary use.  In particular, it seeks to automatically
remove the file when it is no longer needed.
c                 @    Xl         X l        [        XUU5      U l        g r   )r   r+   r   _closerr   s        r   r   _TemporaryFileWrapper.__init__  s    		+D,;=r   c                   ^ U R                   S   n[        X!5      n[        US5      (       a4  Um[        R                  " T5      U4S j5       nU R
                  Ul        Un[        U[        5      (       d  [        XU5        U$ )Nr   __call__c                     > T" U 0 UD6$ r   rK   )rM   kwargsr@   s     r   func_wrapper7_TemporaryFileWrapper.__getattr__.<locals>.func_wrapper  s    T,V,,r   )	__dict__r   hasattr
_functoolswrapsr   r   intsetattr)r   r+   r   ar  r@   s        @r   __getattr__!_TemporaryFileWrapper.__getattr__  s{     }}V$D1j!!Dd#- $- $(<<L A!S!!D"r   c                 :    U R                   R                  5         U $ r   )r   	__enter__r   s    r   r  _TemporaryFileWrapper.__enter__  s    		r   c                 r    U R                   R                  XU5      nU R                  R                  5         U$ r   )r   __exit__r   r   )r   rU   valuetbresults        r   r  _TemporaryFileWrapper.__exit__  s-    ##C3r   c                 8    U R                   R                  5         g)z1
Close the temporary file, possibly deleting it.
N)r   r3   r   s    r   r3   _TemporaryFileWrapper.close  s     	r   c              #   :   #    U R                    H  nUv   M	     g 7fr   )r   )r   lines     r   r   _TemporaryFileWrapper.__iter__  s      IIDJ s   )r   r   r+   Nr   )r   r   r   r   r   r   r
  r  r  r3   r   r   rK   r   r   r   r     s%    =*
r   r   T)errorsr   c          
      8  ^^^^^^ [        TTT5      u  mmmm[        m[        R                  S:X  a!  U(       a  U	(       a  T[        R                  -  mSU ;  a  [
        R                  " U5      nSmUUUUUU4S jn
 [
        R                  " TXX2UU
S9n [        USU5      n[        USU5      nTUl        [        UTXy5      $ !   UR                  5         e = f!   Tb8  [        R                  S:X  a  U(       a  U	(       d  [        R                  " T5        e = f)aG  Create and return a temporary file.
Arguments:
'prefix', 'suffix', 'dir' -- as for mkstemp.
'mode' -- the mode argument to io.open (default "w+b").
'buffering' -- the buffer size argument to io.open (default -1).
'encoding' -- the encoding argument to io.open (default None)
'newline' -- the newline argument to io.open (default None)
'delete' -- whether the file is automatically deleted (default True).
'delete_on_close' -- if 'delete', whether the file is deleted on close
   (default True) or otherwise either on context manager exit
   (if context manager was used) or on object finalization. .
'errors' -- the errors argument to io.open (default None)
The file is created as mkstemp() would do it.

Returns an object with a file-like interface; the name of the file
is accessible as its 'name' attribute.  The file will be automatically
deleted when it is closed unless the 'delete' argument is set to False.

On POSIX, NamedTemporaryFiles cannot be automatically deleted if
the creating process is terminated abruptly with a SIGKILL signal.
Windows can delete the file even in this case.
r   bNc                  ,   > [        TTTTT5      u  nmU$ r   )r   )rM   r_   rw   r   r+   rx   ru   rv   s     r   opener"NamedTemporaryFile.<locals>.opener   s    !#vvukJD	r   	bufferingnewlineencodingr  r  bufferraw)ry   r   rg   r+   O_TEMPORARY_iotext_encodingr6   r   r   r3   r&   )moder!  r#  r"  rv   ru   rw   r   r  r   r  r   r%  r   r+   rx   s       ```      @@@r   r   r     s    6 (8'L$FFCE xx4F 
$$$X.D xxT '6%'	$$/C#uc*CCH(tVMM	JJLHHOJJts   >C -C CC >Dposixcygwin	O_TMPFILEr  c          
        ^^^^^^ SU ;  a  [         R                  " U5      n[        TTT5      u  mmmm[        m[        (       aE  SmUUU4S jn [         R
                  " TXX2XxS9n	[        U	SU	5      n
[        U
SU
5      n
TU
l        U	$ SmUUUUUU4S jn[         R
                  " TXX2UUS9n	[        U	SU	5      n
[        U
SU
5      n
TU
l        U	$ ! [         a    Sq NV[         a     Naf = f)	a(  Create and return a temporary file.
Arguments:
'prefix', 'suffix', 'dir' -- as for mkstemp.
'mode' -- the mode argument to io.open (default "w+b").
'buffering' -- the buffer size argument to io.open (default -1).
'encoding' -- the encoding argument to io.open (default None)
'newline' -- the newline argument to io.open (default None)
'errors' -- the errors argument to io.open (default None)
The file is created as mkstemp() would do it.

Returns an object with a file-like interface.  The file has no
name, and will cease to exist when it is closed.
r  Nc                     > T[         R                  -  [         R                  ) -  n[         R                  " TUS5      mT$ )Nr   )rg   r,  O_CREATr6   )rM   flags2rw   r_   r   s     r   r  TemporaryFile.<locals>.opener;  s3    #--/CKK<?XXc651	r   r   r$  r%  Fc                     > [        TTTTT5      u  mn [        R                  " U5        T$ ! [         a  n[        R                  " T5        e S nAff = fr   )r   rg   r&   BaseExceptionr3   )	rM   r+   erw   r_   r   rx   ru   rv   s	      r   r  r2  [  sQ    %c665+NHB

4  I ! 		"s   - 
AAA)
r'  r(  ry   r   _O_TMPFILE_WORKSr6   r   r+   IsADirectoryErrorr%   )r)  r!  r#  r"  rv   ru   rw   r  r  r   r%  r_   r   rx   s       ```    @@@r   r   r   !  s   $ d?((2H+;FFC+P([B
xxT(/'-> dHd3c5#.& 	 	 xxT '6%' dHd+c5#&E % ) $)   s   9C C-!	C-,C-c                   R   \ rS rSrSrSr   S'SS.S jjr\" \R                  5      r
S rS rS	 rS
 rS rS rS r\S 5       r\S 5       r\S 5       rS rS rS r\S 5       r\S 5       r\S 5       rS rS rS rS rS r S r!S r"S r#S r$S  r%S(S! jr&S" r'S# r(S$ r)S% r*S&r+g))r   il  zTemporary file wrapper, specialized to switch from BytesIO
or StringIO to a real file when it exceeds a certain size or
when a fileno is needed.
FNr-  c	          	          SU;   a  [         R                  " 5       U l        OD[         R                  " U5      n[         R                  " [         R                  " 5       XIUS9U l        Xl        SU l        X#XgXEXS.U l        g )Nr  )r#  r  r"  F)r)  r!  rv   ru   r#  r"  rw   r  )r'  BytesIO_filer(  TextIOWrapper	_max_size_rolled_TemporaryFileArgs)
r   max_sizer)  r!  r#  r"  rv   ru   rw   r  s
             r   r   SpooledTemporaryFile.__init__s  sm     $;DJ((2H**3;;=%-$+-DJ "+/-3/7*-#Ar   c                     U R                   (       a  g U R                  nU(       a&  UR                  5       U:  a  U R                  5         g g g r   )r>  r=  tellrollover)r   r   r@  s      r   _checkSpooledTemporaryFile._check  s4    <<>>		h.MMO /8r   c                    U R                   (       a  g U R                  n[        S0 U R                  D6=o l        U ?UR	                  5       n[        US5      (       a8  UR                  R                  UR                  5       R                  5       5        OUR                  UR                  5       5        UR                  US5        SU l         g )Nr$  r   TrK   )r>  r;  r   r?  rC  r  r$  r   detachgetvalueseek)r   r   newfileposs       r   rD  SpooledTemporaryFile.rollover  s    <<zz,Gt/F/FGG*#iik7H%%NN  !7!7!9:MM$--/*S!r   c                 R    U R                   R                  (       a  [        S5      eU $ )Nz%Cannot enter context with closed file)r;  closed
ValueErrorr   s    r   r  SpooledTemporaryFile.__enter__  s     ::DEEr   c                 8    U R                   R                  5         g r   r;  r3   r   rU   r  r  s       r   r  SpooledTemporaryFile.__exit__      

r   c                 6    U R                   R                  5       $ r   )r;  r   r   s    r   r   SpooledTemporaryFile.__iter__      zz""$$r   c                     U R                   (       d;  [        R                  " SR                  U 5      [        SU S9  U R                  5         g g )NzUnclosed file {!r}   )
stacklevelsource)rO  	_warningswarnformatResourceWarningr3   r   s    r   r   SpooledTemporaryFile.__del__  s<    {{NN$++D1	 JJL r   c                 8    U R                   R                  5         g r   rS  r   s    r   r3   SpooledTemporaryFile.close  rV  r   c                 .    U R                   R                  $ r   )r;  rO  r   s    r   rO  SpooledTemporaryFile.closed      zz   r   c                 .    U R                   R                  $ r   )r;  r#  r   s    r   r#  SpooledTemporaryFile.encoding      zz"""r   c                 .    U R                   R                  $ r   )r;  r  r   s    r   r  SpooledTemporaryFile.errors  rg  r   c                 V    U R                  5         U R                  R                  5       $ r   )rD  r;  filenor   s    r   rn  SpooledTemporaryFile.fileno  s    zz  ""r   c                 8    U R                   R                  5         g r   )r;  flushr   s    r   rq  SpooledTemporaryFile.flush  rV  r   c                 6    U R                   R                  5       $ r   )r;  isattyr   s    r   rt  SpooledTemporaryFile.isatty      zz  ""r   c                 n     U R                   R                  $ ! [         a    U R                  S   s $ f = f)Nr)  )r;  r)  r   r?  r   s    r   r)  SpooledTemporaryFile.mode  s5    	3::??" 	3**622	3s    44c                 P     U R                   R                  $ ! [         a     g f = fr   )r;  r+   r   r   s    r   r+   SpooledTemporaryFile.name  s'    	::??" 		s    
%%c                 .    U R                   R                  $ r   )r;  newlinesr   s    r   r|  SpooledTemporaryFile.newlines  rj  r   c                 6    U R                   R                  5       $ r   )r;  readabler   s    r   r  SpooledTemporaryFile.readable  rY  r   c                 4    U R                   R                  " U6 $ r   )r;  readr   rM   s     r   r  SpooledTemporaryFile.read      zz%%r   c                 4    U R                   R                  " U6 $ r   )r;  read1r  s     r   r  SpooledTemporaryFile.read1  s    zz&&r   c                 8    U R                   R                  U5      $ r   )r;  readintor   r  s     r   r  SpooledTemporaryFile.readinto  s    zz""1%%r   c                 8    U R                   R                  U5      $ r   )r;  	readinto1r  s     r   r  SpooledTemporaryFile.readinto1  s    zz##A&&r   c                 4    U R                   R                  " U6 $ r   )r;  readliner  s     r   r  SpooledTemporaryFile.readline  s    zz""D))r   c                 4    U R                   R                  " U6 $ r   )r;  	readlinesr  s     r   r  SpooledTemporaryFile.readlines  s    zz##T**r   c                 6    U R                   R                  5       $ r   )r;  seekabler   s    r   r  SpooledTemporaryFile.seekable  rY  r   c                 4    U R                   R                  " U6 $ r   )r;  rJ  r  s     r   rJ  SpooledTemporaryFile.seek  r  r   c                 6    U R                   R                  5       $ r   )r;  rC  r   s    r   rC  SpooledTemporaryFile.tell  s    zz  r   c                     Uc  U R                   R                  5       $ XR                  :  a  U R                  5         U R                   R                  U5      $ r   )r;  truncater=  rD  )r   sizes     r   r  SpooledTemporaryFile.truncate   sB    <::&&((nn$::&&t,,r   c                 6    U R                   R                  5       $ r   )r;  writabler   s    r   r  SpooledTemporaryFile.writable  rY  r   c                 b    U R                   nUR                  U5      nU R                  U5        U$ r   )r;  r   rE  )r   sr   rvs       r   r   SpooledTemporaryFile.write  s)    zzZZ]D	r   c                 "   U R                   S:X  d  U R                  (       a  U R                  R                  U5      $ [	        U5      nU HB  nU R                  U5        U R                  (       d  M'  U R                  R                  U5      s  $    g )Nr   )r=  r>  r;  
writelinesiterr   )r   iterableitr  s       r   r  SpooledTemporaryFile.writelines  sf    >>Q$,,::((22(^DJJt|||zz,,R00 r   c                 6    U R                   R                  5       $ r   )r;  rH  r   s    r   rH  SpooledTemporaryFile.detach  rv  r   )r?  r;  r=  r>  )r   w+bNNNNNr   ),r   r   r   r   r   r>  r   classmethod_typesGenericAlias__class_getitem__rE  rD  r  r  r   r   r3   r   rO  r#  r  rn  rq  rt  r)  r+   r|  r  r  r  r  r  r  r  r  rJ  rC  r  r  r   r  rH  r   rK   r   r   r   r   l  s.    G9;(,/3A?CA" $F$7$78*
% ! ! # # ! !## 3 3   # #%&'&'*+%&!-%1#r   r   c                       \ rS rSrSr  SSS.S jjr\SS j5       r\SS j5       rS	 r	S
 r
S rS r\" \R                  5      rSrg)r   i  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 everything contained
in it are removed (unless delete=False is passed or an exception
is raised during cleanup and ignore_cleanup_errors is not True).

Optional Arguments:
    suffix - A str suffix for the directory name.  (see mkdtemp)
    prefix - A str prefix for the directory name.  (see mkdtemp)
    dir - A directory to create this temp dir in.  (see mkdtemp)
    ignore_cleanup_errors - False; ignore exceptions during cleanup?
    delete - True; whether the directory is automatically deleted.
NT)r   c          	          [        XU5      U l        X@l        XPl        [        R
                  " X R                  U R                  SR                  U 5      U R                  U R                  S9U l        g )NzImplicitly cleaning up {!r})warn_messager^   r   )	r   r+   _ignore_cleanup_errors_delete_weakreffinalize_cleanupr`  
_finalizer)r   rv   ru   rw   ignore_cleanup_errorsr   s         r   r   TemporaryDirectory.__init__3  sX    FC0	&;#"++--6==dC55dllLr   c                 2   ^ ^^^ U UUU4S jn[        TUS9  g )Nc                 ~  > [        U[        5      (       ah  T(       a  UT:X  a	  T(       a  g e  UT:w  a(  [        [        R                  R                  U5      5        [        U5         [        R                  " U5        g [        U[        5      (       a  g T(       d  e g ! [         a    TR                  UTS9   g [         ai    [        R                  R                  U5      (       a$  [        R                  R                  U5      (       a
  T(       a   g e TR                  UTUT:H  S9   g f = f! [         a     g f = f)Nr^   )r^   repeated)r   r   r   rg   r"   r   r&   r7  ra   r   
isjunctionr   )r@   r"   rU   clsr^   r+   r  s      r   r   )TemporaryDirectory._rmtree.<locals>.onexc?  s   #//$t|#CHH$4$4T$:;%=

4(& C!233$ %+ - GDF* =  #xx~~d33sxx7J7J47P7P, &!D.2dl $ == ) sH   9D/ (B D,8D/ :AD,D/ D,)D/ +D,,D/ /
D<;D<)r   )ra   )r  r+   r^   r  r   s   ```` r   ra   TemporaryDirectory._rmtree=  s    $	 $	L 	E"r   c                 h    U(       a+  U R                  XS9  [        R                  " U[        5        g g Nr  )ra   r^  r_  ra  )r  r+   r  r^   r   s        r   r  TemporaryDirectory._cleanupg  s&    KKK:NN<9 r   c                 b    SR                  U R                  R                  U R                  5      $ )Nz	<{} {!r}>)r`  	__class__r   r+   r   s    r   __repr__TemporaryDirectory.__repr__m  s#    !!$.."9"9499EEr   c                     U R                   $ r   )r+   r   s    r   r  TemporaryDirectory.__enter__p  s    yyr   c                 H    U R                   (       a  U R                  5         g g r   )r  r   rT  s       r   r  TemporaryDirectory.__exit__s  s    <<LLN r   c                     U R                   R                  5       (       d.  [        R                  R	                  U R
                  5      (       a%  U R                  U R
                  U R                  S9  g g r  )r  rH  rg   r"   existsr+   ra   r  r   s    r   r   TemporaryDirectory.cleanupw  sK    ??!!##sxxtyy'A'ALL$2M2MLN (Br   )r  r  r  r+   NNNF)FF)FT)r   r   r   r   r   r   r  ra   r  r  r  r  r   r  r  r  r   rK   r   r   r   r     sp    & 6:',L8<L '# '#R : :
FO $F$7$78r   r   )FNr  rR   )r  r  NNNNNT)r  r  NNNNN)Rr   __all__	functoolsr  warningsr^  ior'  r   rg   shutil_shutilrmtreera   ImportErrorrW   r   r5   _statr-   rH   r6   r&   r$   supports_dir_fdr   supports_fdr   rY   errnor   randomrb   r   typesr  weakrefr  _threadallocate_lock_allocate_lockO_RDWRr0  O_EXCLr   r  rc   r   rd   r	   rs   r   ri   rq   ry   r{   r   r   r   r   r   r   r   r
   r   r   r   r   r   r   r   r   r   r   r   r+   platformr   r6  IOBaser   r   rK   r   r   <module>r     s  2    ~-NN'|  $    &&**s{{*SZZ7
3s~~%O 
3
cll"N
3	kkGG  
:,$? ?06*%X A:2"" 
''$CN&FP X4 @@( (V< <| ;?9=(,<8<'+<| 88w$--83 'M sK09=8<I*.IVp#3:: p#f\9 \9c  {-%<E!N "))RXX>))* >zzR^^3> ww""="== 
L-T L- L-_{-s   F BH65H6