Spade

Mini Shell

Directory:~$ /proc/self/root/usr/lib64/python3.6/__pycache__/
Upload File

[Home] [System Details] [Kill Me]
Current File:~$ //proc/self/root/usr/lib64/python3.6/__pycache__/tempfile.cpython-36.opt-1.pyc

3

k��h�m�@sBdZddddddddd	d
ddd
g
ZddlZddlZddlZddlZ	ddl
ZddlZ
ddlmZddlZyddlZWnek
r�ddlZYnXejZe	je	jBe	jBZee	d�r�ee	jOZeZee	d�r�ee	jOZee	d�r�e	j
Z ndZ
dZ!e�Z"ee	d��re	j#Z$nee	d��re	j%Z$ndd�Z$dd�Z&dd�Z'dd�Z(Gdd
�d
�Z)d!d"�Z*d#d$�Z+da,d%d&�Z-d'd(�Z.d)d*�Z/d+d,�Z0d-d	�Z1d.d�Z2da3d/d�Z4d0d
�Z5dDd2d�Z6dEd3d�Z7d4e!dfd5d�Z8Gd6d7�d7�Z9Gd8d9�d9�Z:dGd=d�Z;e	j<d>k�se	j=j>d?k�re;Z?nee	d@�a@dIdAd�Z?GdBd�d�ZAGdCd�deB�ZCdS)Ja�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'Ztmp�lstat�statcCstj|tj�}tj|�dS)N)�_os�open�O_RDONLY�close)�fn�fd�r�
/usr/lib64/python3.6/tempfile.py�_statTsrcCs*yt|�Wntk
r dSXdSdS)NFT)r�OSError)rrrr�_existsXs
rcGs`d}xJ|D]B}|dkrq
t|t�r8|tkr2td��t}q
|tkrHtd��t}q
W|dkr\tS|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_typeas

r%cCsdt|||�}|dkr|�}|dkr:|tkr0t}n
tjt�}|dkrX|tkrRt�}nt�}||||fS)z9Common parameter
processing for most APIs in this
module.N)r%r!�templater�fsencoderr
)�prefix�suffix�dir�output_typerrr�_sanitize_paramsvs
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,tj�}|t|dd�kr&t�|_||_|jS)N�_rng_pid)r�getpid�getattr�_RandomZ_rngr.)�selfZcur_pidrrr�rng�s
z_RandomNameSequence.rngcCs|S)Nr)r2rrr�__iter__�sz_RandomNameSequence.__iter__cs0|j�|jj���fdd�td�D�}dj|�S)Ncsg|]}����qSrr)�.0Zdummy)�c�chooserr�
<listcomp>�sz0_RandomNameSequence.__next__.<locals>.<listcomp>��)�
charactersr3Zchoice�range�join)r2Zlettersr)r6r7r�__next__�sz_RandomNameSequence.__next__N)	�__name__�
__module__�__qualname__�__doc__r;�propertyr3r4r>rrrrr-�s
r-cCs�g}x$dD]}tj|�}|r
|j|�q
Wtjdkr\|jtjjd�tjjd�ddd	d
g�n|jddd
g�y|jtj��Wn$t	t
fk
r�|jtj�YnX|S)z[Generate a list of candidate temporary
directories which
    _get_default_tempdir will
try.�TMPDIR�TEMP�TMP�ntz~\AppData\Local\Tempz%SYSTEMROOT%\Tempzc:\tempzc:\tmpz\tempz\tmpz/tmpz/var/tmpz/usr/tmp)rDrErF)r�getenv�append�name�extend�path�
expanduser�
expandvars�getcwd�AttributeErrorr�curdir)�dirlistZenvname�dirnamerrr�_candidate_tempdir_list�s



rTcCs4t�}t�}�x|D�]}|tjkr0tjj|�}x�td�D]�}t|�}tjj||�}y\tj	|t
d�}z<z*tj	|ddd��}|jd�WdQRXWdtj
|�XWdtj|�X|Stk
r�Yq:tk
�rtjdkr�tjj|�r�tj|tj�r�w:PYq:tk
�rPYq:Xq:WqWttjd	|��dS)
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.�di��wbF)�closefdsblatNrGz)No usable temporary
directory found in
%s)r-rTrrQrL�abspathr<�nextr=r�_bin_openflags�_io�writer�unlink�FileExistsError�PermissionErrorrJ�isdir�access�W_OKr�FileNotFoundError�_errno�ENOENT)ZnamerrRr*�seqrJ�filenamer�fprrr�_get_default_tempdir�s:	
ric
Cs2tdkr.tj�ztdkr t�aWdtj�XtS)z7Common setup sequence
for all user-callable interfaces.N)�_name_sequence�
_once_lock�acquirer-�releaserrrr�_get_candidate_names�s

rnc
Cs�t�}|tkrttj|�}x�tt�D]�}t|�}tjj	||||�}ytj
||d�}	WnRtk
rnw$Yn>tk
r�tj
dkr�tjj|�r�tj|tj�r�w$n�YnX|	tjj|�fSWttjd��dS)z>Code
common to mkstemp, TemporaryFile, and NamedTemporaryFile.i�rGz#No usable
temporary file name foundN)rnr
�maprr'r<rrYrLr=rr^r_rJr`rarbrXrd�EEXIST)
r*ZpreZsuf�flagsr+�namesrfrJ�filerrrr�_mkstemp_inner�s$rtcGsJ|tjkr
||f|�ddi�n&tjdks8tjj|�rF||f|��dS)N�follow_symlinksFrG)r�supports_follow_symlinksrJrL�islink)�funcrLr#rrr�_dont_follow_symlinkss
rycCs>y
tj}Wntk
rYnXt||d�ttj|d�dS)Nri�)r�chflagsrPry�chmod)rLrzrrr�_resetpermss
r|cCstS)z-The default prefix for temporary
directories.)r&rrrrr	*scCstjt��S)z6The default prefix
for temporary directories as bytes.)rr'r	rrrrr.sc
Cs2tdkr.tj�ztdkr t�aWdtj�XtS)zAccessor for
tempfile.tempdir.N)r
rkrlrirmrrrrr4s

