a �DOg;m�@s�gd�ZddlZddlZddlZddlZddl Z ddl Z ddl mZddlZddlZddlZddlZejZejejBejBZeed�r�eejOZeZeed�r�eej OZeed�r�ej!Z!ndZ!dZ"e�Z#d d �Z$d d �Z%d d�Z&Gdd�d�Z'dd�Z(dd�Z)da*dd�Z+dd�Z,dd�Z-dd�Z.dd�Z/dd �Z0da1d!d"�Z2d#d$�Z3d@d&d'�Z4dAd(d)�Z5d*e"dfd+d,�Z6Gd-d.�d.�Z7Gd/d0�d0�Z8dBdd4�d5d6�Z9ej:d7k�s�ej;d8k�r�e9ZGd>d?�d?e?�Z@dS)D) �NamedTemporaryFile� TemporaryFile�SpooledTemporaryFile�TemporaryDirectory�mkstemp�mkdtemp�mktemp�TMP_MAX� gettempprefix�tempdir� gettempdir�gettempprefixb� gettempdirb�N)�Random� O_NOFOLLOW�O_BINARYri'�tmpcCs,zt�|�Wnty"YdS0dSdS)NFT)�_os�lstat�OSError)�fn�r� /usr/lib64/python3.9/tempfile.py�_existsLs  rcGsrd}|D]X}|durqt|tj�r,t�|�}t|t�rL|turFtd��t}q|tur\td��t}q|durntS|S)Nz1Can't mix bytes and non-bytes in path components.)� isinstancer�PathLike�fspath�bytes�str� TypeError)�args� return_type�argrrr�_infer_return_typeUs    r#cCsdt|||�}|dur|�}|dur:|tur0t}n t�t�}|durX|turRt�}nt�}||||fS�N)r#r�templater�fsencoder r )�prefix�suffix�dir� output_typerrr�_sanitize_paramsns  r+c@s,eZdZdZedd��Zdd�Zdd�ZdS) �_RandomNameSequence�%abcdefghijklmnopqrstuvwxyz0123456789_cCs,t��}|t|dd�kr&t�|_||_|jS)N�_rng_pid)r�getpid�getattr�_Random�_rngr.)�self�cur_pidrrr�rng�s z_RandomNameSequence.rngcCs|Sr$r�r3rrr�__iter__�sz_RandomNameSequence.__iter__cs0|j�|jj���fdd�td�D�}d�|�S)Ncsg|] }����qSrr)�.0�dummy��c�chooserr� ��z0_RandomNameSequence.__next__..��)� charactersr5�choice�range�join)r3�lettersrr:r�__next__�sz_RandomNameSequence.__next__N)�__name__� __module__� __qualname__rA�propertyr5r7rFrrrrr,�s  r,c Cs�g}dD]}t�|�}|r|�|�qtjdkrX|�tj�d�tj�d�ddddg�n|�gd ��z|�t���Wn"t t fy�|�tj �Yn0|S) N)�TMPDIR�TEMP�TMP�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)�dirlist�envname�dirnamerrr�_candidate_tempdir_list�s   �r\c Csht�}t�}|D�]@}|tjkr,tj�|�}td�D�]}t|�}tj�||�}z�t� |t d�}zdzHt j |ddd��}|� d�Wd�n1s�0YWt� |�n t� |�0Wt�|�n t�|�0|WSty�Yq4t�y6tjdk�r,tj�|��r,t�|tj��r,Yq4YqYq4t�yNYqYq40q4qttjd|��dS) N�d��wbF)�closefdsblatrNz)No usable temporary directory found in %s)r,r\rrXrS�abspathrC�nextrD�open�_bin_openflags�_io�write�close�unlink�FileExistsError�PermissionErrorrQ�isdir�access�W_OKr�FileNotFoundError�_errno�ENOENT)�namerrYr)�seqrQ�filename�fd�fprrr�_get_default_tempdir�s@    *  � ��rvcCs:tdur6t��ztdur t�aWt��n t��0tSr$)�_name_sequence� _once_lock�acquirer,�releaserrrr�_get_candidate_names�sr{c Cs�t�}|turttj|�}tt�D]�}t|�}tj� ||||�}t � d|�zt� ||d�} WnRt yxYq"Yn>ty�tjdkr�tj�|�r�t�|tj�r�Yq"n�Yn0| tj�|�fSt tjd��dS)Nztempfile.mkstempr^rNz#No usable temporary file name found)r{r�maprr&rCrrbrSrD�_sys�auditrcrirjrQrkrlrmraro�EEXIST) r)�pre�suf�flagsr*�namesrrrQ�filertrrr�_mkstemp_inner�s*      ��r�cGsL|tjvr"||g|�Rddi�n&tjdks8tj�|�sH||g|�R�dS)N�follow_symlinksFrN)r�supports_follow_symlinksrQrS�islink)�funcrSr rrr�_dont_follow_symlinkss r�cCs<z tj}WntyYn0t||d�ttj|d�dS)Nr��)r�chflagsrWr��chmod)rSr�rrr� _resetpermss    r�cCstSr$)r%rrrrr "sr cCs t�t��Sr$)rr&r rrrrr &sr cCs:tdur6t��ztdur t�aWt��n t��0tSr$)r rxryrvrzrrrrr ,sr cCs t�t��Sr$)rr&r rrrrr 8sr FcCs2t|||�\}}}}|rt}nt}t|||||�Sr$)r+�_text_openflagsrdr�)r(r'r)�textr*r�rrrr<s rc Cs�t|||�\}}}}t�}|tur.ttj|�}tt�D]�}t|�}tj � ||||�}t � d|�zt� |d�WnRty�Yq6Yn>ty�tjdkr�tj �|�r�t�|tj�r�Yq6n�Yn0|Sttjd��dS)Nztempfile.mkdtempr�rNz(No usable temporary directory name found)r+r{rr|rr&rCrrbrSrDr}r~�mkdirrirjrQrkrlrmror)r(r'r)r*r�rrrQr�rrrrcs,       ��rr@cCs`|durt�}t�}tt�D]2}t|�}tj�||||�}t|�s|Sqt t j d��dS)Nz"No usable temporary filename found) r r{rCrrbrrSrDrriror)r(r'r)r�rrrQr�rrrr�s  �rc@sHeZdZdZdZd dd�ZejdkreZdZddd�Zdd�Zdd�Zdd �Zd d �Zd d �ZdS)�_TemporaryFileWrapperTcCs$||_||_||_t|||�|_dSr$)r�rQr�r��_closerr�rrrr��sz_TemporaryFileWrapper.__init__cs^|jd}t||�}t|d�rD|�t����fdd��}|j|_|}t|t�sZt|||�|S)Nr��__call__cs�|i|��Sr$r)r �kwargs�r�rr� func_wrapper�sz7_TemporaryFileWrapper.__getattr__..func_wrapper) �__dict__r0�hasattr� _functools�wrapsr�r�int�setattr)r3rQr��ar�rr�r� __getattr__�s     z!_TemporaryFileWrapper.__getattr__cCs|j��|Sr$)r�� __enter__r6rrrr��s z_TemporaryFileWrapper.__enter__cCs|j�|||�}|��|Sr$)r��__exit__rg)r3�exc�value�tb�resultrrrr��sz_TemporaryFileWrapper.__exit__cCs|j��dSr$)r�rgr6rrrrgsz_TemporaryFileWrapper.closeccs|jD] }|VqdSr$)r�)r3�linerrrr7 s z_TemporaryFileWrapper.__iter__N)T) rGrHrIr�r�r�r�rgr7rrrrr��s  r��w+b�����T��errorscCs�t|||�\}}}} t} tjdkr0|r0| tjO} t|||| | �\} } z$tj| |||||d�} t| | |�WSt y�t� | �t� | ��Yn0dS)NrN�� buffering�newline�encodingr�) r+rdrrQ� O_TEMPORARYr�rercr�� BaseExceptionrhrg)�moder�r�r�r(r'r)r�r�r*r�rtrQr�rrrrs  �   r�posix�cygwin� O_TMPFILEc Cs�t|||�\}}}}t} tr�z$| tjBtj@} t�|| d�} Wn&tyVdaYnDtyfYn40zt j| |||||d�WSt� | ��Yn0t |||| |�\} } z"t� | �t j| |||||d�WSt� | ��Yn0dS)Nr^Fr�) r+rd�_O_TMPFILE_WORKSrr��O_CREATrc�IsADirectoryErrorrrergr�rh) r�r�r�r�r(r'r)r�r*r��flags2rtrQrrrrGs6   �   � rc@s�eZdZdZd7dd�dd�Zeej�Zd d �Z d d �Z d d�Z dd�Z dd�Z dd�Zedd��Zedd��Zedd��Zdd�Zdd�Zdd �Zed!d"��Zed#d$��Zed%d&��Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd8d1d2�Zd3d4�Zd5d6�Z dS)9rFrr�r�Nr�c  CsTd|vrt��|_ntjt��|| |d�|_||_d|_|||||||| d�|_dS)N�b)r�r�r�F)r�r�r(r'r�r�r)r�)re�BytesIO�_file� TextIOWrapper� _max_size�_rolled�_TemporaryFileArgs) r3�max_sizer�r�r�r�r(r'r)r�rrrr��s  ��zSpooledTemporaryFile.__init__cCs,|jr dS|j}|r(|��|kr(|��dSr$)r�r��tell�rollover)r3r�r�rrr�_check�s zSpooledTemporaryFile._checkcCsv|jr dS|j}tfi|j��}|_|`|��}t|d�rR|j�|��� ��n|�|� ��|� |d�d|_dS)N�bufferrT) r�r�rr�r�r�r�rf�detach�getvalue�seek)r3r��newfile�posrrrr��s   zSpooledTemporaryFile.rollovercCs|jjrtd��|S)Nz%Cannot enter context with closed file)r��closed� ValueErrorr6rrrr��szSpooledTemporaryFile.__enter__cCs|j��dSr$�r�rg�r3r�r�r�rrrr��szSpooledTemporaryFile.__exit__cCs |j��Sr$)r�r7r6rrrr7�szSpooledTemporaryFile.__iter__cCs|j��dSr$r�r6rrrrg�szSpooledTemporaryFile.closecCs|jjSr$)r�r�r6rrrr��szSpooledTemporaryFile.closedcCs|jjSr$)r�r�r6rrrr��szSpooledTemporaryFile.encodingcCs|jjSr$)r�r�r6rrrr��szSpooledTemporaryFile.errorscCs|��|j��Sr$)r�r��filenor6rrrr��szSpooledTemporaryFile.filenocCs|j��dSr$)r��flushr6rrrr��szSpooledTemporaryFile.flushcCs |j��Sr$)r��isattyr6rrrr��szSpooledTemporaryFile.isattycCs,z |jjWSty&|jdYS0dS)Nr�)r�r�rWr�r6rrrr��s  zSpooledTemporaryFile.modecCs$z |jjWStyYdS0dSr$)r�rQrWr6rrrrQ�s  zSpooledTemporaryFile.namecCs|jjSr$)r��newlinesr6rrrr��szSpooledTemporaryFile.newlinescGs |jj|�Sr$)r��read�r3r rrrr��szSpooledTemporaryFile.readcGs |jj|�Sr$)r��readliner�rrrr��szSpooledTemporaryFile.readlinecGs |jj|�Sr$)r�� readlinesr�rrrr��szSpooledTemporaryFile.readlinescGs |jj|�Sr$)r�r�r�rrrr��szSpooledTemporaryFile.seekcCs |j��Sr$)r�r�r6rrrr��szSpooledTemporaryFile.tellcCs6|dur|j��n||jkr&|��|j�|�dSr$)r��truncater�r�)r3�sizerrrr��s   zSpooledTemporaryFile.truncatecCs|j}|�|�}|�|�|Sr$)r�rfr�)r3�sr��rvrrrrfs  zSpooledTemporaryFile.writecCs|j}|�|�}|�|�|Sr$)r�� writelinesr�)r3�iterabler�r�rrrr� s  zSpooledTemporaryFile.writelines)rr�r�NNNNN)N)!rGrHrIr�r�� classmethod�_types� GenericAlias�__class_getitem__r�r�r�r�r7rgrJr�r�r�r�r�r�r�rQr�r�r�r�r�r�r�rfr�rrrrr�sJ��         rc@sXeZdZddd�Zedd��Zedd��Zdd �Zd d �Zd d �Z dd�Z ee j �Z dS)rNcCs0t|||�|_tj||j|jd�|�d�|_dS)NzImplicitly cleaning up {!r})� warn_message)rrQ�_weakref�finalize�_cleanup�format� _finalizer)r3r(r'r)rrrr�s  �zTemporaryDirectory.__init__cs ��fdd�}tj�|d�dS)Nc s�t|dt�rxzT|�kr(ttj�|��t|�zt�|�Wn ttfy^��|�Yn0Wq�t ytYq�0nt|dt �r�n�dS)Nr) � issubclassrjr�rrSr[rhr��_rmtreern)r�rS�exc_info��clsrQrr�onerror&s z+TemporaryDirectory._rmtree..onerror)r�)�_shutil�rmtree)r�rQr�rr�rr�$szTemporaryDirectory._rmtreecCs|�|�t�|t�dSr$)r�� _warnings�warn�ResourceWarning)r�rQr�rrrr�;s zTemporaryDirectory._cleanupcCsd�|jj|j�S)Nz <{} {!r}>)r�� __class__rGrQr6rrr�__repr__@szTemporaryDirectory.__repr__cCs|jSr$)rQr6rrrr�CszTemporaryDirectory.__enter__cCs |��dSr$)�cleanupr�rrrr�FszTemporaryDirectory.__exit__cCs|j��r|�|j�dSr$)r�r�r�rQr6rrrr�Is zTemporaryDirectory.cleanup)NNN)rGrHrIr�r�r�r�r�r�r�r�r�r�r�rrrrrs   r)NNNF)NNN)r�r�NNNNNT)r�r�NNNNN)A�__all__� functoolsr��warningsr��iore�osr�shutilr��errnoro�randomrr1�sysr}�typesr��weakrefr��_thread� allocate_lock�_allocate_lock�O_RDWRr��O_EXCLr�r�rrdrrr%rxrr#r+r,r\rvrwr{r�r�r�r r r r r rrrr�r�rrQ�platformrr�r�objectrrrrr�s|        -   ' ( +?�� ' �� <