grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026B I³oLóùëlã @s dZddddddddd d d d d g ZddlZddlZddlZddlZ ddl Z ddl Z ddlmZddlZddlZejZe je jBe jBZee dƒršee jOZeZee dƒr²ee jOZee dƒrÄe jZndZdZeƒZ ee dƒräe j!Z"nee dƒröe j#Z"ndd„Z"dd„Z$dd„Z%dd„Z&Gdd „d ƒZ'd!d"„Z(d#d$„Z)da*d%d&„Z+d'd(„Z,d)d „Z-d*d „Z.da/d+d „Z0d,d „Z1d@d.d„Z2dAd/d„Z3d0edfd1d„Z4Gd2d3„d3ƒZ5Gd4d5„d5ƒZ6dBd9d„Z7e j8d:k�sÐe j9j:d;k�rÖe7Z;nee d<ƒad„dƒZ=Gd?d„de>ƒZ?dS)Da�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éN)ÚRandomÚ O_NOFOLLOWÚO_BINARYi'ZtmpÚlstatÚstatcCst |tj¡}t |¡dS)N)Ú_osÚopenÚO_RDONLYÚclose)ÚfnÚfd©rú-/opt/alt/python37/lib64/python3.7/tempfile.pyÚ_statPsrcCs*y t|ƒWntk r dSXdSdS)NFT)rÚOSError)rrrrÚ_existsTs  rcGs`d}xJ|D]B}|dkrq t|tƒr8|tkr2tdƒ‚t}q |tkrHtdƒ‚t}q W|dkr\tS|S)zBLook at the type of all args and divine their implied return type.Nz1Can't mix bytes and non-bytes in path components.)Ú isinstanceÚbytesÚstrÚ TypeError)ÚargsZ return_typeÚargrrrÚ_infer_return_type]s  r%cCsdt|||ƒ}|dkr|ƒ}|dkr:|tkr0t}n t t¡}|dkrX|tkrRtƒ}ntƒ}||||fS)z9Common parameter processing for most APIs in this module.N)r%r!ÚtemplaterÚfsencoder r )ÚprefixÚsuffixÚdirÚ output_typerrrÚ_sanitize_paramsrs  r,c@s0eZdZdZdZedd„ƒZdd„Zdd„Zd S) Ú_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.Z%abcdefghijklmnopqrstuvwxyz0123456789_cCs,t ¡}|t|ddƒkr&tƒ|_||_|jS)NÚ_rng_pid)rÚgetpidÚgetattrÚ_RandomZ_rngr.)ÚselfZcur_pidrrrÚrngŽs z_RandomNameSequence.rngcCs|S)Nr)r2rrrÚ__iter__–sz_RandomNameSequence.__iter__cs0|j‰|jj‰‡‡fdd„tdƒDƒ}d |¡S)Ncsg|] }ˆˆƒ‘qSrr)Ú.0Zdummy)ÚcÚchooserrú œsz0_RandomNameSequence.__next__..éÚ)Ú charactersr3ZchoiceÚrangeÚjoin)r2Zlettersr)r6r7rÚ__next__™sz_RandomNameSequence.__next__N) Ú__name__Ú __module__Ú __qualname__Ú__doc__r;Úpropertyr3r4r>rrrrr-„s  r-c Cs¨g}x$dD]}t |¡}|r | |¡q Wtjdkr\| tj d¡tj d¡ddddg¡n| d d d g¡y| t ¡¡Wn$t t fk r¢| tj ¡YnX|S) z[Generate a list of candidate temporary directories which _get_default_tempdir will try.)ZTMPDIRZTEMPZTMPÚntz~\AppData\Local\Tempz%SYSTEMROOT%\Tempzc:\tempzc:\tmpz\tempz\tmpz/tmpz/var/tmpz/usr/tmp) rÚgetenvÚappendÚnameÚextendÚpathÚ expanduserÚ expandvarsÚgetcwdÚAttributeErrorrÚcurdir)ÚdirlistZenvnameÚdirnamerrrÚ_candidate_tempdir_listŸs    rQc Cs4tƒ}tƒ}�x|D�]}|tjkr0tj |¡}xêtdƒD]Þ}t|ƒ}tj ||¡}y\t  |t d¡}zt k rªtj dkr¤tj |¡r¤t |tj¡r¤w$n‚YnX| tj |¡fSWt tjdƒ‚dS)z>Code common to mkstemp, TemporaryFile, and NamedTemporaryFile.i€rDz#No usable temporary file name foundN)rjr Úmaprr'r<rrVrIr=rr[r\rGr]r^r_rUraÚEEXIST) r*ZpreZsufÚflagsr+ÚnamesrbrGÚfilerrrrÚ_mkstemp_inner÷s$ rpcCstS)z-The default prefix for temporary directories.)r&rrrrr scCs t tƒ¡S)z6The default prefix for temporary directories as bytes.)rr'r rrrrr scCs2tdkr.t ¡ztdkr tƒaWdt ¡XtS)zAccessor for tempfile.tempdir.N)r rgrhrerirrrrr s  cCs t tƒ¡S)z)A bytes version of tempfile.gettempdir().)rr'r rrrrr +sFcCs2t|||ƒ\}}}}|rt}nt}t|||||ƒS)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. On some operating systems, this makes no difference. 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_openflagsrWrp)r)r(r*Útextr+rmrrrr/s c CsÔt|||ƒ\}}}}tƒ}|tkr.ttj|ƒ}x”ttƒD]ˆ}t|ƒ}tj   ||||¡}yt  |d¡WnRt k r€w8Yn>t k r¼tjdkr¶tj  |¡r¶t |tj¡r¶w8n‚YnX|SWt tjdƒ‚dS)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. iÀrDz(No usable temporary directory name foundN)r,rjr rkrr'r<rrVrIr=Úmkdirr[r\rGr]r^r_rarl)r)r(r*r+rnrbrGrorrrrWs&  r:cCs`|dkrtƒ}tƒ}x:ttƒD].}t|ƒ}tj ||||¡}t|ƒs|SqWt t j dƒ‚dS)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. Nz"No usable temporary filename found) r rjr<rrVrrIr=rr[rarl)r)r(r*rnrbrGrorrrr~sc@sLeZdZdZdZdZd dd„Zejdkr@ej fdd „Z d d „Z nd d „Z dS)Ú_TemporaryFileCloserz–A separate object allowing proper closing of a temporary file's underlying file object, without adding a __del__ method to the temporary file.NFTcCs||_||_||_dS)N)rorGÚdelete)r2rorGrurrrÚ__init__¦sz_TemporaryFileCloser.__init__rDcCs<|js8|jdk r8d|_z|j ¡Wd|jr6||jƒXdS)NT)Ú close_calledrorrurG)r2rZrrrrµs z_TemporaryFileCloser.closecCs | ¡dS)N)r)r2rrrÚ__del__¿sz_TemporaryFileCloser.__del__cCs|jsd|_|j ¡dS)NT)rwror)r2rrrrÃs)T) r?r@rArBrorwrvrrGrZrrxrrrrrtžs   rtc@sBeZdZdZddd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dS)Ú_TemporaryFileWrapperzÄTemporary 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. TcCs$||_||_||_t|||ƒ|_dS)N)rorGrurtÚ_closer)r2rorGrurrrrvÑsz_TemporaryFileWrapper.__init__cs^|jd}t||ƒ}t|dƒrD|‰t ˆ¡‡fdd„ƒ}|j|_|}t|tƒsZt|||ƒ|S)NroÚ__call__cs ˆ||ŽS)Nr)r#Úkwargs)ÚfuncrrÚ func_wrapperßsz7_TemporaryFileWrapper.__getattr__..func_wrapper) Ú__dict__r0ÚhasattrÚ _functoolsÚwrapsrzrÚintÚsetattr)r2rGroÚar~r)r}rÚ __getattr__×s     z!_TemporaryFileWrapper.__getattr__cCs|j ¡|S)N)roÚ __enter__)r2rrrr‡ìs z_TemporaryFileWrapper.__enter__cCs|j |||¡}| ¡|S)N)roÚ__exit__r)r2ÚexcÚvalueÚtbÚresultrrrrˆòsz_TemporaryFileWrapper.__exit__cCs|j ¡dS)zA Close the temporary file, possibly deleting it. N)rzr)r2rrrr÷sz_TemporaryFileWrapper.closeccsx|jD] }|VqWdS)N)ro)r2Úlinerrrr4þs z_TemporaryFileWrapper.__iter__N)T) r?r@rArBrvr†r‡rˆrr4rrrrryÉs ryúw+béÿÿÿÿTc Cs”t|||ƒ\}}}}t} tjdkr0|r0| tjO} t|||| |ƒ\} } y tj| ||||d�} t| | |ƒSt k rŽt  | ¡t  | ¡‚YnXdS)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) 'delete' -- whether the file is deleted on close (default True). 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. rD)Ú bufferingÚnewlineÚencodingN) r,rWrrGZ O_TEMPORARYrprXrryÚ BaseExceptionrZr) Úmoder�r’r‘r)r(r*rur+rmrrGrorrrrs      ÚposixÚcygwinÚ O_TMPFILEc Csêt|||ƒ\}}}}t}tršy$|tjBtj@} t || d¡} Wn*tk rXdaYnBtk rjYn0Xyt j| ||||d�St  | ¡‚YnXt |||||ƒ\} } yt  | ¡t j| ||||d�St  | ¡‚YnXdS)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) 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. i€F)r�r‘r’N) r,rWÚ_O_TMPFILE_WORKSrr—ÚO_CREATrÚIsADirectoryErrorrrXrrprZ) r”r�r’r‘r)r(r*r+rmZflags2rrGrrrr9s0       c@sðeZdZdZdZd7dd„Zd d „Zd d „Zd d„Zdd„Z dd„Z dd„Z e dd„ƒZ e dd„ƒZdd„Zdd„Zdd„Ze dd „ƒZe d!d"„ƒZe d#d$„ƒZd%d&„Zd'd(„Zd)d*„Zd+d,„Ze d-d.„ƒZd/d0„Zd8d1d2„Zd3d4„Zd5d6„ZdS)9rz�Temporary 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. Frúw+br�Nc CsPd|krt ¡|_ntjt ¡||d�|_||_d|_|||||||dœ|_dS)NÚb)r’r‘F)r”r�r)r(r’r‘r*)rXÚBytesIOÚ_fileÚ TextIOWrapperÚ _max_sizeÚ_rolledÚ_TemporaryFileArgs) r2Úmax_sizer”r�r’r‘r)r(r*rrrrvzs   zSpooledTemporaryFile.__init__cCs,|jr dS|j}|r(| ¡|kr(| ¡dS)N)r¡r ÚtellÚrollover)r2ror£rrrÚ_check‰s zSpooledTemporaryFile._checkcCsr|jr dS|j}tf|jŽ}|_|`| ¡}t|dƒrN|j | ¡  ¡¡n| |  ¡¡|  |d¡d|_dS)NÚbufferrT) r¡ržrr¢r¤r€r§rYÚdetachÚgetvalueÚseek)r2roZnewfileÚposrrrr¥�s  zSpooledTemporaryFile.rollovercCs|jjrtdƒ‚|S)Nz%Cannot enter context with closed file)ržÚclosedÚ ValueError)r2rrrr‡¤szSpooledTemporaryFile.__enter__cCs|j ¡dS)N)ržr)r2r‰rŠr‹rrrrˆ©szSpooledTemporaryFile.__exit__cCs |j ¡S)N)ržr4)r2rrrr4­szSpooledTemporaryFile.__iter__cCs|j ¡dS)N)ržr)r2rrrr°szSpooledTemporaryFile.closecCs|jjS)N)ržr¬)r2rrrr¬³szSpooledTemporaryFile.closedcCs8y|jjStk r2d|jdkr(‚|jdSXdS)Nrœr”r’)ržr’rMr¢)r2rrrr’·s zSpooledTemporaryFile.encodingcCs| ¡|j ¡S)N)r¥ržÚfileno)r2rrrr®ÀszSpooledTemporaryFile.filenocCs|j ¡dS)N)ržÚflush)r2rrrr¯ÄszSpooledTemporaryFile.flushcCs |j ¡S)N)ržÚisatty)r2rrrr°ÇszSpooledTemporaryFile.isattycCs(y|jjStk r"|jdSXdS)Nr”)ržr”rMr¢)r2rrrr”ÊszSpooledTemporaryFile.modecCs"y|jjStk rdSXdS)N)ržrGrM)r2rrrrGÑszSpooledTemporaryFile.namecCs8y|jjStk r2d|jdkr(‚|jdSXdS)Nrœr”r‘)ržÚnewlinesrMr¢)r2rrrr±Øs zSpooledTemporaryFile.newlinescGs |jj|ŽS)N)ržÚread)r2r#rrrr²ászSpooledTemporaryFile.readcGs |jj|ŽS)N)ržÚreadline)r2r#rrrr³äszSpooledTemporaryFile.readlinecGs |jj|ŽS)N)ržÚ readlines)r2r#rrrr´çszSpooledTemporaryFile.readlinescGs |jj|ŽS)N)ržrª)r2r#rrrrªêszSpooledTemporaryFile.seekcCs|jjS)N)ržÚ softspace)r2rrrrµíszSpooledTemporaryFile.softspacecCs |j ¡S)N)ržr¤)r2rrrr¤ñszSpooledTemporaryFile.tellcCs6|dkr|j ¡n||jkr&| ¡|j |¡dS)N)ržÚtruncater r¥)r2Úsizerrrr¶ôs   zSpooledTemporaryFile.truncatecCs|j}| |¡}| |¡|S)N)ržrYr¦)r2ÚsroÚrvrrrrYüs  zSpooledTemporaryFile.writecCs|j}| |¡}| |¡|S)N)ržÚ writelinesr¦)r2Úiterableror¹rrrrºs  zSpooledTemporaryFile.writelines)rr›r�NNNNN)N)r?r@rArBr¡rvr¦r¥r‡rˆr4rrCr¬r’r®r¯r°r”rGr±r²r³r´rªrµr¤r¶rYrºrrrrrss8        c@sFeZdZdZddd„Zedd„ƒZdd„Zd d „Zd d „Z d d„Z dS)ra+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. NcCs0t|||ƒ|_tj||j|jd |¡d�|_dS)NzImplicitly cleaning up {!r})Ú warn_message)rrGÚ_weakrefZfinalizeÚ_cleanupÚformatÚ _finalizer)r2r)r(r*rrrrvs zTemporaryDirectory.__init__cCst |¡t |t¡dS)N)Ú_shutilÚrmtreeÚ _warningsÚwarnÚResourceWarning)ÚclsrGr¼rrrr¾s zTemporaryDirectory._cleanupcCsd |jj|j¡S)Nz <{} {!r}>)r¿Ú __class__r?rG)r2rrrÚ__repr__ szTemporaryDirectory.__repr__cCs|jS)N)rG)r2rrrr‡#szTemporaryDirectory.__enter__cCs | ¡dS)N)Úcleanup)r2r‰rŠr‹rrrrˆ&szTemporaryDirectory.__exit__cCs|j ¡rt |j¡dS)N)rÀr¨rÁrÂrG)r2rrrrÉ)s zTemporaryDirectory.cleanup)NNN) r?r@rArBrvÚ classmethodr¾rÈr‡rˆrÉrrrrr s   )NNNF)NNN)rŽr�NNNNNT)rŽr�NNNNN)@rBÚ__all__Ú functoolsr�ÚwarningsrÃÚiorXÚosrZshutilrÁÚerrnoraZrandomrr1Úweakrefr½Ú_threadÚ allocate_lockZ_allocate_lockÚO_RDWRr™ÚO_EXCLrqr€rrWrrr&rgrrrrr%r,r-rQrerfrjrpr r r r r rrrrtryrrGÚsysÚplatformrr˜rÚobjectrrrrrÚs€         -  ( ' +? $  8