o
    gn                     @   s  	 g d Z ddlZddlZddlZddlZddl	Z
ddlZddlmZ ddlZddlZddlZddlZejZejejB ejB ZeedrIeejO ZeZeedrUeej O Zeedr^ej!Z!ndZ!dZ"e Z#d	d
 Z$dd Z%dd Z&G dd dZ'dd Z(dd Z)da*dd Z+dd Z,dd Z-dd Z.da/dd Z0dd  Z1d!d" Z2d>d$d%Z3d?d&d'Z4d(e"dfd)d*Z5G d+d, d,Z6G d-d. d.Z7			1d@dd2d3d4Z8ej9d5ksej:d6kre8Z;need7a<			dAdd2d8d9Z;G d:d; d;Z=G d<d= d=Z>dS )B)NamedTemporaryFileTemporaryFileSpooledTemporaryFileTemporaryDirectorymkstempmkdtempmktempTMP_MAXgettempprefixtempdir
gettempdirgettempprefixbgettempdirb    N)Random
O_NOFOLLOWO_BINARYr   i'  tmpc                 C   s&   zt |  W dS  ty   Y dS w )NFT)_oslstatOSError)fn r   >/Users/admin/.pyenv/versions/3.10.0/lib/python3.10/tempfile.py_existsL   s   r   c                  G   st   	 d }| D ]!}|d u rqt |tr|tu rtdt}q|tu r$tdt}q|d u r8td u s4t ttr6tS tS |S )Nz1Can't mix bytes and non-bytes in path components.)
isinstancebytesstr	TypeErrorr
   )argsreturn_typeargr   r   r   _infer_return_typeU   s"   
r!   c                 C   sf   	 t | ||}|d u r| }| d u r|tu rt} ntt} |d u r-|tu r*t }nt }| |||fS N)r!   r   templater   fsencoder   r   )prefixsuffixdiroutput_typer   r   r   _sanitize_paramsn   s   
r)   c                   @   s.   e Zd Z	 dZedd Zdd Zdd ZdS )	_RandomNameSequence%abcdefghijklmnopqrstuvwxyz0123456789_c                 C   s,   t  }|t| dd krt | _|| _| jS )N_rng_pid)r   getpidgetattr_Random_rngr,   )selfcur_pidr   r   r   rng   s
   z_RandomNameSequence.rngc                 C   s   | S r"   r   r1   r   r   r   __iter__   s   z_RandomNameSequence.__iter__c                 C   s   d | jj| jddS )N    )k)joinr3   choices
charactersr4   r   r   r   __next__   s   z_RandomNameSequence.__next__N)__name__
__module____qualname__r;   propertyr3   r5   r<   r   r   r   r   r*      s    
r*   c               	   C   s   	 g } dD ]}t |}|r| | qt jdkr-| t jdt jdddddg n| g d	 z
| t   W | S  t	t
fyP   | t j Y | S w )
N)TMPDIRTEMPTMPntz~\AppData\Local\Tempz%SYSTEMROOT%\Tempzc:\tempzc:\tmpz\tempz\tmp)z/tmpz/var/tmpz/usr/tmp)r   getenvappendnameextendpath
expanduser
expandvarsgetcwdAttributeErrorr   curdir)dirlistenvnamedirnamer   r   r   _candidate_tempdir_list   s&   


rR   c                  C   sN  	 t  } t }|D ]}|tjkrtj|}tdD ]}t| }tj||}zGt	|t
d}z2z$tj	|ddd}|d W d    n1 sIw   Y  W t| nt| w W t| nt| w |W     S  tyw   Y q ty   tjdkrtj|rt|tjrY qY  q	 ty   Y  q	w q	ttjd| )	Nd     wbF)closefds   blatrD   z)No usable temporary directory found in %s)r*   rR   r   rN   rI   abspathrangenextr9   open_bin_openflags_iowritecloseunlinkFileExistsErrorPermissionErrorrG   isdiraccessW_OKr   FileNotFoundError_errnoENOENT)namerrO   r'   seqrG   filenamefdfpr   r   r   _get_default_tempdir   sJ   
rm   c                   C   L   	 t d u r$t  zt d u rt a W t  t S W t  t S t  w t S r"   )_name_sequence
_once_lockacquirer*   releaser   r   r   r   _get_candidate_names   s   
rs   c           
   	   C   s   	 t  }|tu rttj|}ttD ]N}t|}tj	| || | }t
