grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026o ®û|jsã@sdZgd¢ZddlZddlZddlZddlZ ddl Z ddl Z ddlmZddlZddlZddlZddlZejZe je jBe jBZee dƒrJee jOZeZ ee dƒrVe e j!OZ ee dƒr_e j"Z"ndZ"d Z#eƒZ$d d „Z%d d „Z&dd„Z'Gdd„dƒZ(dd„Z)dd„Z*da+dd„Z,dd„Z-dd„Z.dd„Z/dd„Z0d d!„Z1da2d"d#„Z3d$d%„Z4d&d'„Z5dCd)d*„Z6dDd+d,„Z7d-e#dfd.d/„Z8Gd0d1„d1ƒZ9Gd2d3„d3ƒZ:   6dEdd7œd8d9„Z;e jnee d<ƒa?   dFdd7œd=d>„Z>Gd?d@„d@ƒZ@GdAdB„dBƒZAdS)Ga�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_BINARYri'ÚtmpcCs&zt |¡WdStyYdSw)NFT)Ú_osÚlstatÚOSError)Úfn©rú//opt/alt/python310/lib64/python3.10/tempfile.pyÚ_existsLs   ýÿrcGsˆd}|D],}|dur qt|tjƒrt |¡}t|tƒr&|tur#tdƒ‚t}q|tur.tdƒ‚t}q|durBtdus>tttƒr@tStS|S)zBLook at the type of all args and divine their implied return type.Nz1Can't mix bytes and non-bytes in path components.)Ú isinstancerÚPathLikeÚfspathÚbytesÚstrÚ TypeErrorr )ÚargsZ return_typeÚargrrrÚ_infer_return_typeUs$   r"cCsdt|||ƒ}|dur |ƒ}|dur|turt}nt t¡}|dur,|tur)tƒ}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ƒkrtƒ|_||_|jS)NÚ_rng_pid)rÚgetpidÚgetattrÚ_RandomZ_rngr+)ÚselfZcur_pidrrrÚrngŽs z_RandomNameSequence.rngcCs|S©Nr©r/rrrÚ__iter__–sz_RandomNameSequence.__iter__cCsd |jj|jdd�¡S)NÚé)Úk)Újoinr0ÚchoicesÚ charactersr2rrrÚ__next__™sz_RandomNameSequence.__next__N) Ú__name__Ú __module__Ú __qualname__Ú__doc__r9Úpropertyr0r3r:rrrrr*„s  r*c Cs g}dD]}t |¡}|r| |¡qtjdkr,| tj d¡tj d¡ddddg¡n| gd ¢¡z | t ¡¡W|St t fyO| tj ¡Y|Sw) z[Generate a list of candidate temporary directories which _get_default_tempdir will try.)ZTMPDIRZTEMPZTMPÚntz~\AppData\Local\Tempz%SYSTEMROOT%\Tempzc:\tempzc:\tmpz\tempz\tmp)z/tmpz/var/tmpz/usr/tmp) rÚgetenvÚappendÚnameÚextendÚpathÚ expanduserÚ expandvarsÚgetcwdÚAttributeErrorrÚcurdir)ÚdirlistZenvnameÚdirnamerrrÚ_candidate_tempdir_listœs$ €  þýýrMc Cstƒ}tƒ}|D]~}|tjkrtj |¡}tdƒD]l}t|ƒ}tj ||¡}z0t  |t d¡}zz t  |d¡Wt  |¡nt  |¡wWt  |¡nt  |¡w|WSty_Yqty|tjdkrytj |¡ryt |tj¡ryYqYn ty…Ynwqttjd|ƒ‚)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.édé€sblatr@z)No usable temporary directory found in %s)r*rMrrJrEÚabspathÚrangeÚnextr7ÚopenÚ_bin_openflagsÚwriteÚcloseÚunlinkÚFileExistsErrorÚPermissionErrorrCÚisdirÚaccessÚW_OKrÚFileNotFoundErrorÚ_errnoZENOENT)ZnamerrKr'ÚseqrCÚfilenameÚfdrrrÚ_get_default_tempdir·sB       ÿ ÿ€ÿÿrbcCóJtdur#t ¡ztdurtƒaWt ¡tSWt ¡tSt ¡wtS)z7Common setup sequence for all user-callable interfaces.N)Ú_name_sequenceÚ _once_lockÚacquirer*ÚreleaserrrrÚ_get_candidate_namesåsü ÿrhc CsÐtj |¡}tƒ}|turttj|ƒ}ttƒD]J}t |ƒ}tj  ||||¡}t   d|¡z t  ||d¡} Wn$ty@Yqty[tjdkrZtj |¡rZt |tj¡rZYq‚w| |fSttjdƒ‚)z>Code common to mkstemp, TemporaryFile, and NamedTemporaryFile.ztempfile.mkstemprOr@z#No usable temporary file name found)rrErPrhrÚmapr$rQrrRr7Ú_sysÚauditrSrXrYrCrZr[r\r^ÚEEXIST) r'ZpreZsufÚflagsr(Únamesr_rCÚfilerarrrÚ_mkstemp_innerós.       ÿù ÿrpcGsR|tjvr||g|¢RddiŽdStjdkstj |¡s'||g|¢RŽdSdS)NÚfollow_symlinksFr@)rÚsupports_follow_symlinksrCrEÚislink)ÚfuncrEr rrrÚ_dont_follow_symlinkss ÿrucCs<ztj}Wn tyYnwt||dƒttj|dƒdS)NréÀ)rÚchflagsrIruÚchmod)rErwrrrÚ _resetpermss  ÿ rycCó t t¡S)z7The default prefix for temporary directories as string.)rÚfsdecoder#rrrrr #ó r cCrz)z6The default prefix for temporary directories as bytes.)rr$r#rrrrr 'r|r cCrc)z&Private accessor for tempfile.tempdir.N)r rerfrbrgrrrrÚ _gettempdir-sü ÿr}cCó t tƒ¡S)z Returns tempfile.tempdir as str.)rr{r}rrrrr 9ó r cCr~)z"Returns tempfile.tempdir as bytes.)rr$r}rrrrr =rr FcCs2t|||ƒ\}}}}|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. 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_openflagsrTrp)r&r%r'Útextr(rmrrrrAs rc CsÐt|||ƒ\}}}}tƒ}|turttj|ƒ}ttƒD]F}t|ƒ}tj   ||||¡}t   d|¡z t  |d¡W|StyFYqtyatjdkr`tj  |¡r`t |tj¡r`Yq‚wttjdƒ‚)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.mkdtemprvr@z(No usable temporary directory name found)r)rhrrirr$rQrrRrEr7rjrkÚmkdirrXrYrCrZr[r\r^rl)r&r%r'r(rnr_rCrorrrrhs.     ö  ÿù ÿrr4cCs\|durtƒ}tƒ}ttƒD]}t|ƒ}tj ||||¡}t|ƒs'|Sqt t j dƒ‚)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 rhrQrrRrrEr7rrXr^rl)r&r%r'rnr_rCrorrrr�s ÿÿrc@sNeZdZdZdZdZd dd„Zejdkr!ej fdd „Z d d „Z dSd 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||_||_||_dSr1)rorCÚdelete©r/rorCr„rrrÚ__init__¸s z_TemporaryFileCloser.__init__r@cCsX|js(|jdur*d|_z|j ¡W|jr||jƒdSdS|jr'||jƒwwdSdS©NT)Ú close_calledrorVr„rC)r/rWrrrrVÇs  ÿ ÿûz_TemporaryFileCloser.closecCó | ¡dSr1)rVr2rrrÚ__del__Ñó z_TemporaryFileCloser.__del__cCs|js d|_|j ¡dSdSr‡)rˆrorVr2rrrrVÕsþ©T) r;r<r=r>rorˆr†rrCrWrVrŠrrrrrƒ°s   rƒc@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|||ƒ|_dSr1)rorCr„rƒÚ_closerr…rrrr†ãsz_TemporaryFileWrapper.__init__cs^|jd}t||ƒ}t|dƒr"|‰t ˆ¡‡fdd„ƒ}|j|_|}t|tƒs-t|||ƒ|S)NroÚ__call__csˆ|i|¤ŽSr1r)r Úkwargs©rtrrÚ func_wrapperñsz7_TemporaryFileWrapper.__getattr__..func_wrapper) Ú__dict__r-ÚhasattrÚ _functoolsÚwrapsrŽrÚintÚsetattr)r/rCroÚar’rr‘rÚ __getattr__és     z!_TemporaryFileWrapper.__getattr__cCs|j ¡|Sr1)roÚ __enter__r2rrrr›þs z_TemporaryFileWrapper.__enter__cCs|j |||¡}| ¡|Sr1)roÚ__exit__rV)r/ÚexcÚvalueÚtbÚresultrrrrœsz_TemporaryFileWrapper.__exit__cCs|j ¡dS)zA Close the temporary file, possibly deleting it. N)rŽrVr2rrrrV sz_TemporaryFileWrapper.closeccs�|jD]}|VqdSr1)ro)r/Úlinerrrr3s€ ÿz_TemporaryFileWrapper.__iter__NrŒ) r;r<r=r>r†ršr›rœrVr3rrrrr�Ûs  r�úw+béÿÿÿÿT©Úerrorsc sÞtˆˆˆƒ\‰‰‰‰t‰tjdkr|rˆtjO‰d|vr!t |¡}d‰‡‡‡‡‡‡fdd„} z,tjˆ|||||| d�} zt| d| ƒ} t| d| ƒ} ˆ| _t | ˆ|ƒWWS|   ¡‚ˆdurntjdkri|snt  ˆ¡‚) 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). '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. r@ÚbNcstˆˆˆˆˆƒ\}‰|Sr1)rp)r ra©r'rmrCr(r%r&rrÚopener:sz"NamedTemporaryFile..opener©Ú bufferingÚnewlineÚencodingr¥r¨ÚbufferÚraw) r)rTrrCZ O_TEMPORARYÚ_ioÚ text_encodingrSr-r�rVrW) Úmoderªr¬r«r&r%r'r„r¥r¨ror®rr§rrs2   þ   rÚposixÚcygwinÚ O_TMPFILEc súd|vr t |¡}tˆˆˆƒ\‰‰‰‰t‰trSd‰‡‡‡fdd„}ztjˆ||||||d�} t| d| ƒ} t| d| ƒ} ˆ| _| WStyJdaYn t yRYnwd‰‡‡‡‡‡‡fd d„}tjˆ||||||d�} t| d| ƒ} t| d| ƒ} ˆ| _| S) 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¦Ncs$ˆtjBtj@}t ˆ|d¡‰ˆS)NrO)rr´ÚO_CREATrS)r Zflags2)r'rarmrrr¨tszTemporaryFile..openerr©r­r®Fc sJtˆˆˆˆˆƒ\‰}zt |¡WˆSty$}zt ˆ¡‚d}~wwr1)rprrWÚ BaseExceptionrV)r rCÚe©r'rarmr(r%r&rrr¨”s ý €þ) r¯r°r)rTÚ_O_TMPFILE_WORKSrSr-rCÚIsADirectoryErrorr) r±rªr¬r«r&r%r'r¥r¨ror®rr¸rrZs>  þ    ø  þ  rc@seZdZdZdZ   d8ddœdd „ZeejƒZ d d „Z d d „Z dd„Z dd„Z dd„Zdd„Zedd„ƒZedd„ƒZedd„ƒZdd„Zdd„Zd d!„Zed"d#„ƒZed$d%„ƒZed&d'„ƒZd(d)„Zd*d+„Zd,d-„Zd.d/„Zd0d1„Zd9d2d3„Zd4d5„Z d6d7„Z!dS):rz�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. Frr¢r£Nr¤c  Cs^d|vr t ¡|_nt |¡}tjt ¡|| |d�|_||_d|_|||||||| dœ|_dS)Nr¦)r¬r¥r«F)r±rªr&r%r¬r«r'r¥)r¯ÚBytesIOÚ_filer°Ú TextIOWrapperÚ _max_sizeÚ_rolledÚ_TemporaryFileArgs) r/Úmax_sizer±rªr¬r«r&r%r'r¥rrrr†¬s   þ ýzSpooledTemporaryFile.__init__cCs4|jrdS|j}|r| ¡|kr| ¡dSdSdSr1)r¿r¾ÚtellÚrollover)r/rorÁrrrÚ_check¿s  ÿzSpooledTemporaryFile._checkcCsv|jrdS|j}tdi|j¤Ž}|_|`| ¡}t|dƒr)|j | ¡  ¡¡n| |  ¡¡|  |d¡d|_dS)Nr­rTr) r¿r¼rrÀrÂr”r­rUÚdetachÚgetvalueÚseek)r/roZnewfileÚposrrrrÃÅs    zSpooledTemporaryFile.rollovercCs|jjrtdƒ‚|S)Nz%Cannot enter context with closed file)r¼ÚclosedÚ ValueErrorr2rrrr›ÚszSpooledTemporaryFile.__enter__cCó|j ¡dSr1©r¼rV©r/r�ržrŸrrrrœßózSpooledTemporaryFile.__exit__cCó |j ¡Sr1)r¼r3r2rrrr3ãó zSpooledTemporaryFile.__iter__cCrËr1rÌr2rrrrVærÎzSpooledTemporaryFile.closecCó|jjSr1)r¼rÉr2rrrrÉéózSpooledTemporaryFile.closedcCrÑr1)r¼r¬r2rrrr¬írÒzSpooledTemporaryFile.encodingcCrÑr1)r¼r¥r2rrrr¥ñrÒzSpooledTemporaryFile.errorscCs| ¡|j ¡Sr1)rÃr¼Úfilenor2rrrrÓõs zSpooledTemporaryFile.filenocCrËr1)r¼Úflushr2rrrrÔùrÎzSpooledTemporaryFile.flushcCrÏr1)r¼Úisattyr2rrrrÕürÐzSpooledTemporaryFile.isattycCs(z|jjWSty|jdYSw)Nr±)r¼r±rIrÀr2rrrr±ÿs   ÿzSpooledTemporaryFile.modecCs z|jjWStyYdSwr1)r¼rCrIr2rrrrCs   ÿzSpooledTemporaryFile.namecCrÑr1)r¼Únewlinesr2rrrrÖ rÒzSpooledTemporaryFile.newlinescGó |jj|ŽSr1)r¼Úread©r/r rrrrØr‹zSpooledTemporaryFile.readcGr×r1)r¼ÚreadlinerÙrrrrÚr‹zSpooledTemporaryFile.readlinecGr×r1)r¼Ú readlinesrÙrrrrÛr‹zSpooledTemporaryFile.readlinescGr×r1)r¼rÇrÙrrrrÇr‹zSpooledTemporaryFile.seekcCrÏr1)r¼rÂr2rrrrÂrÐzSpooledTemporaryFile.tellcCs8|dur |j ¡dS||jkr| ¡|j |¡dSr1)r¼Útruncater¾rÃ)r/ÚsizerrrrÜ s  zSpooledTemporaryFile.truncatecCó|j}| |¡}| |¡|Sr1)r¼rUrÄ)r/ÚsroÚrvrrrrU(ó  zSpooledTemporaryFile.writecCrÞr1)r¼Ú writelinesrÄ)r/Úiterableroràrrrrâ.rázSpooledTemporaryFile.writelines)rr¢r£NNNNNr1)"r;r<r=r>r¿r†Ú classmethodÚ_typesÚ GenericAliasÚ__class_getitem__rÄrÃr›rœr3rVr?rÉr¬r¥rÓrÔrÕr±rCrÖrØrÚrÛrÇrÂrÜrUrârrrrr¥sNþ þ         rc@sdeZdZdZ  ddd„Zeddd„ƒZeddd „ƒZd d „Zd d „Z dd„Z dd„Z ee j ƒZdS)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. NFcCs:t|||ƒ|_||_tj||j|jd |¡|jd�|_dS)NzImplicitly cleaning up {!r})Ú warn_messageÚ ignore_errors)rrCÚ_ignore_cleanup_errorsÚ_weakrefZfinalizeÚ_cleanupÚformatÚ _finalizer)r/r&r%r'Zignore_cleanup_errorsrrrr†As  ýzTemporaryDirectory.__init__cs"‡‡‡fdd„}tjˆ|d�dS)Nc sžt|dtƒrAz/|ˆkrttj |¡ƒt|ƒz t |¡WWdSttfy3ˆj|ˆd�YnwWdSt y@YdSwt|dt ƒrJdSˆsM‚dS)Nr©ré) Ú issubclassrYryrrErLrWrºÚ_rmtreer])rtrEÚexc_info©ÚclsrérCrrÚonerrorLs&ÿ ÿÿz+TemporaryDirectory._rmtree..onerror)rõ)Ú_shutilZrmtree)rôrCrérõrrórrñJszTemporaryDirectory._rmtreecCs|j||d�t |t¡dS©Nrï)rñÚ _warningsÚwarnÚResourceWarning)rôrCrèrérrrrìbszTemporaryDirectory._cleanupcCsd |jj|j¡S)Nz <{} {!r}>)ríÚ __class__r;rCr2rrrÚ__repr__gszTemporaryDirectory.__repr__cCs|jSr1)rCr2rrrr›jszTemporaryDirectory.__enter__cCr‰r1)ÚcleanuprÍrrrrœmr‹zTemporaryDirectory.__exit__cCs2|j ¡s tj |j¡r|j|j|jd�dSdSr÷)rîrÅrrEÚexistsrCrñrêr2rrrrýpsÿzTemporaryDirectory.cleanup©NNNF)F)r;r<r=r>r†rärñrìrür›rœrýrårærçrrrrr5s  ÿ  rrÿ)NNN)r¢r£NNNNNT)r¢r£NNNNN)Br>Ú__all__Ú functoolsr•ÚwarningsrøÚior¯ÚosrZshutilröÚerrnor^Zrandomrr.ÚsysrjÚtypesråÚweakrefrëÚ_threadÚ allocate_lockZ_allocate_lockÚO_RDWRrµÚO_EXCLr€r”rrTrrr#rerr"r)r*rMrbrdrhrpruryr r r r}r r rrrrƒr�rrCÚplatformrr¹rrrrrrÚs‚        ,    '( +?þ þ5 þ þK