�`^c
@sdZddddddddd d
g
ZddlZddlZddlZdd
lm Z
yddlmZ
Wn!ek
r�ddlmZ
nXyddlZWnek
r�d�Zn
Xd�ZyddlZWnek
r�ddlZnXejZejejBejBZeed�r;eejOZneed�rZeejOZneZeed�reejOZneed�r�ej Z ndZ dZ!e�Z"eed�r�ej#Z$n$eed�r�j%Z$n d�Z$d�Z&dd.d��YZ'd�Z(d�Z)da+d�Z,d�Z-d �Z.da/d!�Z0d"e!de1d#�Z2d"e!dd$�Z3d"e!dd%�Z4d&d/d'��YZ5d(dd"e!de6d)�Z7ej8d*ks�ej9j:d+kr�e7Z;nd(dd"e!dd,�Z;dd0d-��YZ<dS(1s�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
TemporaryFiletSpooledTemporaryFiletmkstemptmkdtemptmktemptTMP_MAXt
gettempprefixttempdirt
gettempdiri�N(tRandom(tStringIOcCsdS(N((tfd((s/sys/lib/python2.7/tempfile.pyt_set_cloexec-scCsWytj|tjd�}Wntk
r/n$X|tjO}tj|tj|�dS(Ni(t_fcntltfcntltF_GETFDtIOErrort
FD_CLOEXECtF_SETFD(Rtflags((s/sys/lib/python2.7/tempfile.pyR
0s
tO_NOINHERITt
O_NOFOLLOWtO_BINARYi'ttmptlstattstatcCs;yt|�}Wntk
r,tj�nX|j�dS(N(topenRt_osterrortclose(tfntf((s/sys/lib/python2.7/tempfile.pyt_stat]s
cCs.yt|�Wntjk
r%tSXtSdS(N(R!RRtFalsetTrue(R((s/sys/lib/python2.7/tempfile.pyt_existsds
t_RandomNameSequencecBsFeZdZdddZd�Zed��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.tabcdefghijklmnopqrstuvwxyztABCDEFGHIJKLMNOPQRSTUVWXYZt0123456789_cCst�|_tjj|_dS(N(t_allocate_locktmutexRtpathtnormcase(tself((s/sys/lib/python2.7/tempfile.pyt__init__xscCsCtj�}|t|dd�kr<t�|_||_n|jS(Nt_rng_pid(RtgetpidtgetattrtNonet_Randomt_rngR/(R-tcur_pid((s/sys/lib/python2.7/tempfile.pytrng|s
cCs|S(N((R-((s/sys/lib/python2.7/tempfile.pyt__iter__�scCso|j}|j}|jj}|j�z#gdD]}||�^q2}Wd|j�X|jdj|��S(Nt123456t(R*t
charactersR6tchoicetacquiretreleaseR,tjoin(R-tmtctchoosetdummytletters((s/sys/lib/python2.7/tempfile.pytnext�s
#( t__name__t
__module__t__doc__R:R.tpropertyR6R7RD(((s/sys/lib/python2.7/tempfile.pyR%ls cCs�g}x3dD]+}tj|�}|r
|j|�q
q
Wtjdkrstjd�}|r�|j|�q�nAtjdkr�|jddd d
g�n|jddd
g�y|jtj��Wn*ttjfk
r�|jtj�nX|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/sys/lib/python2.7/tempfile.pyt_candidate_tempdir_list�s"
c
CsVt�}t�}t}x!|D]}|tjkrUtjjtjj|��}nx�d�D]�}|j �}tjj
||�}yutj||d�}zGz2tj|ddt
��}|jd�WdQXWdtj|�XWdtj|�X|SWqbttfk
r3} | jdtjkr4Pq4qbXqbWqWttjd|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�twbtclosefdtblatNis)No usable temporary directory found in %s(R%RXt_text_openflagsRRTR+R,tabspathtxrangeRDR>Rt_ioR"twriteRtunlinktOSErrorRtargst_errnotEEXISTtENOENT(
tnamerRURtdirtseqRPtfilenameRtfpte((s/sys/lib/python2.7/tempfile.pyt_get_default_tempdir�s0
! cCsGtdkrCtj�ztdkr1t�anWdtj�XntS(s7Common setup sequence for all user-callable interfaces.N(t_name_sequenceR2t
_once_lockR<R%R=(((s/sys/lib/python2.7/tempfile.pyt_get_candidate_names�s
c
Cs�t�}x�tt�D]�}|j�}tjj||||�}y9tj||d�}t|�|tjj |�fSWqt
k
r�} | jtj
kr�qntjdkr�| jtjkr�qn�qXqWttj
df�dS(s>Code common to mkstemp, TemporaryFile, and NamedTemporaryFile.i�RMs#No usable temporary file name foundN(RpR^RRDRR+R>RR
R]RbterrnoRdReRPtEACCESR(
RhtpretsufRtnamesRiRPtfileRRl((s/sys/lib/python2.7/tempfile.pyt_mkstemp_inner�s
!cCstS(sAccessor for tempdir.template.(ttemplate(((s/sys/lib/python2.7/tempfile.pyRscCsGtdkrCtj�ztdkr1t�anWdtj�XntS(sAccessor for tempfile.tempdir.N(RR2RoR<RmR=(((s/sys/lib/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_openflagsRw(tsuffixtprefixRhttextR((s/sys/lib/python2.7/tempfile.pyRs cCs�|dkrt�}nt�}x�tt�D]x}|j�}tjj||||�}ytj |d�|SWq.t
k
r�}|jtj
kr�q.n�q.Xq.Wttj
df�dS(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.
i�s(No usable temporary directory name foundN(R2R RpR^RRDRR+R>tmkdirRbRqRdReR(RzR{RhRuRiRPRvRl((s/sys/lib/python2.7/tempfile.pyR7s
cCs�|dkrt�}nt�}xMtt�D]?}|j�}tjj||||�}t |�s.|Sq.Wt
tjdf�dS(s�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(
R2R RpR^RRDRR+R>R$RRdRe(RzR{RhRuRiRPRv((s/sys/lib/python2.7/tempfile.pyRVs t_TemporaryFileWrappercBskeZdZed�Zd�Zd�Zejdkr`ej Z d�Z
d�Zd�Zn d�ZRS( 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(RvRPR"tclose_calledtdelete(R-RvRPR�((s/sys/lib/python2.7/tempfile.pyR.|s cCsN|jd}t||�}tt|�td��sJt|||�n|S(NRvi(t__dict__R1t
issubclassttypetsetattr(R-RPRvta((s/sys/lib/python2.7/tempfile.pyt__getattr__�s
cCs|jj�|S(N(Rvt __enter__(R-((s/sys/lib/python2.7/tempfile.pyR��s
RMcCsB|js>t|_|jj�|jr>|j|j�q>ndS(N(RR#RvRR�RaRP(R-((s/sys/lib/python2.7/tempfile.pyR�s
cCs|j�dS(N(R(R-((s/sys/lib/python2.7/tempfile.pyt__del__�scCs&|jj|||�}|j�|S(N(Rvt__exit__R(R-texctvaluettbtresult((s/sys/lib/python2.7/tempfile.pyR��s
cCs|jj|||�dS(N(RvR�(R-R�R�R�((s/sys/lib/python2.7/tempfile.pyR��s(
RERFRGR#R.R�R�RRPRaRR�R�(((s/sys/lib/python2.7/tempfile.pyR~ts sw+bc
Cs�|dkrt�}nd|kr-t}nt}tjdkrX|rX|tjO}nt||||�\}}y)tj|||�} t | ||�SWntj
|��nXdS(s6Create 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 file.name. The file will be automatically deleted
when it is closed unless the 'delete' argument is set to False.
tbRMN(R2R RyR\RRPtO_TEMPORARYRwtfdopenR~R(
tmodetbufsizeRzR{RhR�RRRPRv((s/sys/lib/python2.7/tempfile.pyR�s
tposixtcygwincCs�|dkrt�}nd|kr-t}nt}t||||�\}}y$tj|�tj|||�SWntj|��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( R2R RyR\RwRRaR�R(R�R�RzR{RhRRRP((s/sys/lib/python2.7/tempfile.pyR�s
cBseZdZeZddddedd�Zd�Zd�Z d�Z
d �Zd
�Zd�Z
ed��Zd
�Zd�Zd�Zed��Zed��Zd�Zd�Zd�Zd�Zd�Zed��Zd�Zd�Zd�Zd�Zd�ZRS(s�Temporary file wrapper, specialized to switch from
StringIO to a real file when it exceeds a certain size or
when a fileno is needed.
isw+bi�R9cCs:t�|_||_t|_|||||f|_dS(N(t _StringIOt_filet _max_sizeR"t_rolledt_TemporaryFileArgs(R-tmax_sizeR�R�RzR{Rh((s/sys/lib/python2.7/tempfile.pyR.s cCs?|jr
dS|j}|r;|j�|kr;|j�ndS(N(R�R�ttelltrollover(R-RvR�((s/sys/lib/python2.7/tempfile.pyt_checks
cCsh|jr
dS|j}t|j�}|_|`|j|j��|j|j�d�t|_dS(Ni( R�R�RR�R`tgetvaluetseekR�R#(R-Rvtnewfile((s/sys/lib/python2.7/tempfile.pyR�
s cCs|jjrtd��n|S(Ns%Cannot enter context with closed file(R�tclosedt
ValueError(R-((s/sys/lib/python2.7/tempfile.pyR�scCs|jj�dS(N(R�R(R-R�R�R�((s/sys/lib/python2.7/tempfile.pyR�#scCs
|jj�S(N(R�R7(R-((s/sys/lib/python2.7/tempfile.pyR7'scCs|jj�dS(N(R�R(R-((s/sys/lib/python2.7/tempfile.pyR*scCs
|jjS(N(R�R�(R-((s/sys/lib/python2.7/tempfile.pyR�-scCs|j�|jj�S(N(R�R�tfileno(R-((s/sys/lib/python2.7/tempfile.pyR�1s
cCs|jj�dS(N(R�tflush(R-((s/sys/lib/python2.7/tempfile.pyR�5scCs
|jj�S(N(R�tisatty(R-((s/sys/lib/python2.7/tempfile.pyR�8scCs.y|jjSWntk
r)|jdSXdS(Ni(R�R�RSR�(R-((s/sys/lib/python2.7/tempfile.pyR�;s
cCs'y|jjSWntk
r"dSXdS(N(R�RPRSR2(R-((s/sys/lib/python2.7/tempfile.pyRPBs
cCs
|jjS(N(R�RD(R-((s/sys/lib/python2.7/tempfile.pyRDIscGs|jj|�S(N(R�tread(R-Rc((s/sys/lib/python2.7/tempfile.pyR�LscGs|jj|�S(N(R�treadline(R-Rc((s/sys/lib/python2.7/tempfile.pyR�OscGs|jj|�S(N(R�t readlines(R-Rc((s/sys/lib/python2.7/tempfile.pyR�RscGs|jj|�dS(N(R�R�(R-Rc((s/sys/lib/python2.7/tempfile.pyR�UscCs
|jjS(N(R�t softspace(R-((s/sys/lib/python2.7/tempfile.pyR�XscCs
|jj�S(N(R�R�(R-((s/sys/lib/python2.7/tempfile.pyR�\scCs|jj�dS(N(R�ttruncate(R-((s/sys/lib/python2.7/tempfile.pyR�_scCs)|j}|j|�}|j|�|S(N(R�R`R�(R-tsRvtrv((s/sys/lib/python2.7/tempfile.pyR`bs
cCs)|j}|j|�}|j|�|S(N(R�t
writelinesR�(R-titerableRvR�((s/sys/lib/python2.7/tempfile.pyR�hs
cGs9t|jd�rt|j�St|jj|��SdS(Nt
xreadlines(thasattrR�titerR�(R-Rc((s/sys/lib/python2.7/tempfile.pyR�ns
N( RERFRGR"R�RxR2R.R�R�R�R�R7RRHR�R�R�R�R�RPRDR�R�R�R�R�R�R�R`R�R�(((s/sys/lib/python2.7/tempfile.pyR�s6 ((((=RGt__all__tioR_tosRRqRdtrandomR
R3t cStringIORR�tImportErrorRRR
tthreadt_threadtdummy_threadt
allocate_lockR)tO_RDWRtO_CREATtO_EXCLR\R�RRRyRRRxRoRR!RR$R%RXRmR2RnRpRwRRR R"RRRR~R#RRPtsystplatformRR(((s/sys/lib/python2.7/tempfile.pyt<module>s~
( & %> #!
|