AlkantarClanX12

Your IP : 18.116.40.53


Current Path : /lib64/python3.8/__pycache__/
Upload File :
Current File : //lib64/python3.8/__pycache__/tempfile.cpython-38.pyc

U

e5d�k�
@s�dZddddddddd	d
ddd
g
ZddlZddlZddlZddlZ	ddl
ZddlZ
ddlmZddlZddlZddlZejZe	je	jBe	jBZee	d�r�ee	jOZeZee	d�r�ee	jOZee	d�r�e	j Z ndZ dZ!e�Z"dd�Z#dd�Z$dd�Z%Gdd�d�Z&dd�Z'dd �Z(da)d!d"�Z*d#d$�Z+d%d	�Z,d&d�Z-da.d'd�Z/d(d
�Z0d=d*d�Z1d>d+d�Z2d,e!dfd-d�Z3Gd.d/�d/�Z4Gd0d1�d1�Z5d?dd5�d6d�Z6e	j7d7k�s�ej8d8k�r�e6Z9nee	d9�a:d@dd5�d:d�Z9Gd;d�d�Z;Gd<d�de<�Z=dS)Aa�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_BINARYi'ZtmpcCs.zt�|�Wntk
r$YdSXdSdS)NFT)�_os�lstat�OSError)�fn�r� /usr/lib64/python3.8/tempfile.py�_existsKs
rcGs\d}|D]B}|dkrqt|t�r6|tkr0td��t}q|tkrFtd��t}q|dkrXtS|S)zBLook at the type of all args and divine their implied return type.Nz1Can't mix bytes and non-bytes in path components.)�
isinstance�bytes�str�	TypeError)�argsZreturn_type�argrrr�_infer_return_typeTs
rcCsdt|||�}|dkr|�}|dkr:|tkr0t}n
t�t�}|dkrX|tkrRt�}nt�}||||fS)z9Common parameter processing for most APIs in this module.N)rr�templater�fsencoderr
)�prefix�suffix�dir�output_typerrr�_sanitize_paramsis
r&c@s0eZdZdZdZedd��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_cCs,t��}|t|dd�kr&t�|_||_|jS)N�_rng_pid)r�getpid�getattr�_RandomZ_rngr()�selfZcur_pidrrr�rng�s
z_RandomNameSequence.rngcCs|S�Nr�r,rrr�__iter__�sz_RandomNameSequence.__iter__cs0|j�|jj���fdd�td�D�}d�|�S)Ncsg|]}����qSrr)�.0Zdummy��cZchooserr�
<listcomp>�sz0_RandomNameSequence.__next__.<locals>.<listcomp>��)�
charactersr-Zchoice�range�join)r,Zlettersrr2r�__next__�sz_RandomNameSequence.__next__N)	�__name__�
__module__�__qualname__�__doc__r7�propertyr-r0r:rrrrr'{s
r'c	Cs�g}dD]}t�|�}|r|�|�qtjdkrX|�tj�d�tj�d�ddddg�n|�d	d
dg�z|�t���Wn$t	t
fk
r�|�tj�YnX|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\tmpz/tmpz/var/tmpz/usr/tmp)r�getenv�append�name�extend�path�
expanduser�
expandvars�getcwd�AttributeErrorr�curdir)�dirlistZenvname�dirnamerrr�_candidate_tempdir_list�s&


�rMcCsFt�}t�}|D�]}|tjkr,tj�|�}td�D�]�}t|�}tj�||�}zft�	|t
d�}z<z*t
j	|ddd��}|�d�W5QRXW5t�|�XW5t�|�X|WStk
r�Yq4tk
�rtjdk�rtj�|��rt�|tj��rYq4YqYq4tk
�r,YqYq4Xq4qttjd|��d	S)
aqCalculate 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)�closefdsblatr@z)No usable temporary directory found in %sN)r'rMrrJrE�abspathr8�nextr9�open�_bin_openflags�unlink�close�_io�write�FileExistsError�PermissionErrorrC�isdir�access�W_OKr�FileNotFoundError�_errnoZENOENT)ZnamerrKr$�seqrC�filename�fd�fprrr�_get_default_tempdir�s@	

�
��recCs2tdkr.t��ztdkr t�aW5t��XtS)z7Common setup sequence for all user-callable interfaces.N)�_name_sequence�
_once_lock�acquire�releaser'rrrr�_get_candidate_names�s

rjc
	Cs�t�}|tkrttj|�}tt�D]�}t|�}tj�	||||�}t
