%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core20/current/lib/python3.8/__pycache__/
Upload File :
Create Path :
Current File : //snap/core20/current/lib/python3.8/__pycache__/tempfile.cpython-38.pyc

U

k�]e{�
@stdZddddddddd	d
ddd
g
ZddlZddlZddlZddlZ	zddl
ZejZ
Wnpek
r�ddlZddlZdd�Zdd�Ze	je	je	je	jhe	jko�e	je	jko�e	je	jkZdCdd�Z
YnXddlZddlm Z!ddlZddl"Z#ddl$Z$e$j%Z&e	j'e	j(Be	j)BZ*e+e	d��r e*e	j,OZ*e*Z-e+e	d��r:e-e	j.OZ-e+e	d��rNe	j/Z/ndZ/dZ0e&�Z1dd�Z2dd�Z3d d!�Z4Gd"d#�d#�Z5d$d%�Z6d&d'�Z7da8d(d)�Z9d*d+�Z:d,d	�Z;d-d�Z<da=d.d�Z>d/d
�Z?dDd0d�Z@dEd1d�ZAd2e0dfd3d�ZBGd4d5�d5�ZCGd6d7�d7�ZDdFdd;�d<d�ZEe	jFd=k�s2ejGd>k�r8eEZHne+e	d?�aIdGdd;�d@d�ZHGdAd�d�ZJGdBd�deK�ZLdS)Ha�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�Nc	CsJztj�|�rtd��Wn*tk
rB|tjj|t���YdSXg}zt�|�}Wn&tk
r||tj|t���YnX|D]�}tj�||�}zt�|�j	}Wntk
r�d}YnXt
�|�r�t||�q�zt�
|�Wq�tk
�r
|tj
|t���Yq�Xq�zt�|�Wn(tk
�rD|tj|t���YnXdS)N�%Cannot call rmtree on a symbolic linkr)�_os�path�islink�OSError�_sys�exc_info�listdir�join�lstat�st_mode�_stat�S_ISDIR�_rmtree_unsafe�unlink�rmdir)r�onerror�names�name�fullname�mode�r$�/usr/lib/python3.8/tempfile.pyr2s6

rc

Cs�g}zt�|�}Wn:tk
rL}z||_|tj|t���W5d}~XYnX|D�]x}tj�||�}ztj||dd�}|j	}Wntk
r�d}YnXt
�|��r�ztj|tj
|d�}	Wn&tk
r�|tj|t���Yn�Xz�tj�|t�|	���rFt|	||�ztj||d�Wn(tk
�rB|tj|t���YnXn8ztd��Wn*tk
�r||tjj|t���YnXW5t�|	�XqRztj||d�WqRtk
�r�|tj|t���YqRXqRdS)NF)�dir_fd�follow_symlinksr)r&r)rrr�filenamerrrr�statrrr�open�O_RDONLY�close�samestat�fstat�_rmtree_safe_fdrrr)
�topfdrrr �errr!r"�orig_str#�dirfdr$r$r%r/SsD$


r/Fc	Csb|rdd�}n|dkrdd�}t�rTt|t�r8t�|�}zt�|�}Wn(tk
rn|tj|t���YdSXzt�	|tj
�}Wn(tk
r�|tj|t���YdSXz�tj�
|t�|���r
t|||�zt�|�Wn(tk
�r|tj|t���YnXn8ztd��Wn*tk
�r@|tjj|t���YnXW5t�|�Xn
t||�SdS)a�Recursively delete a directory tree.

    If ignore_errors is set, errors are ignored; otherwise, if onerror
    is set, it is called to handle the error with arguments (func,
    path, exc_info) where func is platform and implementation dependent;
    path is the argument to that function that caused it to fail; and
    exc_info is a tuple returned by sys.exc_info().  If ignore_errors
    is false and onerror is None, an exception is raised.

    cWsdS�Nr$��argsr$r$r%r�sz_rmtree.<locals>.onerrorNcWs�dSr4r$r5r$r$r%r�sr)�_use_fd_functions�
