a ¾þõj}ã@shdZgd¢ZddlZddlZddlZddlZ ddl Z ddl Z ddlmZddlZddlZddlZddlZddlZejZe je jBe jBZe e dƒrœee j!OZeZ"e e dƒr´e"e j#OZ"e e 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„Z0dd„Z1dd„Z2e j3e j4e jhe j5k�oXe j3e j6vZ7d d!„Z8ze j9e j:Be j!BZ;Wne<�y�dZ;Yn0d"d#„Z=d$d%„Z>d&d'„Z?da@d(d)„ZAd*d+„ZBdGd-d.„ZCdHd/d0„ZDd1e%dfd2d3„ZEGd4d5„d5ƒZFGd6d7„d7ƒZGdIdd;œdk�s&ejJd?k�r,eHZKne e d@ƒaLdJdd;œdAdB„ZKGdCdD„dDƒZMGdEdF„dFeNƒZOdS)Ka�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 |¡Wnty"YdS0dSdS)NFT)Ú_osÚlstatÚOSError)Úfn©rú /usr/lib64/python3.9/tempfile.pyÚ_existsMs  rcGsrd}|D]X}|durqt|tjƒr,t |¡}t|tƒrL|turFtdƒ‚t}q|tur\tdƒ‚t}q|durntS|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Ú TypeError)ÚargsÚ return_typeÚargrrrÚ_infer_return_typeVs    r#cCsdt|||ƒ}|dur|ƒ}|dur:|tur0t}n t t¡}|durX|turRtƒ}ntƒ}||||fS)z9Common parameter processing for most APIs in this module.N)r#rÚtemplaterÚfsencoder r )ÚprefixÚsuffixÚdirÚ output_typerrrÚ_sanitize_paramsos  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.Ú%abcdefghijklmnopqrstuvwxyz0123456789_cCs,t ¡}|t|ddƒkr&tƒ|_||_|jS)NÚ_rng_pid)rÚgetpidÚgetattrÚ_RandomÚ_rngr-)ÚselfÚcur_pidrrrÚrng‹s z_RandomNameSequence.rngcCs|S©Nr©r2rrrÚ__iter__“sz_RandomNameSequence.__iter__cs0|j‰|jj‰‡‡fdd„tdƒDƒ}d |¡S)Ncsg|] }ˆˆƒ‘qSrr)Ú.0Údummy©ÚcÚchooserrÚ ™óz0_RandomNameSequence.__next__..éÚ)Ú charactersr4ÚchoiceÚrangeÚjoin)r2Úlettersrr:rÚ__next__–sz_RandomNameSequence.__next__N) Ú__name__Ú __module__Ú __qualname__Ú__doc__rAÚpropertyr4r7rFrrrrr+�s  r+c Cs g}dD]}t |¡}|r| |¡qtjdkrX| tj d¡tj d¡ddddg¡n| gd ¢¡z| t ¡¡Wn"t t fyš| tj ¡Yn0|S) z[Generate a list of candidate temporary directories which _get_default_tempdir will try.)ÚTMPDIRÚTEMPÚTMPÚ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)ÚdirlistÚenvnameÚdirnamerrrÚ_candidate_tempdir_listœs   þr]c Cshtƒ}tƒ}|D�]@}|tjkr,tj |¡}tdƒD�]}t|ƒ}tj ||¡}zŽt  |t d¡}zdzHt j |ddd��}|  d¡Wdƒn1s”0YWt  |¡n t  |¡0Wt |¡n t |¡0|WStyðYq4t�y6tjdk�r,tj |¡�r,t |tj¡�r,Yq4YqYq4t�yNYqYq40q4qttjd |ƒ‚dS) 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é€ÚwbF)ÚclosefdsblatNrOz)No usable temporary directory found in %s)r+r]rrYrTÚabspathrCÚnextrDÚopenÚ_bin_openflagsÚ_ioÚwriteÚcloseÚunlinkÚFileExistsErrorÚPermissionErrorrRÚisdirÚaccessÚW_OKrÚFileNotFoundErrorÚ_errnoÚENOENT)ÚnamerrZr(ÚseqrRÚfilenameÚfdÚfprrrÚ_get_default_tempdir·s@    *  ÿ ÿÿrwcCs:tdur6t ¡ztdur tƒaWt ¡n t ¡0tS)z7Common setup sequence for all user-callable interfaces.N)Ú_name_sequenceÚ _once_lockÚacquirer+ÚreleaserrrrÚ_get_candidate_namesæsr|c CsÚtƒ}|turttj|ƒ}ttƒD]¦}t|ƒ}tj  ||||¡}t   d|¡zt  ||d¡} WnRt yxYq"Yn>ty´tjdkr®tj |¡r®t |tj¡r®Yq"n‚Yn0| tj |¡fSt tjdƒ‚dS)z>Code common to mkstemp, TemporaryFile, and NamedTemporaryFile.ztempfile.mkstempr_rOz#No usable temporary file name foundN)r|rÚmaprr%rCrrcrTrDÚ_sysÚauditrdrjrkrRrlrmrnrbrpÚEEXIST) r(ÚpreÚsufÚflagsr)ÚnamesrsrRÚfilerurrrÚ_mkstemp_innerôs*      ÿÿr†cGsL|tjvr"||g|¢RddiŽn&tjdks8tj |¡sH||g|¢RŽdS)NÚfollow_symlinksFrO)rÚsupports_follow_symlinksrRrTÚislink)ÚfuncrTr rrrÚ_dont_follow_symlinkss r‹cCs.z tj}WntyYn0t||dƒdS)Nr)rÚchflagsrXr‹)rTrŒrrrÚ _resetflagss   r�cCst|ƒttj|dƒdS©NéÀ)r�r‹rÚchmod)rTrrrÚ _resetpermssr‘cCs,|durt|ƒdSt|ƒt |d¡dSrŽ)r‘r�rr�)Údir_fdrTrrrÚ_resetperms_fd*s r“c CsÆ|durt|ƒdSt|ƒtjtjvrtyÆtjdkrÀtj  |¡rÀt |tj¡rÀYq6n‚Yn0|Sttjdƒ‚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. ztempfile.mkdtempr�rOz(No usable temporary directory name foundN)r*r|rr}rr%rCrrcrTrDr~rÚmkdirrjrkrRrlrmrnrpr€)r'r&r(r)r„rsrRr…rrrr™s,       ÿÿrr@cCs`|durtƒ}tƒ}ttƒD]2}t|ƒ}tj ||||¡}t|ƒs|Sqt 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 r|rCrrcrrTrDrrjrpr€)r'r&r(r„rsrRr…rrrrÁs  ÿrc@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||_||_||_dSr5)r…rRÚdelete©r2r…rRrŸrrrÚ__init__ész_TemporaryFileCloser.__init__rOcCsL|jsH|jdurHd|_z|j ¡W|jrH||jƒn|jrF||jƒ0dS©NT)Ú close_calledr…rhrŸrR)r2rirrrrhøs  ÿz_TemporaryFileCloser.closecCs | ¡dSr5)rhr6rrrÚ__del__sz_TemporaryFileCloser.__del__cCs|jsd|_|j ¡dSr¢)r£r…rhr6rrrrhs)T) rGrHrIrJr…r£r¡rrRrirhr¤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|||ƒ|_dSr5)r…rRrŸržÚ_closerr rrrr¡sz_TemporaryFileWrapper.__init__cs^|jd}t||ƒ}t|dƒrD|‰t ˆ¡‡fdd„ƒ}|j|_|}t|tƒsZt|||ƒ|S)Nr…Ú__call__csˆ|i|¤ŽSr5r)r Úkwargs©rŠrrÚ func_wrapper"sz7_TemporaryFileWrapper.__getattr__..func_wrapper) Ú__dict__r/ÚhasattrÚ _functoolsÚwrapsr¦rÚintÚsetattr)r2rRr…Úarªrr©rÚ __getattr__s     z!_TemporaryFileWrapper.__getattr__cCs|j ¡|Sr5)r…Ú __enter__r6rrrr³/s z_TemporaryFileWrapper.__enter__cCs|j |||¡}| ¡|Sr5)r…Ú__exit__rh)r2ÚexcÚvalueÚtbÚresultrrrr´5sz_TemporaryFileWrapper.__exit__cCs|j ¡dS)zA Close the temporary file, possibly deleting it. N)r¦rhr6rrrrh:sz_TemporaryFileWrapper.closeccs|jD] }|VqdSr5)r…)r2Úlinerrrr7As z_TemporaryFileWrapper.__iter__N)T) rGrHrIrJr¡r²r³r´rhr7rrrrr¥ s r¥úw+béÿÿÿÿT©ÚerrorscCs–t|||ƒ\}}}} t} tjdkr0|r0| tjO} t|||| | ƒ\} } z$tj| |||||d�} t| | |ƒWSt y�t  | ¡t  | ¡‚Yn0dS)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. rO©Ú bufferingÚnewlineÚencodingr½N) r*rerrRÚ O_TEMPORARYr†rfrdr¥Ú BaseExceptionrirh)Úmoder¿rÁrÀr'r&r(rŸr½r)rƒrurRr…rrrrKs  ÿ   rÚposixÚcygwinÚ O_TMPFILEc Csît|||ƒ\}}}}t} tršz$| tjBtj@} t || d¡} Wn&tyVdaYnDtyfYn40zt j| |||||d�WSt  | ¡‚Yn0t |||| |ƒ\} } z"t  | ¡t j| |||||d�WSt  | ¡‚Yn0dS)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_Fr¾N) r*reÚ_O_TMPFILE_WORKSrrÇÚO_CREATrdÚIsADirectoryErrorrrfrhr†ri) rÄr¿rÁrÀr'r&r(r½r)rƒÚflags2rurRrrrr}s6   þ   ÿ rc@seZdZdZdZd8ddœ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  CsTd|vrt ¡|_ntjt ¡|| |d�|_||_d|_|||||||| dœ|_dS)NÚb)rÁr½rÀF)rÄr¿r'r&rÁrÀr(r½)rfÚBytesIOÚ_fileÚ TextIOWrapperÚ _max_sizeÚ_rolledÚ_TemporaryFileArgs) r2Úmax_sizerÄr¿rÁrÀr'r&r(r½rrrr¡Às  þýzSpooledTemporaryFile.__init__cCs,|jr dS|j}|r(| ¡|kr(| ¡dSr5)rÑrÐÚtellÚrollover)r2r…rÓrrrÚ_checkÒs zSpooledTemporaryFile._checkcCsv|jr dS|j}tfi|j¤Ž}|_|`| ¡}t|dƒrR|j | ¡  ¡¡n| |  ¡¡|  |d¡d|_dS)NÚbufferrT) rÑrÎrrÒrÔr¬r×rgÚdetachÚgetvalueÚseek)r2r…ÚnewfileÚposrrrrÕØs   zSpooledTemporaryFile.rollovercCs|jjrtdƒ‚|S)Nz%Cannot enter context with closed file)rÎÚclosedÚ ValueErrorr6rrrr³íszSpooledTemporaryFile.__enter__cCs|j ¡dSr5©rÎrh©r2rµr¶r·rrrr´òszSpooledTemporaryFile.__exit__cCs |j ¡Sr5)rÎr7r6rrrr7öszSpooledTemporaryFile.__iter__cCs|j ¡dSr5rßr6rrrrhùszSpooledTemporaryFile.closecCs|jjSr5)rÎrÝr6rrrrÝüszSpooledTemporaryFile.closedcCs|jjSr5)rÎrÁr6rrrrÁszSpooledTemporaryFile.encodingcCs|jjSr5)rÎr½r6rrrr½szSpooledTemporaryFile.errorscCs| ¡|j ¡Sr5)rÕrÎÚfilenor6rrrrászSpooledTemporaryFile.filenocCs|j ¡dSr5)rÎÚflushr6rrrrâ szSpooledTemporaryFile.flushcCs |j ¡Sr5)rÎÚisattyr6rrrrãszSpooledTemporaryFile.isattycCs,z |jjWSty&|jdYS0dS)NrÄ)rÎrÄrXrÒr6rrrrÄs  zSpooledTemporaryFile.modecCs$z |jjWStyYdS0dSr5)rÎrRrXr6rrrrRs  zSpooledTemporaryFile.namecCs|jjSr5)rÎÚnewlinesr6rrrrä szSpooledTemporaryFile.newlinescGs |jj|ŽSr5)rÎÚread©r2r rrrrå$szSpooledTemporaryFile.readcGs |jj|ŽSr5)rÎÚreadlinerærrrrç'szSpooledTemporaryFile.readlinecGs |jj|ŽSr5)rÎÚ readlinesrærrrrè*szSpooledTemporaryFile.readlinescGs |jj|ŽSr5)rÎrÚrærrrrÚ-szSpooledTemporaryFile.seekcCs |j ¡Sr5)rÎrÔr6rrrrÔ0szSpooledTemporaryFile.tellcCs6|dur|j ¡n||jkr&| ¡|j |¡dSr5)rÎÚtruncaterÐrÕ)r2Úsizerrrré3s   zSpooledTemporaryFile.truncatecCs|j}| |¡}| |¡|Sr5)rÎrgrÖ)r2Úsr…Úrvrrrrg;s  zSpooledTemporaryFile.writecCs|j}| |¡}| |¡|Sr5)rÎÚ writelinesrÖ)r2Úiterabler…rìrrrríAs  zSpooledTemporaryFile.writelines)rrºr»NNNNN)N)"rGrHrIrJrÑr¡Ú classmethodÚ_typesÚ GenericAliasÚ__class_getitem__rÖrÕr³r´r7rhrKrÝrÁr½rárârãrÄrRrärårçrèrÚrÔrérgrírrrrr¹sLþþ         rc@s^eZdZdZddd„Zeddd„ƒZedd „ƒ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. NcCs0t|||ƒ|_tj||j|jd |¡d�|_dS)NzImplicitly cleaning up {!r})Ú warn_message)rrRÚ_weakrefÚfinalizeÚ_cleanupÚformatÚ _finalizer)r2r'r&r(rrrr¡Ts  þzTemporaryDirectory.__init__Fcs8ˆdur ˆ‰d‡‡‡‡‡fdd„ }tjˆ||dd�dS)Nc sft|dttfƒ�rNˆr*|ˆkr*ˆr(dS‚ˆ|tˆƒd…}|dusJtsV|d}}n|durd|}n|j}z¬|ˆkr†t|tj  |¡ƒt |||ƒztj ||d�WnntyΈj |ˆ|ˆk||d�YnFt�ytj  |¡söˆrôYWdS‚ˆj |ˆ|ˆk||d�Yn0Wn4t�y*Yn"t�yJˆ�rDYdS‚Yn0nt|dtƒ�r`n‚dS)Nrr”)Ú ignore_errorsÚrepeatedr’Úfullname)Ú issubclassrkrÊÚlenÚ_rmtree_use_dir_fdrRr“rrTr\ršriÚ_rmtreerlror)rŠrTÚexc_infoÚdirentryr’ÚfullpathÚbase©ÚclsrûrùrRrúrrÚonerror`sP     þ  þ z+TemporaryDirectory._rmtree..onerrorT)rr’Ú_onerror_kwargs)NN)Ú_shutilÚrmtree)rrRrùrúr’rûrrrrrÿZs : ÿzTemporaryDirectory._rmtreecCs| |¡t |t¡dSr5)rÿÚ _warningsÚwarnÚResourceWarning)rrRrórrrrö�s zTemporaryDirectory._cleanupcCsd |jj|j¡S)Nz <{} {!r}>)r÷Ú __class__rGrRr6rrrÚ__repr__¢szTemporaryDirectory.__repr__cCs|jSr5)rRr6rrrr³¥szTemporaryDirectory.__enter__cCs | ¡dSr5)Úcleanupràrrrr´¨szTemporaryDirectory.__exit__cCs|j ¡r| |j¡dSr5)rørØrÿrRr6rrrr«s zTemporaryDirectory.cleanup)NNN)FFNN)rGrHrIrJr¡rïrÿrörr³r´rrðrñròrrrrrHs ÿ B r)NNNF)NNN)rºr»NNNNNT)rºr»NNNNN)PrJÚ__all__Ú functoolsr­Úwarningsr ÚiorfÚosrÚshutilrÚerrnorpÚrandomrr0r™r–Úsysr~ÚtypesrðÚweakrefrôÚ_threadÚ allocate_lockÚ_allocate_lockÚO_RDWRrÉÚO_EXCLr›r¬rrerrr$ryrr#r*r+r]rwrxr|r†r‹r�r‘r�riÚsupports_dir_fdÚ supports_fdrþr“ÚO_RDONLYÚ O_NONBLOCKr•rXršr r r r r rrrržr¥rrRÚplatformrrÈrÚobjectrrrrrÚs”        - þ !  ' ( +?þþ ' þþ <