cCstjt��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.  On
    some operating systems, this makes no difference.

    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_openflagsrZrt)r)r(r*�textr+rqrrrrDs
cCs�t|||�\}}}}t�}|tkr.ttj|�}x�tt�D]�}t|�}tj	j
||||�}ytj|d�WnRtk
r�w8Yn>t
k
r�tjdkr�tj	j|�r�tj|tj�r�w8n�YnX|SWttjd��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.
    i�rGz(No usable temporary directory name foundN)r,rnr
rorr'r<rrYrLr=�mkdirr^r_rJr`rarbrdrp)r)r(r*r+rrrfrJrsrrrrls&
r:cCs`|dkrt�}t�}x:tt�D].}t|�}tjj||||�}t|�s|SqWt	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)rrnr<rrYrrLr=rr^rdrp)r)r(r*rrrfrJrsrrrr�sc@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||_||_||_dS)N)rsrJ�delete)r2rsrJr�rrr�__init__�sz_TemporaryFileCloser.__init__rGcCs>|jr:|jdk	r:d|_z|jj�Wd|jr8||j�XdS)NT)�close_calledrsrr�rJ)r2r]rrrr�sz_TemporaryFileCloser.closecCs|j�dS)N)r)r2rrr�__del__�sz_TemporaryFileCloser.__del__cCs|jsd|_|jj�dS)NT)r�rsr)r2rrrr�s)T)r?r@rArBrsr�r�rrJr]rr�rrrrr��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|||�|_dS)N)rsrJr�r��_closer)r2rsrJr�rrrr��sz_TemporaryFileWrapper.__init__cs^|jd}t||�}t|d�rD|�tj���fdd��}|j|_|}t|t�sZt|||�|S)Nrs�__call__cs
�||�S)Nr)r#�kwargs)rxrr�func_wrapper�sz7_TemporaryFileWrapper.__getattr__.<locals>.func_wrapper)	�__dict__r0�hasattr�
_functools�wrapsr�r�int�setattr)r2rJrs�ar�r)rxr�__getattr__�s



z!_TemporaryFileWrapper.__getattr__cCs|jj�|S)N)rs�	__enter__)r2rrrr�s
z_TemporaryFileWrapper.__enter__cCs|jj|||�}|j�|S)N)rs�__exit__r)r2�exc�value�tb�resultrrrr�sz_TemporaryFileWrapper.__exit__cCs|jj�dS)zA
        Close the temporary file, possibly deleting it.
       
N)r�r)r2rrrrsz_TemporaryFileWrapper.closeccsx|jD]
}|VqWdS)N)rs)r2�linerrrr4sz_TemporaryFileWrapper.__iter__N)T)
r?r@rArBr�r�r�r�rr4rrrrr��s
r��w+b�Tc

Cs�t|||�\}}}}t}	tjdkr0|r0|	tjO}	t||||	|�\}
}y tj|
||||d�}t|||�St	k
r�tj
|�tj|
��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).
    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.
   
rG)�	buffering�newline�encodingN)r,rZrrJZO_TEMPORARYrtr[rr��
BaseExceptionr]r)
�moder�r�r�r)r(r*r�r+rqrrJrsrrrrs




�posix�cygwin�	O_TMPFILEcCs�t|||�\}}}}t}tr�y$|tjBtj@}	tj||	d�}
Wn*tk
rXdaYnBtk
rjYn0Xyt	j|
||||d�Stj
|
��YnXt|||||�\}
}ytj|�t	j|
||||d�Stj
|
��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)
        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.
       
i�F)r�r�r�N)
r,rZ�_O_TMPFILE_WORKSrr��O_CREATr�IsADirectoryErrorrr[rrtr])r�r�r�r�r)r(r*r+rqZflags2rrJrrrrNs0






c@s�eZdZdZdZd8dd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�Zedd��Z
edd��Zdd�Zdd�Zdd�Zedd
��Zed!d"��Zed#d$��Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zed-d.��Zd/d0�Zd9d1d2�Zd3d4�Zd5d6�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.
   
Fr�w+br�Nc		CsHd|krtj�|_ntjdd�|_||_d|_|||||||d�|_dS)N�b�
)r�F)r�r�r)r(r�r�r*)r[�BytesIO�_file�StringIO�	_max_size�_rolled�_TemporaryFileArgs)	r2�max_sizer�r�r�r�r)r(r*rrrr��szSpooledTemporaryFile.__init__cCs,|jr
dS|j}|r(|j�|kr(|j�dS)N)r�r��tell�rollover)r2rsr�rrr�_check�s
zSpooledTemporaryFile._checkcCsN|jr
dS|j}tf|j�}|_|`|j|j��|j|j�d�d|_dS)NrT)r�r�rr�r\�getvalue�seekr�)r2rsZnewfilerrrr��szSpooledTemporaryFile.rollovercCs|jjrtd��|S)Nz%Cannot
enter context with closed file)r��closed�
ValueError)r2rrrr��szSpooledTemporaryFile.__enter__cCs|jj�dS)N)r�r)r2r�r�r�rrrr��szSpooledTemporaryFile.__exit__cCs
|jj�S)N)r�r4)r2rrrr4�szSpooledTemporaryFile.__iter__cCs|jj�dS)N)r�r)r2rrrr�szSpooledTemporaryFile.closecCs|jjS)N)r�r�)r2rrrr��szSpooledTemporaryFile.closedcCs8y|jjStk
r2d|jdkr(�|jdSXdS)Nr�r�r�)r�r�rPr�)r2rrrr��szSpooledTemporaryFile.encodingcCs|j�|jj�S)N)r�r��fileno)r2rrrr��szSpooledTemporaryFile.filenocCs|jj�dS)N)r��flush)r2rrrr��szSpooledTemporaryFile.flushcCs
|jj�S)N)r��isatty)r2rrrr��szSpooledTemporaryFile.isattycCs(y|jjStk
r"|jdSXdS)Nr�)r�r�rPr�)r2rrrr��szSpooledTemporaryFile.modecCs"y|jjStk
rdSXdS)N)r�rJrP)r2rrrrJ�szSpooledTemporaryFile.namecCs8y|jjStk
r2d|jdkr(�|jdSXdS)Nr�r�r�)r��newlinesrPr�)r2rrrr��szSpooledTemporaryFile.newlinescGs|jj|�S)N)r��read)r2r#rrrr��szSpooledTemporaryFile.readcGs|jj|�S)N)r��readline)r2r#rrrr��szSpooledTemporaryFile.readlinecGs|jj|�S)N)r��	readlines)r2r#rrrr��szSpooledTemporaryFile.readlinescGs|jj|�dS)N)r�r�)r2r#rrrr��szSpooledTemporaryFile.seekcCs|jjS)N)r��	softspace)r2rrrr�szSpooledTemporaryFile.softspacecCs
|jj�S)N)r�r�)r2rrrr�szSpooledTemporaryFile.tellcCs6|dkr|jj�n||jkr&|j�|jj|�dS)N)r��truncater�r�)r2�sizerrrr�s

