Qf}dZgdZddlZddlZddlZddlZ ddl Z ddl Z ddlmZddlZddlZddlZddlZej0Ze j4e j6ze j8zZee dree j>zZeZ ee dre e jBzZ ee dr e jDZ"ndZ"d Z#eZ$d Z%d Z&d Z'Gd dZ(dZ)dZ*da+dZ,dZ-dZ.dZ/dZ0dZ1da2dZ3dZ4dZ5d.dZ6d/dZ7de#dfdZ8GddZ9Gd d!Z: d0dd"d#d$Z;e jxd%k7sejzd&k(re;Z>nee d'a? d1dd(d)Z>Gd*d+ejZAGd,d-ZBy)2aTemporary 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 TemporaryFileSpooledTemporaryFileTemporaryDirectorymkstempmkdtempmktempTMP_MAX gettempprefixtempdir gettempdirgettempprefixb gettempdirbN)Random O_NOFOLLOWO_BINARYr i'tmpcN tj|y#t$rYywxYw)NTF)_oslstatOSError)fns //opt/alt/python312/lib64/python3.12/tempfile.py_existsrLs+ "    $$cRd}|D]w}|t|tjrtj|}t|tr|t ur t dt}_|tur t dt }y|&tttt rt StS|S)zBLook at the type of all args and divine their implied return type.Nz1Can't mix bytes and non-bytes in path components.) isinstancerPathLikefspathbytesstr TypeErrorr )args return_typeargs r_infer_return_typer&UsK ;  c3<< (**S/C c5 !c!!344Ke#!344K!" ?j#6JL ct|||}||}|(|turt}ntjt}||tur t }n t }||||fS)z9Common parameter processing for most APIs in this module.)r&r!templaterfsencoder r)prefixsuffixdir output_types r_sanitize_paramsr/rsf$VVS9K ~ ~ # F\\(+F { # ,C-C 63 ++r'c0eZdZdZdZedZdZdZy)_RandomNameSequencea,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_ctj}|t|ddk7rt|_||_|jS)N_rng_pid)rgetpidgetattr_Random_rngr4)selfcur_pids rrngz_RandomNameSequence.rngs8**, gdJ5 5 DI#DMyyr'c|SNr9s r__iter__z_RandomNameSequence.__iter__s r'cndj|jj|jdS)N)k)joinr;choices charactersr?s r__next__z_RandomNameSequence.__next__s)wwtxx''1'=>>r'N) __name__ __module__ __qualname____doc__rGpropertyr;r@rHr>r'rr1r1s*+9J ?r'r1c g}dD]+}tj|}|s|j|-tjdk(rR|j tj j dtj jdddddgn|j gd  |jtj|S#ttf$r#|jtjY|SwxYw) z[Generate a list of candidate temporary directories which _get_default_tempdir will try.)TMPDIRTEMPTMPntz~\AppData\Local\Tempz%SYSTEMROOT%\Tempzc:\tempzc:\tmpz\tempz\tmp)z/tmpz/var/tmpz/usr/tmp) rgetenvappendnameextendpath expanduser expandvarsgetcwdAttributeErrorrcurdir)dirlistenvnamedirnames r_candidate_tempdir_listr`sG+**W% GNN7++  xx4,,-DE,,-AB#Y'D E 9:#szz|$ N G $#szz" N#s,#C.DDc|t}t}|D]}|tjk7rtjj |}t dD]}t|}tjj||} tj|td} tj|dtj| tj||ccSt+t,j.d|z#tj|wxYw#tj|wxYw#t$rYt$r^tj dk(rFtjj#|r'tj$|tj&rYSYt($rYwxYw)aqCalculate 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.dsblatrRz)No usable temporary directory found in %s)r1r`rr\rWabspathrangenextrEopen_bin_openflagswritecloseunlinkFileExistsErrorPermissionErrorrUisdiraccessW_OKrFileNotFoundError_errnoENOENT)namerr]r-seqrUfilenamefds r_get_default_tempdirrxsI !E%'G #** ((""3'C:C;Dxx}}S$/H XXh>)& "g. " JJx(  8 FMMG#$ %% " JJx(" " HH$)<JJsCHH-  sID>#D 9D$D> D!!D$$D;;D>> F; AF;.F;:F;ct?tj t tatj tStS#tj wxYw)z7Common setup sequence for all user-callable interfaces.)_name_sequence _once_lockacquirer1releaser>r'r_get_candidate_namesr~sP !%!4!6    >    A A"ctjj|}t}|turt tj |}ttD]f}t|}tjj|||z|z}tjd| tj||d} | |fcStt(j*d#t$rYt$rZtj dk(rEtjj#|r&tj$|tj&rYwxYw)z>Code common to mkstemp, TemporaryFile, and NamedTemporaryFile.ztempfile.mkstemprcrRz#No usable temporary file name found)rrWrdr~r mapr*rer rfrE_sysauditrgrlrmrUrnrorprrEEXIST) r-presufflagsr.namesrurUfilerws r_mkstemp_innerrs ((  3 C "EeCLL%(W~E{xx}}S#*s"23 %t, $u-B4x!$ &--? AA   D SXX^^C%8 3) s&C E )AE  E c|tjvr ||g|ddiytjdk(stjj |s ||g|yy)Nfollow_symlinksFrR)rsupports_follow_symlinksrUrWislink)funcrWr#s r_dont_follow_symlinksrsO s+++ T0D0%0 T !6 TD"7r'c tj}t||dttj|dy#t$rY'wxYw)Nr)rchflagsrr[chmod)rWrs r _resetpermsrsB0++ gtQ/#))T51    s; AAc4tjtS)z7The default prefix for temporary directories as string.)rfsdecoder)r>r'rr r # << !!r'c4tjtS)z6The default prefix for temporary directories as bytes.)rr*r)r>r'rr r 'rr'ct?tj t tatj tStS#tj wxYw)z&Private accessor for tempfile.tempdir.)r r{r|rxr}r>r'r _gettempdirr-sL !.0    N7N    rc<tjtS)z Returns tempfile.tempdir as str.)rrrr>r'rr r 9 << &&r'c<tjtS)z"Returns tempfile.tempdir as bytes.)rr*rr>r'rrr=rr'cbt|||\}}}}|rt}nt}t|||||S)aUser-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. )r/_text_openflagsrhr)r,r+r-textr.rs rrrAs;:(8'L$FFC  #vvuk BBr'ct|||\}}}}t}|turttj |}t tD]}t|}tjj|||z|z}tjd| t j|dtjj)|cStt*j,d#t$rYt$r[tj dk(rFtjj#|r't j$|tj&rY wxYw)aUser-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. ztempfile.mkdtemprrRz(No usable temporary directory name found)r/r~r rrr*rer rfrWrErrmkdirrlrmrUrnrorprdrrr)r,r+r-r.rrurUrs rrrhs(8'L$FFC "EeCLL%(W~E{xx}}S&4-&"89 %t,  IIdE "xx%%!$ &--D FF   D SXX^^C%8 3) sC++ E6AEErBc | t}t}ttD]B}t |}t j j|||z|z}t|r@|cSttjd)aUser-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~rer rfrrWrErrlrrr)r,r+r-rrurUrs rrrsr$ {l "EW~E{xx}}S&4-&"89t}K  &--> @@r'cfeZdZdZdZdZd dZejdk(ejfdZ dZ dZ y) _TemporaryFileCloserzA separate object allowing proper closing of a temporary file's underlying file object, without adding a __del__ method to the temporary file.Fc<||_||_||_||_yr=)rrUdeletedelete_on_closer9rrUrrs r__init__z_TemporaryFileCloser.__init__s   .r'rRc|jsed|_ |js!d|_|jj|jr#|r |j s ||j yyyy#t$rYywxYw#|jr2|r |j s# ||j w#t$rYwwxYwwwxYwNT)cleanup_called close_calledrrjrrrUrq)r9windowsrks rcleanupz_TemporaryFileCloser.cleanups"""&D  (((,D%IIOO%;;D4H4Htyy)5I;#-;;D4H4Htyy),5I;sA-BA33 A?>A?CB10C1 B=:C<B==Cc|jsMd|_ |jj|jr|jr|j yyyy#|jr|jr|j wwwxYwr)rrrjrrrr?s rrjz_TemporaryFileCloser.closesm  $D  # !;;4#7#7LLN$8; ! ;;4#7#7LLN$8;s A,Bc$|jyr=)rr?s r__del__z_TemporaryFileCloser.__del__s  r'NTT) rIrJrKrLrrrrrUrkrrjrr>r'rrrs;NL/ #xx4/ #r'rc6eZdZdZd dZdZdZdZdZdZ y) _TemporaryFileWrapperzTemporary 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. cF||_||_t|||||_yr=)rrUr_closerrs rrz_TemporaryFileWrapper.__init__s%  +D$,;= r'c|jd}t||}t|dr2|tjfd}|j |_|}t |ts t||||S)Nr__call__c|i|Sr=r>)r#kwargsrs r func_wrapperz7_TemporaryFileWrapper.__getattr__..func_wrappersT,V,,r') __dict__r6hasattr _functoolswrapsrrintsetattr)r9rUrarrs @r __getattr__z!_TemporaryFileWrapper.__getattr__sy}}V$ D$  1j !D   d # -$ -$(<r'rrrs%= *  r'rT)errorsrc   t\t tjdk(r|r| r tjz d|vrt j |}d fd} t j|||||| } t| d| } t| d| } | _t| || S#| jxYw#,tjdk(r|r| stjxYw)aCreate 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. rRbNc,t\}|Sr=)r)r#rwr-rrUr.r+r,s ropenerz"NamedTemporaryFile..openerAs!#vvukJD r' bufferingnewlineencodingrrbufferraw) r/rhrrU O_TEMPORARY_io text_encodingrgr6rrjrk)moderrrr,r+r-rrrrrrrrUr.s ``` @@@rrrs6(8'L$FFC E xx4F   $$$X. DxxTY '(6%' $$/C#uc*CCH(tV_M M  JJL    HH O JJt  s/C .B;;CC1Dposixcygwin O_TMPFILErc  d|vrtj|}t\ t trId  fd} tj ||||||} t | d| } t | d| } | _| Sd  fd}tj ||||||} t | d| } t | d| } | _| S#t$rdaYXt$rYbwxYw) aCreate 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. rNctjztjz}tj|dS)Nrc)rrO_CREATrg)r#flags2r-rwrs rrzTemporaryFile..opener|s3#--/CKK<?XXc651 r'rrrFct\} tj|S#t$r}tjd}~wwxYwr=)rrrk BaseExceptionrj) r#rUer-rwrr.r+r,s rrzTemporaryFile..openersQ%c665+NHB  4 I!  "  s, AA  A) rrr/rh_O_TMPFILE_WORKSrgr6rUIsADirectoryErrorr)rrrrr,r+r-rrrrrwrr.s ``` @@@rrrbs$ d?((2H+;FFC+P([ B   xxTY(/('-f>dHd3c5#. &  xxTY '(6%'dHd+c5#& E% ) $)   s>C C*C*)C*cDeZdZdZdZ d%dddZeejZ dZ dZ dZ d Z d Zd Zd Zed ZedZedZdZdZdZedZedZedZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$d&d Z%d!Z&d"Z'd#Z(d$Z)y)'rzTemporary 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. FNrc  d|vrtj|_nEtj|}tjtj|| ||_||_d|_|||||||| d|_y)Nr)rrrF)rrr,r+rrr-r)rBytesIO_filer TextIOWrapper _max_size_rolled_TemporaryFileArgs) r9max_sizerrrrr,r+r-rs rrzSpooledTemporaryFile.__init__sy $;DJ((2H**3;;=%-f$+-DJ" +/i-3v/7G*-#Ar'c|jry|j}|r%|j|kDr|jyyyr=)rrtellrollover)r9rrs r_checkzSpooledTemporaryFile._checks4 <<>>  h. MMO/8r'c|jry|j}tdi|jx}|_|`|j }t |dr8|j j|jjn|j|j|j|dd|_y)NrrTr>) rrrrrrrridetachgetvalueseek)r9rnewfileposs rrzSpooledTemporaryFile.rollovers <<zz,Gt/F/FGG$*  #iik 7H % NN !7!7!9 : MM$--/ * S! r'cH|jjr td|S)Nz%Cannot enter context with closed file)rclosed ValueErrorr?s rrzSpooledTemporaryFile.__enter__s ::  DE E r'c8|jjyr=rrjr9rrrs rrzSpooledTemporaryFile.__exit__ r'c6|jjSr=)rr@r?s rr@zSpooledTemporaryFile.__iter__zz""$$r'c|js=tjdj|td||j yy)NzUnclosed file {!r}) stacklevelsource)r _warningswarnformatResourceWarningrjr?s rrzSpooledTemporaryFile.__del__s<{{ NN$++D1   JJLr'c8|jjyr=rr?s rrjzSpooledTemporaryFile.closerr'c.|jjSr=)rrr?s rrzSpooledTemporaryFile.closedzz   r'c.|jjSr=)rrr?s rrzSpooledTemporaryFile.encodingzz"""r'c.|jjSr=)rrr?s rrzSpooledTemporaryFile.errorsrr'cV|j|jjSr=)rrfilenor?s rrzSpooledTemporaryFile.filenos zz  ""r'c8|jjyr=)rflushr?s rrzSpooledTemporaryFile.flush rr'c6|jjSr=)risattyr?s rrzSpooledTemporaryFile.isattyzz  ""r'cl |jjS#t$r|jdcYSwxYw)Nr)rrr[rr?s rrzSpooledTemporaryFile.modes5 3::?? " 3**62 2 3s 33cN |jjS#t$rYywxYwr=)rrUr[r?s rrUzSpooledTemporaryFile.names' ::?? "  rc.|jjSr=)rnewlinesr?s rr"zSpooledTemporaryFile.newlinesrr'c6|jjSr=)rreadabler?s rr$zSpooledTemporaryFile.readable#r r'c4|jj|Sr=)rreadr9r#s rr&zSpooledTemporaryFile.read&tzz%%r'c4|jj|Sr=)rread1r's rr*zSpooledTemporaryFile.read1)stzz&&r'c8|jj|Sr=)rreadintor9rs rr,zSpooledTemporaryFile.readinto,szz""1%%r'c8|jj|Sr=)r readinto1r-s rr/zSpooledTemporaryFile.readinto1/szz##A&&r'c4|jj|Sr=)rreadliner's rr1zSpooledTemporaryFile.readline2s"tzz""D))r'c4|jj|Sr=)r readlinesr's rr3zSpooledTemporaryFile.readlines5s#tzz##T**r'c6|jjSr=)rseekabler?s rr5zSpooledTemporaryFile.seekable8r r'c4|jj|Sr=)rrr's rrzSpooledTemporaryFile.seek;r(r'c6|jjSr=)rrr?s rrzSpooledTemporaryFile.tell>szz  r'c||jjS||jkDr|j|jj|Sr=)rtruncaterr)r9sizes rr9zSpooledTemporaryFile.truncateAsD <::&&( (dnn$ ::&&t, ,r'c6|jjSr=)rwritabler?s rr<zSpooledTemporaryFile.writableIr r'cb|j}|j|}|j||Sr=)rrir)r9srrvs rrizSpooledTemporaryFile.writeLs)zz ZZ] D r'cb|j}|j|}|j||Sr=)r writelinesr)r9iterablerr?s rrAzSpooledTemporaryFile.writelinesRs*zz __X & D r'c6|jjSr=)rrr?s rrzSpooledTemporaryFile.detachXrr')rw+bNNNNNr=)*rIrJrKrLrr classmethod_types GenericAlias__class_getitem__rrrrr@rrjrMrrrrrrrrUr"r$r&r*r,r/r1r3r5rrr9r<rirArr>r'rrrs.G9;(,/3A?CA"$F$7$78 * %!!##!!##33  ##%&'&'*+%&!-%  #r'rceZdZdZ d dddZed dZeddZdZd Z d Z d Z ee jZy)raCreate 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)rct||||_||_||_t j ||j |jdj||j|j|_y)NzImplicitly cleaning up {!r}) warn_message ignore_errorsr) rrU_ignore_cleanup_errors_delete_weakreffinalize_cleanupr _finalizer)r9r,r+r-ignore_cleanup_errorsrs rrzTemporaryDirectory.__init__ps`FFC0 &;# "++ $--6==dC55dllLr'cJfd}tj|y)Nc2t|tr]r |k(rry |k7r(ttjj |t| tj |yyyt|trysy#t$rj|Y4t$r]tjj|rtjj|rrYyj||k(YwxYw#t$rYywxYw)NrM)rMrepeated) rrmrrrWr_rkr_rmtreern isjunctionrq)rrWrclsrMrUrXs ronexcz)TemporaryDirectory._rmtree..onexc|s#/ $t|#CHH$4$4T$:;%= 4(=G"C!23$%+-G D F* = #xx~~d3sxx7J7J47P, &! D .2dl$= =)sH8D BD D "AD*D ,DD DD DD)r\)_shutilrmtree)r[rUrMrXr\s```` rrYzTemporaryDirectory._rmtreezs$ L t5)r'cd|r.|j||tj|tyyNrW)rYrrr)r[rUrLrMrs rrRzTemporaryDirectory._cleanups(  KKMK : NN< 9 r'cbdj|jj|jS)Nz <{} {!r}>)r __class__rIrUr?s r__repr__zTemporaryDirectory.__repr__s#!!$.."9"9499EEr'c|jSr=)rUr?s rrzTemporaryDirectory.__enter__s yyr'c>|jr|jyyr=)rOrrs rrzTemporaryDirectory.__exit__s << LLN r'c|jjs)tjj |j r(|j |j |jyyr`)rSrrrWexistsrUrYrNr?s rrzTemporaryDirectory.cleanupsE ?? ! ! #sxxtyy'A LL$2M2ML N(Br'NNNF)FF)FT)rIrJrKrLrrFrYrRrcrrrrGrHrIr>r'rrr\sp&6:',L8<L'*'*R:: FO$F$7$78r'rrh)NNN)rDrENNNNNT)rDrENNNNN)CrL__all__ functoolsrwarningsriorosrshutilr]errnorrrandomrr7sysrtypesrGweakrefrP_thread allocate_lock_allocate_lockO_RDWRrO_EXCLrrrrhrr r)r{rr&r/r1r`rxrzr~rrrr r r rr rrrrrrrrUplatformrrIOBaserrr>r'rr{s2 $&&**s{{*SZZ7 3 s~~%O  3 cll"N 3 kkGG   :,$??06*%X A:2""  ''$CN&FPX4@@((V<<|;?9=(,<8<'+<|88w$--83'M sK09=8<I*.IVl#3::l#^\9\9r'