d| z	t||d}	W n$ ty;   Y q tyV   tjdkrUtj| rUt| tjrUY q w |	tj|f  S ttjd)Nztempfile.mkstemprT   rD   z#No usable temporary file name found)rs   r   mapr   r$   rX   r   rY   rI   r9   _sysauditrZ   r`   ra   rG   rb   rc   rd   rW   rf   EEXIST)
r'   presufflagsr(   namesri   rG   filerk   r   r   r   _mkstemp_inner   s.   r}   c                   C      	 t tS r"   )r   fsdecoder#   r   r   r   r   r	        
r	   c                   C   r~   r"   )r   r$   r#   r   r   r   r   r     r   r   c                   C   rn   r"   )r
   rp   rq   rm   rr   r   r   r   r   _gettempdir  s   
r   c                   C      	 t t S r"   )r   r   r   r   r   r   r   r   %     r   c                   C   r   r"   )r   r$   r   r   r   r   r   r   )  r   r   Fc                 C   s4   	 t || |\}} }}|rt}nt}t||| ||S r"   )r)   _text_openflagsr[   r}   )r&   r%   r'   textr(   rz   r   r   r   r   -  s   r   c              	   C   s   	 t || |\}} }}t }|tu rttj|}ttD ]F}t|}tj	
||| |  }td| zt|d W |  S  tyG   Y q tyb   tjdkratj	|rat|tjraY q w ttjd)Nztempfile.mkdtemp  rD   z(No usable temporary directory name found)r)   rs   r   rt   r   r$   rX   r   rY   rI   r9   ru   rv   mkdirr`   ra   rG   rb   rc   rd   rf   rw   )r&   r%   r'   r(   r{   ri   rG   r|   r   r   r   r   T  s0   
r   r6   c                 C   s^   	 |d u rt  }t }ttD ]}t|}tj||| |  }t|s(|  S qt	t
jd)Nz"No usable temporary filename found)r   rs   rX   r   rY   r   rI   r9   r   r`   rf   rw   )r&   r%   r'   r{   ri   rG   r|   r   r   r   r   |  s   r   c                   @   sL   e Zd Z	 dZdZdddZejdkr ejfddZ	d	d
 Z
dS dd Z	dS )_TemporaryFileCloserNFTc                 C   s   || _ || _|| _d S r"   )r|   rG   deleter1   r|   rG   r   r   r   r   __init__  s   
z_TemporaryFileCloser.__init__rD   c                 C   sX   | j s(| jd ur*d| _ z| j  W | jr|| j d S d S | jr'|| j w w d S d S NT)close_calledr|   r^   r   rG   )r1   r_   r   r   r   r^     s   
z_TemporaryFileCloser.closec                 C      |    d S r"   )r^   r4   r   r   r   __del__     z_TemporaryFileCloser.__del__c                 C   s   | j sd| _ | j  d S d S r   )r   r|   r^   r4   r   r   r   r^     s   T)r=   r>   r?   r|   r   r   r   rG   r_   r^   r   r   r   r   r   r     s    


r   c                   @   s@   e Zd Z	 dddZdd Zdd Zdd	 Zd
d Zdd ZdS )_TemporaryFileWrapperTc                 C   s$   || _ || _|| _t|||| _d S r"   )r|   rG   r   r   _closerr   r   r   r   r     s   z_TemporaryFileWrapper.__init__c                    s^   | j d }t||}t|dr"| t  fdd}| j|_|}t|ts-t| || |S )Nr|   __call__c                     s    | i |S r"   r   )r   kwargsfuncr   r   func_wrapper  s   z7_TemporaryFileWrapper.__getattr__.<locals>.func_wrapper)	__dict__r.   hasattr
_functoolswrapsr   r   intsetattr)r1   rG   r|   ar   r   r   r   __getattr__  s   



