grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026î   fýWã@sdZddddddddd d d g Zd d lZd d lZd d lZd d lZ d d l Z d d l Z d dlmZd d lZyd d lZWnek rÁd d lZYnXejZe je jBe jBZee dƒree jOZneZee dƒr&ee jOZnee dƒrAe j Z ndZ dZ!eƒZ"ee dƒrqe j#Z$n'ee dƒrŒe j%Z$n dd„Z$dd„Z&Gdd„dƒZ'dd„Z(dd„Z)d a*dd „Z+d!d"„Z,d#d „Z-d a.d$d „Z/d%e!d d&d'd„Z0d%e!d d(d„Z1d%e!d d)d„Z2Gd*d+„d+ƒZ3Gd,d-„d-ƒZ4d.d7d d d%e!d d0d1d„Z5e j6d2ks¸e j7j8d3krÁe5Z9n!d.d8d d d%e!d d4d„Z9Gd5d„dƒZ:Gd6d„de;ƒZ<d S)9a³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. 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éN)ÚRandomÚ O_NOFOLLOWÚO_BINARYi'ZtmpÚlstatÚstatcCs&tj|tjƒ}tj|ƒdS)N)Ú_osÚopenÚO_RDONLYÚclose)ÚfnÚfd©rú-/opt/alt/python34/lib64/python3.4/tempfile.pyÚ_statIsrc Cs/yt|ƒWntk r&dSYnXdSdS)NFT)rÚOSError)rrrrÚ_existsMs   rc@sFeZdZdZdZedd„ƒ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 six characters long. Multiple threads can safely use the same instance at the same time. _RandomNameSequence is an iterator.Z%abcdefghijklmnopqrstuvwxyz0123456789_cCsCtjƒ}|t|ddƒkr<tƒ|_||_n|jS)NÚ_rng_pid)rÚgetpidÚgetattrÚ_RandomZ_rngr)ÚselfZcur_pidrrrÚrng_s    z_RandomNameSequence.rngcCs|S)Nr)r"rrrÚ__iter__gsz_RandomNameSequence.__iter__csD|j‰|jj‰‡‡fdd†tdƒDƒ}dj|ƒS)Ncsg|]}ˆˆƒ‘qSrr)Ú.0Zdummy)ÚcÚchooserrú ms z0_RandomNameSequence.__next__..éÚ)Ú charactersr#ZchoiceÚrangeÚjoin)r"Zlettersr)r&r'rÚ__next__js  "z_RandomNameSequence.__next__N) Ú__name__Ú __module__Ú __qualname__Ú__doc__r+Úpropertyr#r$r.rrrrrUs  rc CsÃg}x3d D]+}tj|ƒ}|r |j|ƒq q Wtjdkrg|jddddgƒn|jd d d gƒy|jtjƒƒWn(ttfk r¾|jtjƒYnX|S) z[Generate a list of candidate temporary directories which _get_default_tempdir will try.ÚTMPDIRÚTEMPÚTMPÚntzc:\tempzc:\tmpz\tempz\tmpz/tmpz/var/tmpz/usr/tmp)r4r5r6) rÚgetenvÚappendÚnameÚextendÚgetcwdÚAttributeErrorrÚcurdir)ÚdirlistZenvnameÚdirnamerrrÚ_candidate_tempdir_listps rAcCsƒtƒ}tƒ}xT|D]L}|tjkrCtjj|ƒ}nxtdƒD]}t|ƒ}tjj||ƒ}yutj |t dƒ}zGz2t j |dddƒ�}|j dƒWdQXWdtj |ƒXWdtj|ƒX|SWqPtk rYqPtk rNtjdkrItjj|ƒrItj|tjƒrIwPnPYqPtk r`PYqPXqPWqWttjd |ƒ‚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.édi€ÚwbÚclosefdFsblatNr7z)No usable temporary directory found in %s)rrArr>ÚpathÚabspathr,Únextr-rÚ_bin_openflagsÚ_ioÚwriterÚunlinkÚFileExistsErrorÚPermissionErrorr:ÚisdirÚaccessÚW_OKrÚFileNotFoundErrorÚ_errnoÚENOENT)Znamerr?ÚdirÚseqr:ÚfilenamerÚfprrrÚ_get_default_tempdir‰s:      !  rXc CsGtdkrCtjƒztdkr1tƒanWdtjƒXntS)z7Common setup sequence for all user-callable interfaces.N)Ú_name_sequenceÚ _once_lockÚacquirerÚreleaserrrrÚ_get_candidate_names¸s   r]c Csötƒ}xÔttƒD]Æ}t|ƒ}tjj||||ƒ}y/tj||dƒ}|tjj|ƒfSWqt k r‹wYqt k rÛtj dkrÔtjj |ƒrÔtj |tjƒrÔwn‚YqXqWt tjdƒ‚dS)z>Code common to mkstemp, TemporaryFile, and NamedTemporaryFile.i€r7z#No usable temporary file name foundN)r]r,rrGrrEr-rrFrLrMr:rNrOrPrRÚEEXIST) rTZpreZsufÚflagsÚnamesrUr:ÚfilerrrrÚ_mkstemp_innerÆs     !  rbcCstS)zAccessor for tempdir.template.)Útemplaterrrrr âsc CsGtdkrCtjƒztdkr1tƒanWdtjƒXntS)zAccessor for tempfile.tempdir.N)r rZr[rXr\rrrrr ès   r*FcCs@|dkrtƒ}n|r't}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 specified, the file name will end with that suffix, otherwise there will be no suffix. If 'prefix' is specified, the file name will begin with that prefix, otherwise a default prefix is used. If 'dir' is specified, 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. 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. N)r Ú_text_openflagsrHrb)ÚsuffixÚprefixrTÚtextr_rrrrôs    c Cs÷|dkrtƒ}ntƒ}x½ttƒD]¯}t|ƒ}tjj||||ƒ}ytj|dƒ|SWq.t k rŒw.Yq.t k rÜtj dkrÕtjj |ƒrÕtj |tjƒrÕw.n‚Yq.Xq.Wt 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. NiÀr7z(No usable temporary directory name found)r r]r,rrGrrEr-ÚmkdirrLrMr:rNrOrPrRr^)rerfrTr`rUr:rarrrrs$      !  cCs‡|dkrtƒ}ntƒ}xMttƒD]?}t|ƒ}tjj||||ƒ}t|ƒs.|Sq.Wt t j dƒ‚dS)ašUser-callable function to return a unique temporary file name. The file is not created. Arguments are as for mkstemp, except that the 'text' argument is not accepted. This function is unsafe and should not be used. The file name refers 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]r,rrGrrEr-rrLrRr^)rerfrTr`rUr:rarrrr?s      c@smeZdZdZdZdZddd„Zejdkr]ej dd „Z d d „Z n d 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)rar:Údelete)r"rar:rjrrrÚ__init__fs  z_TemporaryFileCloser.__init__r7c CsW|j rS|jdk rSd|_z|jjƒWd|jrO||jƒnXndS)NT)Ú close_calledrarrjr:)r"rKrrrrus   z_TemporaryFileCloser.closecCs|jƒdS)N)r)r"rrrÚ__del__sz_TemporaryFileCloser.__del__cCs&|js"d|_|jjƒndS)NT)rlrar)r"rrrrƒs  ) r/r0r1r2rarlrkrr:rKrrmrrrrri^s  ric@saeZdZdZddd„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. TcCs4||_||_||_t|||ƒ|_dS)N)rar:rjriÚ_closer)r"rar:rjrrrrk‘s   z_TemporaryFileWrapper.__init__cs�|jd}t||ƒ}t|dƒrg|‰tjˆƒ‡fdd†ƒ}|j|_|}nt|tƒs‰t|||ƒn|S)NraÚ__call__cs ˆ||ŽS)Nr)ÚargsÚkwargs)ÚfuncrrÚ func_wrapperŸsz7_TemporaryFileWrapper.__getattr__..func_wrapper) Ú__dict__r ÚhasattrÚ _functoolsÚwrapsroÚ isinstanceÚintÚsetattr)r"r:raÚartr)rsrÚ __getattr__—s !  z!_TemporaryFileWrapper.__getattr__cCs|jjƒ|S)N)raÚ __enter__)r"rrrr~¬s z_TemporaryFileWrapper.__enter__cCs&|jj|||ƒ}|jƒ|S)N)raÚ__exit__r)r"ÚexcÚvalueÚtbÚresultrrrr²s z_TemporaryFileWrapper.__exit__cCs|jjƒdS)zA Close the temporary file, possibly deleting it. N)ror)r"rrrr·sz_TemporaryFileWrapper.closeccsx|jD] }|Vq WdS)N)ra)r"Úlinerrrr$¾sz_TemporaryFileWrapper.__iter__N) r/r0r1r2rkr}r~rrr$rrrrrn‰s     rnzw+béTc Cs¿|dkrtƒ}nt}tjdkrC|rC|tjO}nt||||ƒ\} } y8tj| |d|d|d|ƒ} t| | |ƒSWn"t k rºtj | ƒ‚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 file.name. The file will be automatically deleted when it is closed unless the 'delete' argument is set to False. Nr7Ú bufferingÚnewlineÚencoding) r rHrr:Z O_TEMPORARYrbrIrrnÚ Exceptionr) Úmoder†rˆr‡rerfrTrjr_rr:rarrrrÈs    ÚposixÚcygwinc Cs‹|dkrtƒ}nt}t||||ƒ\}} y3tj| ƒtj||d|d|d|ƒSWntj|ƒ‚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. Nr†r‡rˆ)r rHrbrrKrIrr) rŠr†rˆr‡rerfrTr_rr:rrrrôs    c @s{eZdZdZdZddd8dddeddd „Zd d „Zd d „Zdd„Z dd„Z dd„Z dd„Z e dd„ƒZe dd„ƒZdd„Zdd„Zdd„Ze d d!„ƒZe d"d#„ƒZe d$d%„ƒZd&d'„Zd(d)„Zd*d+„Zd,d-„Ze d.d/„ƒZd0d1„Zdd2d3„Zd4d5„Zd6d7„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 zw+br…Nr*c Csƒd|krtjƒ|_ntjddƒ|_||_d|_i|d6|d6|d6|d6|d 6|d6|d 6|_dS) NÚbr‡Ú FrŠr†rerfrˆrT)rIÚBytesIOÚ_fileÚStringIOÚ _max_sizeÚ_rolledÚ_TemporaryFileArgs) r"Úmax_sizerŠr†rˆr‡rerfrTrrrrks   zSpooledTemporaryFile.__init__cCs?|jr dS|j}|r;|jƒ|kr;|jƒndS)N)r“r’ÚtellÚrollover)r"rar•rrrÚ_check*s   zSpooledTemporaryFile._checkcCsh|jr dS|j}t|j�}|_|`|j|jƒƒ|j|jƒdƒd|_dS)Nr T)r“r�rr”rJÚgetvalueÚseekr–)r"raZnewfilerrrr—0s  zSpooledTemporaryFile.rollovercCs|jjrtdƒ‚n|S)Nz%Cannot enter context with closed file)r�ÚclosedÚ ValueError)r"rrrr~As zSpooledTemporaryFile.__enter__cCs|jjƒdS)N)r�r)r"r€r�r‚rrrrFszSpooledTemporaryFile.__exit__cCs |jjƒS)N)r�r$)r"rrrr$JszSpooledTemporaryFile.__iter__cCs|jjƒdS)N)r�r)r"rrrrMszSpooledTemporaryFile.closecCs |jjS)N)r�r›)r"rrrr›PszSpooledTemporaryFile.closedc CsKy|jjSWn6tk rFd|jdkr7‚n|jdSYnXdS)Nr�rŠrˆ)r�rˆr=r”)r"rrrrˆTs  zSpooledTemporaryFile.encodingcCs|jƒ|jjƒS)N)r—r�Úfileno)r"rrrr�]s zSpooledTemporaryFile.filenocCs|jjƒdS)N)r�Úflush)r"rrrržaszSpooledTemporaryFile.flushcCs |jjƒS)N)r�Úisatty)r"rrrrŸdszSpooledTemporaryFile.isattyc Cs2y|jjSWntk r-|jdSYnXdS)NrŠ)r�rŠr=r”)r"rrrrŠgs zSpooledTemporaryFile.modec Cs+y|jjSWntk r&dSYnXdS)N)r�r:r=)r"rrrr:ns zSpooledTemporaryFile.namec CsKy|jjSWn6tk rFd|jdkr7‚n|jdSYnXdS)Nr�rŠr‡)r�Únewlinesr=r”)r"rrrr us  zSpooledTemporaryFile.newlinescGs|jj|ŒS)N)r�Úread)r"rqrrrr¡~szSpooledTemporaryFile.readcGs|jj|ŒS)N)r�Úreadline)r"rqrrrr¢�szSpooledTemporaryFile.readlinecGs|jj|ŒS)N)r�Ú readlines)r"rqrrrr£„szSpooledTemporaryFile.readlinescGs|jj|ŒdS)N)r�rš)r"rqrrrrš‡szSpooledTemporaryFile.seekcCs |jjS)N)r�Ú softspace)r"rrrr¤ŠszSpooledTemporaryFile.softspacecCs |jjƒS)N)r�r–)r"rrrr–ŽszSpooledTemporaryFile.tellcCsL|dkr|jjƒn,||jkr8|jƒn|jj|ƒdS)N)r�Útruncater’r—)r"Úsizerrrr¥‘s   zSpooledTemporaryFile.truncatecCs)|j}|j|ƒ}|j|ƒ|S)N)r�rJr˜)r"ÚsraÚrvrrrrJ™s  zSpooledTemporaryFile.writecCs)|j}|j|ƒ}|j|ƒ|S)N)r�Ú writelinesr˜)r"Úiterablerar¨rrrr©Ÿs  zSpooledTemporaryFile.writelineséÿÿÿÿ)r/r0r1r2r“rcrkr˜r—r~rr$rr3r›rˆr�ržrŸrŠr:r r¡r¢r£ršr¤r–r¥rJr©rrrrrs8                 c@smeZdZdZdeddd„Zedd„ƒZdd „Zd d „Z d d „Z dd„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. r*NcCsFt|||ƒ|_tj||j|jddj|ƒƒ|_dS)NÚ warn_messagezImplicitly cleaning up {!r})rr:Ú_weakrefÚfinalizeÚ_cleanupÚformatÚ _finalizer)r"rerfrTrrrrk²szTemporaryDirectory.__init__cCs!tj|ƒtj|tƒdS)N)Ú_shutilÚrmtreeÚ _warningsÚwarnÚResourceWarning)Úclsr:r¬rrrr¯¸s zTemporaryDirectory._cleanupcCsdj|jj|jƒS)Nz <{} {!r}>)r°Ú __class__r/r:)r"rrrÚ__repr__¾szTemporaryDirectory.__repr__cCs|jS)N)r:)r"rrrr~ÁszTemporaryDirectory.__enter__cCs|jƒdS)N)Úcleanup)r"r€r�r‚rrrrÄszTemporaryDirectory.__exit__cCs&|jjƒr"tj|jƒndS)N)r±Údetachr²r³r:)r"rrrrºÇszTemporaryDirectory.cleanup) r/r0r1r2rcrkÚ classmethodr¯r¹r~rrºrrrrr¦s    r«r«)=r2Ú__all__Ú functoolsrwÚwarningsr´ÚiorIÚosrZshutilr²ÚerrnorRZrandomr r!Úweakrefr­Ú_threadÚ ImportErrorZ _dummy_threadÚ allocate_lockZ_allocate_lockÚO_RDWRÚO_CREATÚO_EXCLrdrvrrHrrrcrZrrrrrrArXrYr]rbr r r rrrrirnrr:ÚsysÚplatformrrÚobjectrrrrrÚsx                  -    %&+?  $!   ”