isinstance�bytesr�fsdecoder�	Exceptionrrr*r+r,rr-r.r/rrrr)r�
ignore_errorsrr2�fdr$r$r%�_rmtree�s<


r>)�Random�
O_NOFOLLOW�O_BINARYi'ZtmpcCs.zt�|�Wntk
r$YdSXdSdS)NFT)rrr)�fnr$r$r%�_exists�s
rCcGs\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.)r8r9�str�	TypeError)r6Zreturn_type�argr$r$r%�_infer_return_type�s
rGcCsdt|||�}|dkr|�}|dkr:|tkr0t}n
t�t�}|dkrX|tkrRt�}nt�}||||fS)z9Common parameter processing for most APIs in this module.N)rGrD�templater�fsencoderr
)�prefix�suffix�dir�output_typer$r$r%�_sanitize_params�s
rNc@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_rngrP)�selfZcur_pidr$r$r%�rngs
z_RandomNameSequence.rngcCs|Sr4r$�rTr$r$r%�__iter__sz_RandomNameSequence.__iter__cs0|j�|jj���fdd�td�D�}d�|�S)Ncsg|]}����qSr$r$)�.0Zdummy��cZchooser$r%�
<listcomp>sz0_RandomNameSequence.__next__.<locals>.<listcomp>��)�
charactersrUZchoice�ranger)rTZlettersr$rYr%�__next__sz_RandomNameSequence.__next__N)	�__name__�
__module__�__qualname__�__doc__r^�propertyrUrWr`r$r$r$r%rOs
rOc	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�appendr!�extendr�
expanduser�
expandvars�getcwd�AttributeErrorr�curdir)�dirlistZenvname�dirnamer$r$r%�_candidate_tempdir_list!s&


�rqcCsFt�}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)�closefdsblatrfz)No usable temporary directory found in %sN)rOrqrrnr�abspathr_�nextrr*�_bin_openflagsrr,�_io�write�FileExistsError�PermissionErrorr!�isdir�access�W_OKr�FileNotFoundError�_errnoZENOENT)ZnamerrorL�seqr!r(r=�fpr$r$r%�_get_default_tempdir<s@	

�
��r�cCs2tdkr.t��ztdkr t�aW5t��XtS)z7Common setup sequence for all user-callable interfaces.N)�_name_sequence�
_once_lock�acquire�releaserOr$r$r$r%�_get_candidate_namesks

r�c
	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.mkstemprsrfz#No usable temporary file name foundN)r�r9�maprrIr_rrwrrr�auditr*r{r|r!r}r~rrvr��EEXIST)
rLZpreZsuf�flagsrMr r�r!�filer=r$r$r%�_mkstemp_innerys*��r�cCstS)z-The default prefix for temporary directories.)rHr$r$r$r%r	�scCst�t��S)z6The default prefix for temporary directories as bytes.)rrIr	r$r$r$r%r�scCs2tdkr.t��ztdkr t�aW5t��XtS)zAccessor for tempfile.tempdir.N)r
r�r�r�r�r$r$r$r%r�s

cCst�t��S)z)A bytes version of tempfile.gettempdir().)rrIrr$r$r$r%r
�scCs2t|||�\}}}}|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.
    )rN�_text_openflagsrxr�)rKrJrL�textrMr�r$r$r%r�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�rfz(No usable temporary directory name foundN)rNr�r9r�rrIr_rrwrrrr��mkdirr{r|r!r}r~rr�r�)rKrJrLrMr r�r!r�r$r$r%r�s,
��r]cCs`|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)rr�r_rrwrrrrCr{r�r�)rKrJrLr r�r!r�r$r$r%rs
�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||_||_||_dSr4)r�r!�delete�rTr�r!r�r$r$r%�__init__)sz_TemporaryFileCloser.__init__rfcCs<|js8|jdk	r8d|_z|j��W5|jr6||j�XdS�NT)�close_calledr�r�r!r,)rTrr$r$r%r,8sz_TemporaryFileCloser.closecCs|��dSr4)r,rVr$r$r%�__del__Bsz_TemporaryFileCloser.__del__cCs|jsd|_|j��dSr�)r�r�r,rVr$r$r%r,Fs)T)rarbrcrdr�r�r�rr!rr,r�r$r$r$r%r�!s