z!_TemporaryFileWrapper.__getattr__c                 C   s   | j   | S r"   )r|   	__enter__r4   r   r   r   r     s   
z_TemporaryFileWrapper.__enter__c                 C   s   | j |||}|   |S r"   )r|   __exit__r^   )r1   excvaluetbresultr   r   r   r     s   z_TemporaryFileWrapper.__exit__c                 C   s   	 | j   d S r"   )r   r^   r4   r   r   r   r^     s   z_TemporaryFileWrapper.closec                 c   s    | j D ]}|V  qd S r"   )r|   )r1   liner   r   r   r5     s   
z_TemporaryFileWrapper.__iter__Nr   )	r=   r>   r?   r   r   r   r   r^   r5   r   r   r   r   r     s    
r   w+bTerrorsc                C   s   	 t |||\}}}}	t}
tjdkr|r|
tjO }
d| vr"t|}t||||
|	\}}ztj|| ||||d}t	|||W S  t
yP   t| t|  w )NrD   b	bufferingnewlineencodingr   )r)   r[   r   rG   O_TEMPORARYr\   text_encodingr}   rZ   r   BaseExceptionr_   r^   )moder   r   r   r&   r%   r'   r   r   r(   rz   rk   rG   r|   r   r   r   r     s$   




r   posixcygwin	O_TMPFILEc                C   s   	 d| vr
t |}t|||\}}}}t}	trTz|	tjB tj @ }
t||
d}W n t	y5   daY n t
y=   Y nw zt j|| ||||dW S    t|  t||||	|\}}zt| t j|| ||||dW S    t|  )Nr   rT   Fr   )r\   r   r)   r[   _O_TMPFILE_WORKSr   r   O_CREATrZ   IsADirectoryErrorr   r^   r}   r_   )r   r   r   r   r&   r%   r'   r   r(   rz   flags2rk   rG   r   r   r   r   ;  s>   






r   c                   @   s  e Zd Z	 dZ			d7ddddZeejZd	d
 Z	dd Z
dd Zdd Zdd Zdd Zedd Zedd Zedd Zdd Zdd Zdd  Zed!d" Zed#d$ Zed%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd8d1d2Zd3d4 Zd5d6 Z dS )9r   Fr   r   r   Nr   c	          
   	   C   s^   d|v r
t  | _nt |}t jt  ||	|d| _|| _d| _||||||||	d| _d S )Nr   )r   r   r   F)r   r   r&   r%   r   r   r'   r   )r\   BytesIO_filer   TextIOWrapper	_max_size_rolled_TemporaryFileArgs)
r1   max_sizer   r   r   r   r&   r%   r'   r   r   r   r   r     s   

zSpooledTemporaryFile.__init__c                 C   s4   | j rd S | j}|r| |kr|   d S d S d S r"   )r   r   tellrollover)r1   r|   r   r   r   r   _check  s
   