�d|�zt�||d�}	WnVt
k
rzYq"Yn@tk
r�tjdkr�tj�|�r�t�|tj�r�Yq"n�YnX|	tj�|�fSt
tjd��dS)z>Code common to mkstemp, TemporaryFile, and NamedTemporaryFile.ztempfile.mkstemprOr@z#No usable temporary file name foundN)rjr�maprr!r8rrSrEr9�_sys�auditrTrZr[rCr\r]r^rRr`�EEXIST)
r$ZpreZsuf�flagsr%�namesrarC�filercrrr�_mkstemp_inner�s*��rrcCstS)z-The default prefix for temporary directories.)r rrrrr	
scCst�t��S)z6The default prefix for temporary directories as bytes.)rr!r	rrrrrscCs2tdkr.t��ztdkr t�aW5t��XtS)zAccessor for tempfile.tempdir.N)r
rgrhrirerrrrrs

cCst�t��S)z)A bytes version of tempfile.gettempdir().)rr!rrrrrr
#sFcCs2t|||�\}}}}|rt}nt}t|||||�S)a�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 not None, the file name will end with that suffix,
    otherwise there will be no suffix.

    If 'prefix' is not None, the file name will begin with that prefix,
    otherwise a default prefix is used.

    If 'dir' is not None, 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.

    If any of 'suffix', 'prefix' and 'dir' are not None, they must be the
    same type.  If they are bytes, the returned name will be bytes; str
    otherwise.

    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.
    )r&�_text_openflagsrUrr)r#r"r$�textr%rorrrr's
c	Cs�t|||�\}}}}t�}|tkr.ttj|�}tt�D]�}t|�}tj	�
||||�}t�d|�zt�
|d�WnVtk
r�Yq6Yn@tk
r�tjdkr�tj	�|�r�t�|tj�r�Yq6n�YnX|Sttjd��dS)aUser-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.
    ztempfile.mkdtemp�r@z(No usable temporary directory name foundN)r&rjrrkrr!r8rrSrEr9rlrm�mkdirrZr[rCr\r]r^r`rn)r#r"r$r%rprarCrqrrrrNs,
��r6cCs`|dkrt�}t�}tt�D]2}t|�}tj�||||�}t|�s|Sqt	t
jd��dS)a�User-callable function to return a unique temporary file name.  The
    file is not created.

    Arguments are similar to mkstemp, except that the 'text' argument is
    not accepted, and suffix=None, prefix=None and bytes file names are not
    supported.

    THIS FUNCTION IS UNSAFE AND SHOULD NOT BE USED.  The file name may
    refer 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.
    Nz"No usable temporary filename found)rrjr8rrSrrEr9rrZr`rn)r#r"r$rprarCrqrrrrvs
�c@sLeZdZdZdZdZd
dd�Zejdkr@ej	fdd	�Z
d
d�Zndd	�Z
dS)�_TemporaryFileCloserz�A separate object allowing proper closing of a temporary file's
    underlying file object, without adding a __del__ method to the
    temporary file.NFTcCs||_||_||_dSr.)rqrC�delete�r,rqrCrxrrr�__init__�sz_TemporaryFileCloser.__init__r@cCs<|js8|jdk	r8d|_z|j��W5|jr6||j�XdS�NT)�close_calledrqrxrCrW)r,rVrrrrW�sz_TemporaryFileCloser.closecCs|��dSr.)rWr/rrr�__del__�sz_TemporaryFileCloser.__del__cCs|jsd|_|j��dSr{)r|rqrWr/rrrrW�s)T)r;r<r=r>rqr|rzrrCrVrWr}rrrrrw�s



rwc@sBeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�_TemporaryFileWrapperz�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.
    TcCs$||_||_||_t|||�|_dSr.)rqrCrxrw�_closerryrrrrz�sz_TemporaryFileWrapper.__init__cs^|jd}t||�}t|d�rD|�t����fdd��}|j|_|}t|t�sZt|||�|S)Nrq�__call__cs
�||�Sr.r)r�kwargs��funcrr�func_wrapper�sz7_TemporaryFileWrapper.__getattr__.<locals>.func_wrapper)	�__dict__r*�hasattr�
_functools�wrapsrr�int�setattr)r,rCrq�ar�rr�r�__getattr__�s