r�c@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|||�|_dSr4)r�r!r�r��_closerr�r$r$r%r�Tsz_TemporaryFileWrapper.__init__cs^|jd}t||�}t|d�rD|�t����fdd��}|j|_|}t|t�sZt|||�|S)Nr��__call__cs
�||�Sr4r$)r6�kwargs��funcr$r%�func_wrapperbsz7_TemporaryFileWrapper.__getattr__.<locals>.func_wrapper)	�__dict__rR�hasattr�
_functools�wrapsr�r8�int�setattr)rTr!r��ar�r$r�r%�__getattr__Zs



z!_TemporaryFileWrapper.__getattr__cCs|j��|Sr4)r��	__enter__rVr$r$r%r�os
z_TemporaryFileWrapper.__enter__cCs|j�|||�}|��|Sr4)r��__exit__r,)rT�exc�value�tb�resultr$r$r%r�usz_TemporaryFileWrapper.__exit__cCs|j��dS)zA
        Close the temporary file, possibly deleting it.
        N)r�r,rVr$r$r%r,zsz_TemporaryFileWrapper.closeccs|jD]
}|VqdSr4)r�)rT�liner$r$r%rW�s
z_TemporaryFileWrapper.__iter__N)T)
rarbrcrdr�r�r�r�r,rWr$r$r$r%r�Ls
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.
    rf��	buffering�newline�encodingr�N)rNrxrr!ZO_TEMPORARYr�ryr*r��
BaseExceptionrr,)r#r�r�r�rKrJrLr�r�rMr�r=r!r�r$r$r%r�s 

�

�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.
        rsFr�N)
rNrx�_O_TMPFILE_WORKSrr��O_CREATr*�IsADirectoryErrorrryr,r�r)
r#r�r�r�rKrJrLr�rMr�Zflags2r=r!r$r$r%r�s<
�


