³ò £l‡Jc@súdZddddddddd g Zd d kZd d kZd d klZei d jo"d d k i Z d d k iZnyd d kZWnej od„Zn Xd„Zyd d kZWnej od d kZnXeiZeieiBeiBZeedƒoeeiOZneedƒoeeiOZneZ eedƒoe ei!OZ needƒo ei"Z"ndZ"dZ#d a%eƒZ&eedƒo ei'Z(n'eedƒo ei)Z(n d„Z(d„Z*dd,d„ƒYZ+d„Z,d„Z-d a.d„Z/d„Z0d„Z1d a%d „Z2d!e#d e3d"„Z4d!e#d d#„Z5d!e#d d$„Z6d%d-d&„ƒYZ7d'd d!e#d d(„Z8ei d)jpei9i:d*jo e8Z;nd'd d!e#d d+„Z;d S(.søTemporary files. This module provides generic, low- and high-level interfaces for creating temporary files and directories. The interfaces listed as "safe" just below can be used without fear of race conditions. Those listed as "unsafe" cannot, and are 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. template - the default prefix for all temporary names. You may change this to control the default prefix. 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. tNamedTemporaryFilet TemporaryFiletmkstemptmkdtemptmktemptTMP_MAXt gettempprefixttempdirt gettempdiriÿÿÿÿN(tRandomtmaccCsdS(N((tfd((s/sys/lib/python/tempfile.pyt _set_cloexec*scCsYyti|tidƒ}Wntj on%X|tiO}ti|ti|ƒdS(Ni(t_fcntltfcntltF_GETFDtIOErrort FD_CLOEXECtF_SETFD(R tflags((s/sys/lib/python/tempfile.pyR -s  t O_NOINHERITt O_NOFOLLOWtO_BINARYi'ttmptlstattstatcCs=yt|ƒ}Wntj oti‚nX|iƒdS(N(topenRt_osterrortclose(tfntf((s/sys/lib/python/tempfile.pyt_stat\s cCs3yt|ƒWntij o tSnXtSdS(N(R RRtFalsetTrue(R((s/sys/lib/python/tempfile.pyt_existscs  t_RandomNameSequencecBs7eZdZdddZd„Zd„Zd„ZRS(s*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.tabcdefghijklmnopqrstuvwxyztABCDEFGHIJKLMNOPQRSTUVWXYZs 0123456789-_cCs+tƒ|_tƒ|_tii|_dS(N(t_allocate_locktmutext_RandomtrngRtpathtnormcase(tself((s/sys/lib/python/tempfile.pyt__init__ws  cCs|S(N((R-((s/sys/lib/python/tempfile.pyt__iter__|scCsw|i}|i}|ii}|iƒz+g}dD]}|||ƒq6~}Wd|iƒX|idi|ƒƒS(Nt123456t(R(t charactersR*tchoicetacquiretreleaseR,tjoin(R-tmtctchooset_[1]tdummytletters((s/sys/lib/python/tempfile.pytnexts    + (t__name__t __module__t__doc__R2R.R/R=(((s/sys/lib/python/tempfile.pyR$ks   c Cskg}x5dD]-}ti|ƒ}|o|i|ƒq q WtidjoUy8tititidƒ}|i ƒ}|i|ƒWq!ti j oq!Xntidjo+tidƒ}|o|i|ƒq!nDtidjo|i d d d d gƒn|i d ddgƒy|iti ƒƒWn,t ti fj o|itiƒnX|S(s[Generate a list of candidate temporary directories which _get_default_tempdir will try.tTMPDIRtTEMPtTMPR itriscoss Wimp$ScrapDirtntsc:\tempsc:\tmps\temps\tmps/tmps/var/tmps/usr/tmp(RARBRC(Rtgetenvtappendtnamet_Foldert FSFindFoldert_Folderst kOnSystemDisktkTemporaryFolderTypet as_pathnameRtextendtgetcwdtAttributeErrortcurdir(tdirlisttenvnametdirnametfsr((s/sys/lib/python/tempfile.pyt_candidate_tempdir_listŒs0   c Cs=tƒ}tƒ}t}x|D]}|tijo"tiitii|ƒƒ}nxÅtdƒD]·}|i ƒ}tii ||ƒ}yYti ||dƒ}ti |dƒ}|i dƒ|iƒti|ƒ~~|SWqdttfj o"} | dtijoPqqdXqdWqWttid|f‚dS(sqCalculate 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.idi€twtblatis)No usable temporary directory found in %sN(R$RWt_text_openflagsRRRR+R,tabspathtxrangeR=R6RtfdopentwriteRtunlinktOSErrorRt_errnotEEXISTtENOENT( tnamerRSRtdirtseqRHtfilenameR tfpte((s/sys/lib/python/tempfile.pyt_get_default_tempdir°s2  "       cCsKtdjo:tiƒztdjo tƒanWdtiƒXntS(s7Common setup sequence for all user-callable interfaces.N(t_name_sequencetNonet _once_lockR4R$R5(((s/sys/lib/python/tempfile.pyt_get_candidate_namesÕs   c CsÍtƒ}x«ttƒD]}|iƒ}tii||||ƒ}y9ti||dƒ}t|ƒ|tii |ƒfSWqt j o&} | i t i joqn‚qXqWtt i df‚dS(s>Code common to mkstemp, TemporaryFile, and NamedTemporaryFile.i€s#No usable temporary file name foundN(RnR\RR=RR+R6RR R[R`terrnoRaRbR( RetpretsufRtnamesRfRHtfileR Ri((s/sys/lib/python/tempfile.pyt_mkstemp_innerãs     cCstS(sAccessor for tempdir.template.(ttemplate(((s/sys/lib/python/tempfile.pyRùscCsKtdjo:tiƒztdjo tƒanWdtiƒXntS(sAccessor for tempdir.tempdir.N(RRlRmR4RjR5(((s/sys/lib/python/tempfile.pyRÿs   R1cCsD|djo tƒ}n|o t}nt}t||||ƒS(sVmkstemp([suffix, [prefix, [dir, [text]]]]) 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(RlRRZt_bin_openflagsRt(tsuffixtprefixRettextR((s/sys/lib/python/tempfile.pyR s    cCsÆ|djo tƒ}ntƒ}xŠttƒD]|}|iƒ}tii||||ƒ}yti |dƒ|SWq0t j o&}|i t i joq0n‚q0Xq0Wtt i df‚dS(s¦mkdtemp([suffix, [prefix, [dir]]]) User-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Às(No usable temporary directory name foundN(RlRRnR\RR=RR+R6tmkdirR`RoRaRbR(RwRxReRrRfRHRsRi((s/sys/lib/python/tempfile.pyR1s      cCsŽ|djo tƒ}ntƒ}xRttƒD]D}|iƒ}tii||||ƒ}t |ƒp|Sq0q0Wt t i df‚dS(sÀmktemp([suffix, [prefix, [dir]]]) 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. s"No usable temporary filename foundN( RlRRnR\RR=RR+R6R#RRaRb(RwRxReRrRfRHRs((s/sys/lib/python/tempfile.pyRQs       t_TemporaryFileWrappercBsOeZdZd„Zd„ZeidjoeiZd„Zd„Z nRS(sÄ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. cCs||_||_t|_dS(N(RsRHR!t close_called(R-RsRH((s/sys/lib/python/tempfile.pyR.ws  cCsM|id}t||ƒ}t|ƒtdƒjot|||ƒn|S(NRsi(t__dict__tgetattrttypetsetattr(R-RHRsta((s/sys/lib/python/tempfile.pyt __getattr__|s  REcCs8|ip*t|_|iiƒ|i|iƒndS(N(R|R"RsRR_RH(R-((s/sys/lib/python/tempfile.pyRs   cCs|iƒdS(N(R(R-((s/sys/lib/python/tempfile.pyt__del__•s( R>R?R@R.R‚RRHR_RRƒ(((s/sys/lib/python/tempfile.pyR{os    sw+bc Cs•|djo tƒ}nd|jo t}nt}tidjo|tiO}nt||||ƒ\}}ti|||ƒ}t ||ƒS(sÄCreate and return a temporary file. Arguments: 'prefix', 'suffix', 'dir' -- as for mkstemp. 'mode' -- the mode argument to os.fdopen (default "w+b"). 'bufsize' -- the buffer size argument to os.fdopen (default -1). 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. tbREN( RlRRvRZRRHt O_TEMPORARYRtR]R{( tmodetbufsizeRwRxReRR RHRs((s/sys/lib/python/tempfile.pyR˜s    tposixtcygwincCs”|djo tƒ}nd|jo t}nt}t||||ƒ\}}y$ti|ƒti|||ƒSWnti|ƒ‚nXdS(s¶Create and return a temporary file. Arguments: 'prefix', 'suffix', 'dir' -- as for mkstemp. 'mode' -- the mode argument to os.fdopen (default "w+b"). 'bufsize' -- the buffer size argument to os.fdopen (default -1). 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„N( RlRRvRZRtRR_R]R(R†R‡RwRxReRR RH((s/sys/lib/python/tempfile.pyR½s      (((<R@t__all__tosRRoRatrandomR R)RHt Carbon.FoldertFolderRItCarbon.FolderstFoldersRKRR t ImportErrorR tthreadt_threadt dummy_threadt allocate_lockR'tO_RDWRtO_CREATtO_EXCLRZthasattrRRRvRRRuRlRRmRR RR#R$RWRjRkRnRtRRR!RRRR{RtsystplatformR(((s/sys/lib/python/tempfile.pyssx           ! $ #    & ) #