z!_TemporaryFileWrapper.__getattr__cCs|j��|Sr.)rq�	__enter__r/rrrr��s
z_TemporaryFileWrapper.__enter__cCs|j�|||�}|��|Sr.)rq�__exit__rW)r,�exc�value�tb�resultrrrr��sz_TemporaryFileWrapper.__exit__cCs|j��dS)zA
        Close the temporary file, possibly deleting it.
        N)rrWr/rrrrW�sz_TemporaryFileWrapper.closeccs|jD]
}|VqdSr.)rq)r,�linerrrr0�s
z_TemporaryFileWrapper.__iter__N)T)
r;r<r=r>rzr�r�r�rWr0rrrrr~�s
r~�w+b���T��errorscCs�t|||�\}}}}	t}
tjdkr0|r0|
tjO}
t||||
|	�\}}z$tj||||||d�}
t|
||�WSt	k
r�t�
|�t�|��YnXdS)a�Create and return a temporary file.
    Arguments:
    'prefix', 'suffix', 'dir' -- as for mkstemp.
    'mode' -- the mode argument to io.open (default "w+b").
    'buffering' -- the buffer size argument to io.open (default -1).
    'encoding' -- the encoding argument to io.open (default None)
    'newline' -- the newline argument to io.open (default None)
    'delete' -- whether the file is deleted on close (default True).
    'errors' -- the errors argument to io.open (default None)
    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.
    r@��	buffering�newline�encodingr�N)r&rUrrCZO_TEMPORARYrrrXrTr~�
BaseExceptionrVrW)�moder�r�r�r#r"r$rxr�r%rorcrCrqrrrrs 

�

�posix�cygwin�	O_TMPFILEc
Cs�t|||�\}}}}t}	tr�z$|	tjBtj@}
t�||
d�}Wn*tk
rXdaYnFtk
rjYn4Xzt	j||||||d�WSt�
|��YnXt||||	|�\}}z"t�|�t	j||||||d�WSt�
|��YnXdS)a�Create and return a temporary file.
        Arguments:
        'prefix', 'suffix', 'dir' -- as for mkstemp.
        'mode' -- the mode argument to io.open (default "w+b").
        'buffering' -- the buffer size argument to io.open (default -1).
        'encoding' -- the encoding argument to io.open (default None)
        'newline' -- the newline argument to io.open (default None)
        'errors' -- the errors argument to io.open (default None)
        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.
        rOFr�N)
r&rU�_O_TMPFILE_WORKSrr��O_CREATrT�IsADirectoryErrorrrXrWrrrV)
r�r�r�r�r#r"r$r�r%roZflags2rcrCrrrr2s<
�


�
c@seZdZdZdZd:dd�dd	�Zd
d�Zdd
�Zdd�Zdd�Z	dd�Z
dd�Zedd��Z
edd��Zedd��Zdd�Zdd�Zd d!�Zed"d#��Zed$d%��Zed&d'��Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zed0d1��Zd2d3�Zd;d4d5�Zd6d7�Zd8d9�ZdS)<rz�Temporary file wrapper, specialized to switch from BytesIO
    or StringIO to a real file when it exceeds a certain size or
    when a fileno is needed.
    Frr�r�Nr�c	
	CsTd|krt��|_ntjt��||	|d�|_||_d|_||||||||	d�|_dS)N�b)r�r�r�F)r�r�r#r"r�r�r$r�)rX�BytesIO�_file�
