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<