zSpooledTemporaryFile._checkc                 C   sv   | j rd S | j}tdi | j }| _| `| }t|dr)|j| 	  n||	  |
|d d| _ d S )Nbufferr   Tr   )r   r   r   r   r   r   r   r]   detachgetvalueseek)r1   r|   newfileposr   r   r   r     s   


zSpooledTemporaryFile.rolloverc                 C   s   | j jrtd| S )Nz%Cannot enter context with closed file)r   closed
ValueErrorr4   r   r   r   r     s   zSpooledTemporaryFile.__enter__c                 C      | j   d S r"   r   r^   r1   r   r   r   r   r   r   r        zSpooledTemporaryFile.__exit__c                 C   
   | j  S r"   )r   r5   r4   r   r   r   r5        
zSpooledTemporaryFile.__iter__c                 C   r   r"   r   r4   r   r   r   r^     r   zSpooledTemporaryFile.closec                 C      | j jS r"   )r   r   r4   r   r   r   r        zSpooledTemporaryFile.closedc                 C   r   r"   )r   r   r4   r   r   r   r     r   zSpooledTemporaryFile.encodingc                 C   r   r"   )r   r   r4   r   r   r   r     r   zSpooledTemporaryFile.errorsc                 C   s   |    | j S r"   )r   r   filenor4   r   r   r   r     s   
zSpooledTemporaryFile.filenoc                 C   r   r"   )r   flushr4   r   r   r   r     r   zSpooledTemporaryFile.flushc                 C   r   r"   )r   isattyr4   r   r   r   r     r   zSpooledTemporaryFile.isattyc                 C   s(   z| j jW S  ty   | jd  Y S w )Nr   )r   r   rM   r   r4   r   r   r   r     s
   
zSpooledTemporaryFile.modec                 C   s    z| j jW S  ty   Y d S w r"   )r   rG   rM   r4   r   r   r   rG     s
   
zSpooledTemporaryFile.namec                 C   r   r"   )r   newlinesr4   r   r   r   r     r   zSpooledTemporaryFile.newlinesc                 G      | j j| S r"   )r   readr1   r   r   r   r   r     r   zSpooledTemporaryFile.readc                 G   r   r"   )r   readliner   r   r   r   r     r   zSpooledTemporaryFile.readlinec                 G   r   r"   )r   	readlinesr   r   r   r   r     r   zSpooledTemporaryFile.readlinesc                 G   r   r"   )r   r   r   r   r   r   r     r   zSpooledTemporaryFile.seekc                 C   r   r"   )r   r   r4   r   r   r   r     r   zSpooledTemporaryFile.tellc                 C   s8   |d u r| j   d S || jkr|   | j | d S r"   )r   truncater   r   )r1   sizer   r   r   r     s
   
zSpooledTemporaryFile.truncatec                 C      | j }||}| | |S r"   )r   r]   r   )r1   sr|   rvr   r   r   r]        

zSpooledTemporaryFile.writec                 C   r   r"   )r   
writelinesr   )r1   iterabler|   r   r   r   r   r     r   zSpooledTemporaryFile.writelines)r   r   r   NNNNNr"   )!r=   r>   r?   r   r   classmethod_typesGenericAlias__class_getitem__r   r   r   r   r5   r^   r@   r   r   r   r   r   r   r   rG   r   r   r   r   r   r   r   r]   r   r   r   r   r   r   z  sN    







r   c                   @   sb   e Zd Z	 		dddZedddZedddZd	d
 Zdd Zdd Z	dd Z
eejZdS )r   NFc                 C   s:   t |||| _|| _tj| | j| jd| | jd| _d S )NzImplicitly cleaning up {!r})warn_messageignore_errors)r   rG   _ignore_cleanup_errors_weakreffinalize_cleanupformat
_finalizer)r1   r&   r%   r'   ignore_cleanup_errorsr   r   r   r     s   
zTemporaryDirectory.__init__c                    s"    fdd}t j|d d S )Nc              	      s   t |d trEdd }z/|kr|tj| || z	t| W W d S  ttfy7    j|d Y nw W d S  tyD   Y d S w t |d trNd S sQ d S )Nr   c                 S   s4   zt | d W n	 ty   Y nw t | d d S )Nr   r   )r   chflagsrM   chmod)rI   r   r   r   
resetperms#  s   z?TemporaryDirectory._rmtree.<locals>.onerror.<locals>.resetpermsr   )	
issubclassra   r   rI   rQ   r_   r   _rmtreere   )r   rI   exc_infor   clsr   rG   r   r   onerror!  s(   z+TemporaryDirectory._rmtree.<locals>.onerror)r   )_shutilrmtree)r   rG   r   r   r   r   r   r     s   zTemporaryDirectory._rmtreec                 C   s   | j ||d t|t d S Nr   )r   	_warningswarnResourceWarning)r   rG   r   r   r   r   r   r   >  s   zTemporaryDirectory._cleanupc                 C   s   d | jj| jS )Nz	<{} {!r}>)r   	__class__r=   rG   r4   r   r   r   __repr__C  s   zTemporaryDirectory.__repr__c                 C   s   | j S r"   )rG   r4   r   r   r   r   F  s   zTemporaryDirectory.__enter__c                 C   r   r"   )cleanupr   r   r   r   r   I  r   zTemporaryDirectory.__exit__c                 C   s2   | j  stj| jr| j| j| jd d S d S r   )r   r   r   rI   existsrG   r   r   r4   r   r   r   r  L  s   zTemporaryDirectory.cleanupNNNF)F)r=   r>   r?   r   r   r   r   r  r   r   r  r   r   r   r   r   r   r   r   
  s    
	r   r  )NNN)r   r   NNNNNT)r   r   NNNNN)?__all__	functoolsr   warningsr  ior\   osr   shutilr   errnorf   randomr   r/   sysru   typesr   weakrefr   _threadallocate_lock_allocate_lockO_RDWRr   O_EXCLr   r   r   r[   r   r   r#   rp   r   r!   r)   r*   rR   rm   ro   rs   r}   r	   r   r
   r   r   r   r   r   r   r   r   r   rG   platformr   r   r   r   r   r   r   r   <module>   s~    




	-

'( +?*
? 