�
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�rKrJr�r�rLr�)ry�BytesIO�_file�
TextIOWrapper�	_max_size�_rolled�_TemporaryFileArgs)
rT�max_sizer#r�r�r�rKrJrLr�r$r$r%r�s"
��zSpooledTemporaryFile.__init__cCs,|jr
dS|j}|r(|��|kr(|��dSr4)r�r��tell�rollover)rTr�r�r$r$r%�_checks
zSpooledTemporaryFile._checkcCsr|jr
dS|j}tf|j�}|_|`|��}t|d�rN|j�|���	��n|�|�	��|�
|d�d|_dS)N�bufferrT)r�r�rr�r�r�r�rz�detach�getvalue�seek)rTr�Znewfile�posr$r$r%r�s
zSpooledTemporaryFile.rollovercCs|jjrtd��|S)Nz%Cannot enter context with closed file)r��closed�
ValueErrorrVr$r$r%r�+szSpooledTemporaryFile.__enter__cCs|j��dSr4�r�r,�rTr�r�r�r$r$r%r�0szSpooledTemporaryFile.__exit__cCs
|j��Sr4)r�rWrVr$r$r%rW4szSpooledTemporaryFile.__iter__cCs|j��dSr4r�rVr$r$r%r,7szSpooledTemporaryFile.closecCs|jjSr4)r�r�rVr$r$r%r�:szSpooledTemporaryFile.closedcCs|jjSr4)r�r�rVr$r$r%r�>szSpooledTemporaryFile.encodingcCs|jjSr4)r�r�rVr$r$r%r�BszSpooledTemporaryFile.errorscCs|��|j��Sr4)r�r��filenorVr$r$r%r�FszSpooledTemporaryFile.filenocCs|j��dSr4)r��flushrVr$r$r%r�JszSpooledTemporaryFile.flushcCs
|j��Sr4)r��isattyrVr$r$r%r�MszSpooledTemporaryFile.isattycCs.z
|jjWStk
r(|jdYSXdS)Nr#)r�r#rmr�rVr$r$r%r#Ps
zSpooledTemporaryFile.modecCs&z
|jjWStk
r YdSXdSr4)r�r!rmrVr$r$r%r!Ws
zSpooledTemporaryFile.namecCs|jjSr4)r��newlinesrVr$r$r%r�^szSpooledTemporaryFile.newlinescGs|jj|�Sr4)r��read�rTr6r$r$r%r�bszSpooledTemporaryFile.readcGs|jj|�Sr4)r��readliner�r$r$r%r�eszSpooledTemporaryFile.readlinecGs|jj|�Sr4)r��	readlinesr�r$r$r%r�hszSpooledTemporaryFile.readlinescGs|jj|�Sr4)r�r�r�r$r$r%r�kszSpooledTemporaryFile.seekcCs|jjSr4)r��	softspacerVr$r$r%r�nszSpooledTemporaryFile.softspacecCs
|j��Sr4)r�r�rVr$r$r%r�rszSpooledTemporaryFile.tellcCs6|dkr|j��n||jkr&|��|j�|�dSr4)r��truncater�r�)rT�sizer$r$r%r�us

zSpooledTemporaryFile.truncatecCs|j}|�|�}|�|�|Sr4)r�rzr�)rT�sr��rvr$r$r%rz}s

zSpooledTemporaryFile.writecCs|j}|�|�}|�|�|Sr4)r��
writelinesr�)rT�iterabler�r�r$r$r%r��s

zSpooledTemporaryFile.writelines)rr�r�NNNNN)N)rarbrcrdr�r�r�r�r�r�rWr,rer�r�r�r�r�r�r#r!r�r�r�r�r�r�r�r�rzr�r$r$r$r%r�sT��







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)rr!�_weakrefZfinalize�_cleanup�format�
_finalizer)rTrKrJrLr$r$r%r��s�zTemporaryDirectory.__init__cs��fdd�}t�|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)Nrr�)rZchflagsrm�chmod)rr$r$r%�
resetperms�s
z?TemporaryDirectory._rmtree.<locals>.onerror.<locals>.resetperms)	�
issubclassr|rrrprr�r>r�)r�rrr���clsr!r$r%r�sz+TemporaryDirectory._rmtree.<locals>.onerror)r)r>)r�r!rr$r�r%r>�szTemporaryDirectory._rmtreecCs|�|�t�|t�dSr4)r>�	_warnings�warn�ResourceWarning)r�r!r�r$r$r%r��s
zTemporaryDirectory._cleanupcCsd�|jj|j�S)Nz	<{} {!r}>)r��	__class__rar!rVr$r$r%�__repr__�szTemporaryDirectory.__repr__cCs|jSr4)r!rVr$r$r%r��szTemporaryDirectory.__enter__cCs|��dSr4)�cleanupr�r$r$r%r��szTemporaryDirectory.__exit__cCs|j��r|�|j�dSr4)r�r�r>r!rVr$r$r%r��s
zTemporaryDirectory.cleanup)NNN)rarbrcrdr��classmethodr>r�r�r�r�r�r$r$r$r%r�s


)FN)NNNF)NNN)r�r�NNNNNT)r�r�NNNNN)Mrd�__all__�	functoolsr��warningsr��iory�osrZshutilZ_shutilZrmtreer>�ImportError�sysrr)rrr/r*rr�supports_dir_fdr�supports_fd�supports_follow_symlinksr7�errnor�Zrandomr?rS�weakrefr��_thread�
allocate_lockZ_allocate_lock�O_RDWRr��O_EXCLr�r�r@rxrArrHr�rCrGrNrOrqr�r�r�r�r	rr
rr
rrrr�r�rr!�platformrr�r�objectrr$r$r$r%�<module>s��

!,�
�
�3

	-
'
( +?��'
��<

Zerion Mini Shell 1.0