TextIOWrapper�	_max_size�_rolled�_TemporaryFileArgs)
r,�max_sizer�r�r�r�r#r"r$r�rrrrzus"
��zSpooledTemporaryFile.__init__cCs,|jr
dS|j}|r(|��|kr(|��dSr.)r�r��tell�rollover)r,rqr�rrr�_check�s
zSpooledTemporaryFile._checkcCsr|jr
dS|j}tf|j�}|_|`|��}t|d�rN|j�|���	��n|�|�	��|�
|d�d|_dS)N�bufferrT)r�r�rr�r�r�r�rY�detach�getvalue�seek)r,rqZnewfile�posrrrr��s
zSpooledTemporaryFile.rollovercCs|jjrtd��|S)Nz%Cannot enter context with closed file)r��closed�
ValueErrorr/rrrr��szSpooledTemporaryFile.__enter__cCs|j��dSr.�r�rW�r,r�r�r�rrrr��szSpooledTemporaryFile.__exit__cCs
|j��Sr.)r�r0r/rrrr0�szSpooledTemporaryFile.__iter__cCs|j��dSr.r�r/rrrrW�szSpooledTemporaryFile.closecCs|jjSr.)r�r�r/rrrr��szSpooledTemporaryFile.closedcCs|jjSr.)r�r�r/rrrr��szSpooledTemporaryFile.encodingcCs|jjSr.)r�r�r/rrrr��szSpooledTemporaryFile.errorscCs|��|j��Sr.)r�r��filenor/rrrr��szSpooledTemporaryFile.filenocCs|j��dSr.)r��flushr/rrrr��szSpooledTemporaryFile.flushcCs
|j��Sr.)r��isattyr/rrrr��szSpooledTemporaryFile.isattycCs.z
|jjWStk
r(|jdYSXdS)Nr�)r�r�rIr�r/rrrr��s
zSpooledTemporaryFile.modecCs&z
|jjWStk
r YdSXdSr.)r�rCrIr/rrrrC�s
zSpooledTemporaryFile.namecCs|jjSr.)r��newlinesr/rrrr��szSpooledTemporaryFile.newlinescGs|jj|�Sr.)r��read�r,rrrrr��szSpooledTemporaryFile.readcGs|jj|�Sr.)r��readliner�rrrr��szSpooledTemporaryFile.readlinecGs|jj|�Sr.)r��	readlinesr�rrrr��szSpooledTemporaryFile.readlinescGs|jj|�Sr.)r�r�r�rrrr��szSpooledTemporaryFile.seekcCs|jjSr.)r��	softspacer/rrrr��szSpooledTemporaryFile.softspacecCs
|j��Sr.)r�r�r/rrrr��szSpooledTemporaryFile.tellcCs6|dkr|j��n||jkr&|��|j�|�dSr.)r��truncater�r�)r,�sizerrrr��s

zSpooledTemporaryFile.truncatecCs|j}|�|�}|�|�|Sr.)r�rYr�)r,�srq�rvrrrrY�s

zSpooledTemporaryFile.writecCs|j}|�|�}|�|�|Sr.)r��
writelinesr�)r,�iterablerqr�rrrr��s

zSpooledTemporaryFile.writelines)rr�r�NNNNN)N)r;r<r=r>r�rzr�r�r�r�r0rWr?r�r�r�r�r�r�r�rCr�r�r�r�r�r�r�r�rYr�rrrrrnsT��







c@sReZdZdZddd�Zedd��Zedd��Zd	d
�Zdd�Z	d
d�Z
dd�ZdS)ra+Create and return a temporary directory.  This has the same
    behavior as mkdtemp but can be used as a context manager.  For
    example:

        with TemporaryDirectory() as tmpdir:
            ...

    Upon exiting the context, the directory and everything contained
    in it are removed.
    NcCs0t|||�|_tj||j|jd�|�d�|_dS)NzImplicitly cleaning up {!r})�warn_message)rrC�_weakrefZfinalize�_cleanup�format�
_finalizer)r,r#r"r$rrrrzs�zTemporaryDirectory.__init__cs ��fdd�}tj�|d�dS)Nc	s�t|dt�r�dd�}zV|�kr0|tj�|��||�zt�|�Wn"ttfk
rh��|�YnXWq�tk
r�Yq�Xnt|dt�r�n�dS)NrcSs6zt�|d�Wntk
r$YnXt�|d�dS)Nrru)rZchflagsrI�chmod)rErrr�
resetpermss
z?TemporaryDirectory._rmtree.<locals>.onerror.<locals>.resetperms)	�
issubclassr[rrErLrVr��_rmtreer_)r�rE�exc_infor���clsrCrr�onerrorsz+TemporaryDirectory._rmtree.<locals>.onerror)r�)�_shutilZrmtree)r�rCr�rr�rr�szTemporaryDirectory._rmtreecCs|�|�t�|t�dSr.)r��	_warnings�warn�ResourceWarning)r�rCr�rrrr�/s
zTemporaryDirectory._cleanupcCsd�|jj|j�S)Nz	<{} {!r}>)r��	__class__r;rCr/rrr�__repr__4szTemporaryDirectory.__repr__cCs|jSr.)rCr/rrrr�7szTemporaryDirectory.__enter__cCs|��dSr.)�cleanupr�rrrr�:szTemporaryDirectory.__exit__cCs|j��r|�|j�dSr.)r�r�r�rCr/rrrr�=s
zTemporaryDirectory.cleanup)NNN)r;r<r=r>rz�classmethodr�r�r�r�r�r�rrrrr�s


)NNNF)NNN)r�r�NNNNNT)r�r�NNNNN)>r>�__all__�	functoolsr��warningsr��iorX�osrZshutilr��errnor`Zrandomrr+�sysrl�weakrefr��_thread�
allocate_lockZ_allocate_lock�O_RDWRr��O_EXCLrsr�rrUrrr rgrrr&r'rMrerfrjrrr	rr
rr
rrrrwr~rrC�platformrr�r�objectrrrrr�<module>s��





	-
'
( +?��'
��<