zSpooledTemporaryFile.truncatecCs|j}|j|�}|j|�|S)N)r�r\r�)r2�srs�rvrrrr\s

zSpooledTemporaryFile.writecCs|j}|j|�}|j|�|S)N)r��
writelinesr�)r2�iterablersr�rrrr�s

zSpooledTemporaryFile.writelines���)rr�r�NNNNN)N)r?r@rArBr�r�r�r�r�r�r4rrCr�r�r�r�r�r�rJr�r�r�r�r�r�r�r�r\r�rrrrr�s8
		
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|jdj|�d�|_dS)NzImplicitly
cleaning up
{!r})�warn_message)rrJ�_weakref�finalize�_cleanup�format�
_finalizer)r2r)r(r*rrrr�(s
zTemporaryDirectory.__init__cs
��fdd�}tj�|d�dS)Ncs�t|dt�r|yV|�kr(ttjj|��t|�ytj|�Wn"ttfk
r`�j|�YnXWq�t	k
rxYq�Xnt|dt	�r�n�dS)Nr)
�
issubclassr_r|rrLrSr]r��_rmtreerc)rxrL�exc_info)�clsrJrr�onerror0sz+TemporaryDirectory._rmtree.<locals>.onerror)r�)�_shutilZrmtree)r�rJr�r)r�rJrr�.szTemporaryDirectory._rmtreecCs|j|�tj|t�dS)N)r��	_warnings�warn�ResourceWarning)r�rJr�rrrr�Es
zTemporaryDirectory._cleanupcCsdj|jj|j�S)Nz	<{}
{!r}>)r��	__class__r?rJ)r2rrr�__repr__JszTemporaryDirectory.__repr__cCs|jS)N)rJ)r2rrrr�MszTemporaryDirectory.__enter__cCs|j�dS)N)�cleanup)r2r�r�r�rrrr�PszTemporaryDirectory.__exit__cCs|jj�r|j|j�dS)N)r��detachr�rJ)r2rrrr�Ss
zTemporaryDirectory.cleanup)NNN)r?r@rArBr��classmethodr�r�r�r�r�r�rrrrrs

)NNNF)NNNr�)r�r�NNNNNTr�)r�r�NNNNN)DrB�__all__�	functoolsr��warningsr��ior[�osrZshutilr��errnordZrandomrr1�weakrefr��_thread�ImportErrorZ
_dummy_thread�
allocate_lockZ_allocate_lock�O_RDWRr��O_EXCLr}r�rrZrrr&rkrrrrr%r,r-rTrirjrnrtryr|r	rr
rr
rrrr�r�rrJ�sys�platformrr�r�objectrrrrr�<module>s�




	-
(
' +?
$

8