zfc @s dZddddddddd d g Zd d lZd d lZd d lZd d lm Z yd dl m Z Wn!ek rd dl m Z nXyd d lZWnek rdZn XdZyd d lZWnek rd d lZnXejZejejBejBZeedr;eejOZneedrZeejOZneZeedreejOZneedrej Z ndZ dZ!eZ"eedrej#Z$n$eedrej%Z$n dZ$dZ&dd.dYZ'dZ(dZ)d a+dZ,dZ-d Z.d a/d!Z0d"e!d e1d#Z2d"e!d d$Z3d"e!d d%Z4d&d/d'YZ5d(d d"e!d e6d)Z7ej8d*ksej9j:d+kre7Z;nd(d d"e!d d,Z;dd0d-YZ<d S(1s,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. 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 TemporaryFiletSpooledTemporaryFiletmkstemptmkdtemptmktemptTMP_MAXt gettempprefixttempdirt gettempdiriN(tRandom(tStringIOcCsdS(N((tfd((s /usr/lib64/python2.7/tempfile.pyt _set_cloexec-scCsWytj|tjd}Wntk r/n$X|tjO}tj|tj|dS(Ni(t_fcntltfcntltF_GETFDtIOErrort FD_CLOEXECtF_SETFD(R tflags((s /usr/lib64/python2.7/tempfile.pyR 0s   t O_NOINHERITt O_NOFOLLOWtO_BINARYi'ttmptlstattstatcCs;yt|}Wntk r,tjnX|jdS(N(topenRt_osterrortclose(tfntf((s /usr/lib64/python2.7/tempfile.pyt_stat]s   cCs.yt|Wntjk r%tSXtSdS(N(R!RRtFalsetTrue(R((s /usr/lib64/python2.7/tempfile.pyt_existsds t_RandomNameSequencecBsFeZdZdddZdZedZdZdZRS(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.tabcdefghijklmnopqrstuvwxyztABCDEFGHIJKLMNOPQRSTUVWXYZt 0123456789_cCst|_tjj|_dS(N(t_allocate_locktmutexRtpathtnormcase(tself((s /usr/lib64/python2.7/tempfile.pyt__init__xs cCsCtj}|t|ddkr<t|_||_n|jS(Nt_rng_pid(RtgetpidtgetattrtNonet_Randomt_rngR/(R-tcur_pid((s /usr/lib64/python2.7/tempfile.pytrng|s    cCs|S(N((R-((s /usr/lib64/python2.7/tempfile.pyt__iter__scCso|j}|j}|jj}|jz#gdD]}||^q2}Wd|jX|jdj|S(Nt123456t(R*t charactersR6tchoicetacquiretreleaseR,tjoin(R-tmtctchoosetdummytletters((s /usr/lib64/python2.7/tempfile.pytnexts    # ( t__name__t __module__t__doc__R:R.tpropertyR6R7RD(((s /usr/lib64/python2.7/tempfile.pyR%ls  cCsg}x3dD]+}tj|}|r |j|q q Wtjdkrstjd}|r|j|qnAtjdkr|jddd d gn|jd d d gy|jtjWn*ttjfk r|jtjnX|S(s[Generate a list of candidate temporary directories which _get_default_tempdir will try.tTMPDIRtTEMPtTMPtriscoss Wimp$ScrapDirtntsc:\tempsc:\tmps\temps\tmps/tmps/var/tmps/usr/tmp(RIRJRK( RtgetenvtappendtnametextendtgetcwdtAttributeErrorRtcurdir(tdirlisttenvnametdirname((s /usr/lib64/python2.7/tempfile.pyt_candidate_tempdir_lists" c Cst}t}t}xv|D]n}|tjkrUtjjtjj|}nx5tdD]'}|j }tjj ||}yutj ||d}zGz2t j |ddt }|jdWdQXWdtj|XWdtj|X|SWqbttfk r} | jdtjkr2qbntjdkr| jdtjkrtjj|rtj|tjrqbnPqbXqbWqWttjd |fdS( 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.iditwbtclosefdtblatNiRMs)No usable temporary directory found in %s(R%RXt_text_openflagsRRTR+R,tabspathtxrangeRDR>Rt_ioR"twriteRtunlinktOSErrorRtargst_errnotEEXISTRPtEACCEStisdirtaccesstW_OKtENOENT( tnamerRURtdirtseqRPtfilenameR tfpte((s /usr/lib64/python2.7/tempfile.pyt_get_default_tempdirs6   ! %'  cCsGtdkrCtjztdkr1tanWdtjXntS(s7Common setup sequence for all user-callable interfaces.N(t_name_sequenceR2t _once_lockR<R%R=(((s /usr/lib64/python2.7/tempfile.pyt_get_candidate_namess   c Cst}xttD]}|j}tjj||||}y9tj||d}t||tjj |fSWqt k r} | j t j krqntjdkr| j t jkrtjj|rtj|tjrqnqXqWtt j dfdS(s>Code common to mkstemp, TemporaryFile, and NamedTemporaryFile.iRMs#No usable temporary file name foundN(RtR^RRDRR+R>RR R]RbterrnoRdReRPRfRgRhRiR( RltpretsufRtnamesRmRPtfileR Rp((s /usr/lib64/python2.7/tempfile.pyt_mkstemp_inners    !' cCstS(sAccessor for tempdir.template.(ttemplate(((s /usr/lib64/python2.7/tempfile.pyRscCsGtdkrCtjztdkr1tanWdtjXntS(sAccessor for tempfile.tempdir.N(RR2RsR<RqR=(((s /usr/lib64/python2.7/tempfile.pyR s   R9cCs@|dkrt}n|r't}nt}t||||S(s'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(R2R R\t_bin_openflagsRz(tsuffixtprefixRlttextR((s /usr/lib64/python2.7/tempfile.pyRs    cCs|dkrt}nt}xttD]}|j}tjj||||}ytj |d|SWq.t k r}|j t j krq.ntjdkr|j t jkrtjj|rtj|tjrq.nq.Xq.Wtt j dfdS(sUser-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. iRMs(No usable temporary directory name foundN(R2R RtR^RRDRR+R>tmkdirRbRuRdReRPRfRgRhRiR(R}R~RlRxRmRPRyRp((s /usr/lib64/python2.7/tempfile.pyR=s"    !' cCs|dkrt}nt}xMttD]?}|j}tjj||||}t |s.|Sq.Wt t j dfdS(sUser-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( R2R RtR^RRDRR+R>R$RRdRe(R}R~RlRxRmRPRy((s /usr/lib64/python2.7/tempfile.pyRas     t_TemporaryFileWrappercBskeZdZedZdZdZejdkr`ej Z dZ dZ dZ n dZ RS( sTemporary 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(RyRPR"t close_calledtdelete(R-RyRPR((s /usr/lib64/python2.7/tempfile.pyR.s   cCsN|jd}t||}tt|tdsJt|||n|S(NRyi(t__dict__R1t issubclassttypetsetattr(R-RPRyta((s /usr/lib64/python2.7/tempfile.pyt __getattr__s  cCs|jj|S(N(Ryt __enter__(R-((s /usr/lib64/python2.7/tempfile.pyRs RMcCsJ|jsFt|_z|jjWd|jrB|j|jnXndS(N(RR#RyRRRaRP(R-((s /usr/lib64/python2.7/tempfile.pyRs    cCs|jdS(N(R(R-((s /usr/lib64/python2.7/tempfile.pyt__del__scCs&|jj|||}|j|S(N(Ryt__exit__R(R-texctvaluettbtresult((s /usr/lib64/python2.7/tempfile.pyRs cCs|jj|||dS(N(RyR(R-RRR((s /usr/lib64/python2.7/tempfile.pyRs( RERFRGR#R.RRRRPRaRRR(((s /usr/lib64/python2.7/tempfile.pyRs     sw+bc Cs|dkrt}nd|kr-t}nt}tjdkrX|rX|tjO}nt||||\}}y)tj|||} t | ||SWn.t k rtj |tj |nXdS(sACreate 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). '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. tbRMN( R2R R|R\RRPt O_TEMPORARYRztfdopenRt BaseExceptionRaR( tmodetbufsizeR}R~RlRRR RPRy((s /usr/lib64/python2.7/tempfile.pyRs       tposixtcygwincCs|dkrt}nd|kr-t}nt}t||||\}}y$tj|tj|||SWntj|nXdS(sCreate 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. RN( R2R R|R\RzRRaRR(RRR}R~RlRR RP((s /usr/lib64/python2.7/tempfile.pyRs      cBseZdZeZddddeddZdZdZ dZ d Z d Z d Z ed Zd ZdZdZedZedZdZdZdZdZdZedZdZdZdZdZdZRS(sTemporary file wrapper, specialized to switch from StringIO to a real file when it exceeds a certain size or when a fileno is needed. isw+biR9cCs:t|_||_t|_|||||f|_dS(N(t _StringIOt_filet _max_sizeR"t_rolledt_TemporaryFileArgs(R-tmax_sizeRRR}R~Rl((s /usr/lib64/python2.7/tempfile.pyR.s   cCs?|jr dS|j}|r;|j|kr;|jndS(N(RRttelltrollover(R-RyR((s /usr/lib64/python2.7/tempfile.pyt_checks   cCsh|jr dS|j}t|j}|_|`|j|j|j|jdt|_dS(Ni( RRRRR`tgetvaluetseekRR#(R-Rytnewfile((s /usr/lib64/python2.7/tempfile.pyRs  cCs|jjrtdn|S(Ns%Cannot enter context with closed file(Rtclosedt ValueError(R-((s /usr/lib64/python2.7/tempfile.pyR,s cCs|jjdS(N(RR(R-RRR((s /usr/lib64/python2.7/tempfile.pyR1scCs |jjS(N(RR7(R-((s /usr/lib64/python2.7/tempfile.pyR75scCs|jjdS(N(RR(R-((s /usr/lib64/python2.7/tempfile.pyR8scCs |jjS(N(RR(R-((s /usr/lib64/python2.7/tempfile.pyR;scCs|j|jjS(N(RRtfileno(R-((s /usr/lib64/python2.7/tempfile.pyR?s cCs|jjdS(N(Rtflush(R-((s /usr/lib64/python2.7/tempfile.pyRCscCs |jjS(N(Rtisatty(R-((s /usr/lib64/python2.7/tempfile.pyRFscCs.y|jjSWntk r)|jdSXdS(Ni(RRRSR(R-((s /usr/lib64/python2.7/tempfile.pyRIs cCs'y|jjSWntk r"dSXdS(N(RRPRSR2(R-((s /usr/lib64/python2.7/tempfile.pyRPPs cCs |jjS(N(RRD(R-((s /usr/lib64/python2.7/tempfile.pyRDWscGs|jj|S(N(Rtread(R-Rc((s /usr/lib64/python2.7/tempfile.pyRZscGs|jj|S(N(Rtreadline(R-Rc((s /usr/lib64/python2.7/tempfile.pyR]scGs|jj|S(N(Rt readlines(R-Rc((s /usr/lib64/python2.7/tempfile.pyR`scGs|jj|dS(N(RR(R-Rc((s /usr/lib64/python2.7/tempfile.pyRcscCs |jjS(N(Rt softspace(R-((s /usr/lib64/python2.7/tempfile.pyRfscCs |jjS(N(RR(R-((s /usr/lib64/python2.7/tempfile.pyRjscCs|jjdS(N(Rttruncate(R-((s /usr/lib64/python2.7/tempfile.pyRmscCs)|j}|j|}|j||S(N(RR`R(R-tsRytrv((s /usr/lib64/python2.7/tempfile.pyR`ps  cCs)|j}|j|}|j||S(N(Rt writelinesR(R-titerableRyR((s /usr/lib64/python2.7/tempfile.pyRvs  cGs9t|jdrt|jSt|jj|SdS(Nt xreadlines(thasattrRtiterR(R-Rc((s /usr/lib64/python2.7/tempfile.pyR|s N( RERFRGR"RR{R2R.RRRRR7RRHRRRRRRPRDRRRRRRRR`RR(((s /usr/lib64/python2.7/tempfile.pyRs6                   ((((=RGt__all__tioR_tosRRuRdtrandomR R3t cStringIOR Rt ImportErrorRRR tthreadt_threadt dummy_threadt allocate_lockR)tO_RDWRtO_CREATtO_EXCLR\RRRR|RRR{RsRR!RR$R%RXRqR2RrRtRzRRR R"RRRRR#RRPtsystplatformRR(((s /usr/lib64/python2.7/tempfile.pyts~                (  +    %$@ $!