a
XC?h;m ã @ sô d Z g d¢ZddlZddlZddlZddlZ ddl
ZddlZ
ddlmZ ddlZddlZddlZddlZejZe je jB e jB Zee dƒr”ee jO ZeZ ee dƒr¬e e j!O Z ee dƒr¾e j"Z"ndZ"d Z#eƒ Z$d
d„ Z%dd
„ Z&dd„ Z'G dd„ dƒZ(dd„ Z)dd„ Z*da+dd„ Z,dd„ Z-dd„ Z.dd„ Z/dd„ Z0d d!„ Z1da2d"d#„ Z3d$d%„ Z4dAd'd(„Z5dBd)d*„Z6d+e#dfd,d-„Z7G d.d/„ d/ƒZ8G d0d1„ d1ƒZ9dCdd5œd6d7„Z:e j;d8k�s²ejdDdd5œd;d<„Z=G d=d>„ d>ƒZ?G d?d@„ d@e@ƒZAdS )Ea� 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_BINARYr i' Útmpc C s, zt | ¡ W n ty" Y dS 0 dS d S )NFT)Ú_osÚlstatÚOSError)Úfn© r ú-/opt/alt/python39/lib64/python3.9/tempfile.pyÚ_existsL s
r c G sr d}| D ]X}|du rqt |tjƒr,t |¡}t |tƒrL|tu rFtdƒ‚t}q|tu r\tdƒ‚t}q|du rntS |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)ÚargsZreturn_typeÚargr r r Ú_infer_return_typeU s
r" c C sd t | ||ƒ}|du r|ƒ }| du r:|tu r0t} n
t t¡} |du rX|tu rRtƒ }ntƒ }| |||fS )z9Common parameter processing for most APIs in this module.N)r" r Útemplater Úfsencoder r
)ÚprefixÚsuffixÚdirÚoutput_typer r r Ú_sanitize_paramsn s
r) c @ s0 e Zd ZdZdZedd„ ƒ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.Z%abcdefghijklmnopqrstuvwxyz0123456789_c C s, t ¡ }|t| dd ƒkr&tƒ | _|| _| jS )NÚ_rng_pid)r ÚgetpidÚgetattrÚ_RandomZ_rngr+ )ÚselfZcur_pidr r r ÚrngŠ s
z_RandomNameSequence.rngc C s | S ©Nr ©r/ r r r Ú__iter__’ s z_RandomNameSequence.__iter__c s0 | j ‰ | jj‰‡ ‡fdd„tdƒD ƒ}d |¡S )Nc s g | ]}ˆˆ ƒ‘qS r r )Ú.0Zdummy©ÚcZchooser r Ú
˜ ó z0_RandomNameSequence.__next__..é Ú )Ú
charactersr0 ZchoiceÚrangeÚjoin)r/ Zlettersr r5 r Ú__next__• s z_RandomNameSequence.__next__N) Ú__name__Ú
__module__Ú__qualname__Ú__doc__r; Úpropertyr0 r3 r> r r r r r* € s
r* c C s g } dD ]}t |¡}|r| |¡ qt jdkrX| t j d¡t j d¡ddddg¡ n| g d ¢¡ z| t ¡ ¡ W n" t t
fyš | t j¡ Y n0 | S )
z[Generate a list of candidate temporary directories which
_get_default_tempdir will try.)ZTMPDIRZTEMPZTMPÚ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)ÚdirlistZenvnameÚdirnamer r r Ú_candidate_tempdir_list› s
þrQ c C sh t ƒ } tƒ }|D �]@}|tjkr,tj |¡}tdƒD �]}t| ƒ}tj ||¡}zŽt |t
d¡}zdzHtj |ddd��}| d¡ W d ƒ n1 s”0 Y W t
|¡ nt
|¡ 0 W t |¡ nt |¡ 0 |W S tyð Y q4 t�y6 tjdk�r,tj |¡�r,t |tj¡�r,Y q4Y qY q4 t�yN Y qY q40 q4qttjd | ƒ‚dS )
aq Calculate 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)Úclosefds blatNrD z)No usable temporary directory found in %s)r* rQ r rN rI Úabspathr<