
    f jL                       d dl mZ d dlZd dlZd dlZd dlmZ d dlmZm	Z	 d dl
mZ d dlmZmZmZmZmZ ddlmZ dd	lmZ dd
lmZ erd dlmZmZmZmZ  G d dee                   Z G d dee                   Z G d dee                   Z G d dee                   Z e	 	 	 	 d,d-d            Z!e	 	 	 	 d,d.d             Z!	 	 	 	 d,d/d#Z!e	 	 	 d0d1d%            Z"e	 	 	 d0d2d'            Z"	 	 	 d0d3d)Z"d4d*Z#d5d+Z$dS )6    )annotationsN)Iterable)BytesIOTextIOWrapper)TracebackType)TYPE_CHECKINGAnyAnyStrGenericoverload   )	to_thread)	AsyncFile)checkpoint_if_cancelled)OpenBinaryModeOpenTextModeReadableBufferWriteableBufferc                      e Zd ZU dZded<   e	 	 	 	 	 	 	 d&ddd'd            Ze	 	 	 	 	 	 d(ddd)d            Z	 	 	 	 	 	 	 d*ddd+dZd,dZd-d%ZdS ).TemporaryFilea  
    An asynchronous temporary file that is automatically created and cleaned up.

    This class provides an asynchronous context manager interface to a temporary file.
    The file is created using Python's standard `tempfile.TemporaryFile` function in a
    background thread, and is wrapped as an asynchronous file using `AsyncFile`.

    :param mode: The mode in which the file is opened. Defaults to "w+b".
    :param buffering: The buffering policy (-1 means the default buffering).
    :param encoding: The encoding used to decode or encode the file. Only applicable in
        text mode.
    :param newline: Controls how universal newlines mode works (only applicable in text
        mode).
    :param suffix: The suffix for the temporary file name.
    :param prefix: The prefix for the temporary file name.
    :param dir: The directory in which the temporary file is created.
    :param errors: The error handling scheme used for encoding/decoding errors.
    AsyncFile[AnyStr]_async_file.errorsselfTemporaryFile[bytes]moder   	bufferingintencoding
str | Nonenewlinesuffixprefixdirr   c                   d S N 	r   r   r   r    r"   r#   r$   r%   r   s	            iC:\Users\Terasoftware\OneDrive\Desktop\faahhh\fyndo\fyndo\venv\Lib\site-packages\anyio/_core/_tempfile.py__init__zTemporaryFile.__init__/   	     s    TemporaryFile[str]r   c                   d S r'   r(   r)   s	            r*   r+   zTemporaryFile.__init__<   r,   r-   w+bNOpenTextMode | OpenBinaryModereturnNonec               v    || _         || _        || _        || _        || _        || _        || _        || _        d S r'   r   r   r    r"   r#   r$   r%   r   r)   s	            r*   r+   zTemporaryFile.__init__J   s@     	" "("("r-   c                x    K   t          j         fd           d {V }t          |           _         j        S )Nc            
         t          j         j         j         j         j         j         j         j         j	                  S )Nr   )
tempfiler   r   r   r    r"   r#   r$   r%   r   r   s   r*   <lambda>z*TemporaryFile.__aenter__.<locals>.<lambda>a   sA    H*	{	 	 	 r-   r   run_syncr   r   r   fps   ` r*   
__aenter__zTemporaryFile.__aenter___   sd      %	 	 	 	
 
 
 
 
 
 
 
 %R==r-   exc_typetype[BaseException] | None	exc_valueBaseException | None	tracebackTracebackType | Nonec                H   K   | j                                          d {V  d S r'   r   acloser   rA   rC   rE   s       r*   	__aexit__zTemporaryFile.__aexit__o   5       %%'''''''''''r-   .......)r   r   r   r   r   r   r    r!   r"   r!   r#   r!   r$   r!   r%   r!   r   r!   )......)r   r.   r   r   r   r   r    r!   r"   r!   r#   r!   r$   r!   r%   r!   r   r!   )r0   r1   NNNNN)r   r2   r   r   r    r!   r"   r!   r#   r!   r$   r!   r%   r!   r   r!   r3   r4   r3   r   rA   rB   rC   rD   rE   rF   r3   r4   	__name__
__module____qualname____doc____annotations__r   r+   r@   rK   r(   r-   r*   r   r      s&         & #"""  #"!   !     X  "!   !     X /4#"!! "     *        ( ( ( ( ( (r-   r   c                      e Zd ZU dZded<   e	 	 	 	 	 	 	 	 d*dddd+d            Ze	 	 	 	 	 	 	 d,dddd-d            Z	 	 	 	 	 	 	 	 d.dddd/d!Zd0d"Zd1d)ZdS )2NamedTemporaryFilea|  
    An asynchronous named temporary file that is automatically created and cleaned up.

    This class provides an asynchronous context manager for a temporary file with a
    visible name in the file system. It uses Python's standard
    :func:`~tempfile.NamedTemporaryFile` function and wraps the file object with
    :class:`AsyncFile` for asynchronous operations.

    :param mode: The mode in which the file is opened. Defaults to "w+b".
    :param buffering: The buffering policy (-1 means the default buffering).
    :param encoding: The encoding used to decode or encode the file. Only applicable in
        text mode.
    :param newline: Controls how universal newlines mode works (only applicable in text
        mode).
    :param suffix: The suffix for the temporary file name.
    :param prefix: The prefix for the temporary file name.
    :param dir: The directory in which the temporary file is created.
    :param delete: Whether to delete the file when it is closed.
    :param errors: The error handling scheme used for encoding/decoding errors.
    :param delete_on_close: (Python 3.12+) Whether to delete the file on close.
    r   r   .)r   delete_on_closer   NamedTemporaryFile[bytes]r   r   r   r   r    r!   r"   r#   r$   r%   deleteboolr   rX   c	                   d S r'   r(   r   r   r   r    r"   r#   r$   r%   rZ   r   rX   s              r*   r+   zNamedTemporaryFile.__init__   	     sr-   NamedTemporaryFile[str]r   c	                   d S r'   r(   r]   s              r*   r+   zNamedTemporaryFile.__init__   r^   r-   r0   r1   NTOpenBinaryMode | OpenTextModer3   r4   c	          
     `    |||||||||	d	| _         t          j        dk    r|
| j         d<   d S d S )N)	r   r   r    r"   r#   r$   r%   rZ   r         rX   )_paramssysversion_infor]   s              r*   r+   zNamedTemporaryFile.__init__   s\     " 
(
 
(
 w& 	>.=DL*+++	> 	>r-   c                x    K   t          j         fd           d {V }t          |           _         j        S )Nc                 0    t          j        di  j        S Nr(   )r9   rW   rf   r:   s   r*   r;   z/NamedTemporaryFile.__aenter__.<locals>.<lambda>   s    H/??$,?? r-   r<   r>   s   ` r*   r@   zNamedTemporaryFile.__aenter__   s\      %????
 
 
 
 
 
 
 
 %R==r-   rA   rB   rC   rD   rE   rF   c                H   K   | j                                          d {V  d S r'   rH   rJ   s       r*   rK   zNamedTemporaryFile.__aexit__   rL   r-   ........)r   rY   r   r   r   r   r    r!   r"   r!   r#   r!   r$   r!   r%   r!   rZ   r[   r   r!   rX   r[   rM   )r   r_   r   r   r   r   r    r!   r"   r!   r#   r!   r$   r!   r%   r!   rZ   r[   r   r!   rX   r[   )r0   r1   NNNNNT)r   ra   r   r   r    r!   r"   r!   r#   r!   r$   r!   r%   r!   rZ   r[   r   r!   rX   r[   r3   r4   rN   rO   rP   r(   r-   r*   rW   rW   x   s8         , #"""  #"!   ! #     X  "!   ! #     X" /4#"!!> " $> > > > > >8       ( ( ( ( ( (r-   rW   c                      e Zd ZU dZdZded<   e	 	 	 	 	 	 	 	 dDdddEd            Ze	 	 	 	 	 	 	 	 dDdddFd            Z	 	 	 	 	 	 	 	 dGdddH fd ZdI fd!ZdId"Z	dId#Z
edJd$            ZdKdL fd'ZdKdM fd)ZdN fd*ZdO fd,ZdP fd/ZdP fd0Zej        fdQ fd4ZdR fd5ZdSdT fd6ZedUd8            ZedVd:            ZdW fd<ZedXd?            ZedYdA            ZdZ fdCZ xZS )[SpooledTemporaryFilea  
    An asynchronous spooled temporary file that starts in memory and is spooled to disk.

    This class provides an asynchronous interface to a spooled temporary file, much like
    Python's standard :class:`~tempfile.SpooledTemporaryFile`. It supports asynchronous
    write operations and provides a method to force a rollover to disk.

    :param max_size: Maximum size in bytes before the file is rolled over to disk.
    :param mode: The mode in which the file is opened. Defaults to "w+b".
    :param buffering: The buffering policy (-1 means the default buffering).
    :param encoding: The encoding used to decode or encode the file (text mode only).
    :param newline: Controls how universal newlines mode works (text mode only).
    :param suffix: The suffix for the temporary file name.
    :param prefix: The prefix for the temporary file name.
    :param dir: The directory in which the temporary file is created.
    :param errors: The error handling scheme used for encoding/decoding errors.
    Fr[   _rolled.r   r   SpooledTemporaryFile[bytes]max_sizer   r   r   r   r    r!   r"   r#   r$   r%   r   c	                   d S r'   r(   
r   rr   r   r   r    r"   r#   r$   r%   r   s
             r*   r+   zSpooledTemporaryFile.__init__   	     sr-   SpooledTemporaryFile[str]r   c	                   d S r'   r(   rt   s
             r*   r+   zSpooledTemporaryFile.__init__   ru   r-   r   r0   r1   Nra   r3   r4   c	          	        ||||||||	d| _         || _        d|v r/t                                          t	                                 d S t                                          t          t	                      ||	|d                     d S )Nr6   bT)r    r   r"   write_through)_tempfile_params	_max_sizesuperr+   r   r   )r   rr   r   r   r    r"   r#   r$   r%   r   	__class__s             r*   r+   zSpooledTemporaryFile.__init__  s     " 	1
 	1
 "$; 	GGWYY'''''GGII%!#"&      r-   c                   K   | j         s| j                                         d S t                                                       d {V  d S r'   )rp   _fpcloser}   rI   r   r~   s    r*   rI   zSpooledTemporaryFile.aclose3  sT      | 	HNNFggnnr-   c                   K   | j         s"| j                                        | j        k    rd S |                                  d {V  d S r'   )rp   r   tellr|   rolloverr:   s    r*   _checkzSpooledTemporaryFile._check:  sS      < 	48==??dn< 	Fmmoor-   c                *   K    j         rd S d _          j        }|                    d           t          j         fd           d {V  _                             |                                           d {V  |                                 d S )NTr   c                 0    t          j        di  j        S rk   )r9   r   r{   r:   s   r*   r;   z/SpooledTemporaryFile.rollover.<locals>.<lambda>H  s    H*CCT-BCC r-   )rp   r   seekr   r=   writereadr   )r   buffers   ` r*   r   zSpooledTemporaryFile.rollover@  s      < 	FA"+CCCC
 
 
 
 
 
 
 
 jj'''''''''r-   c                    | j         j        S r'   )r   closedr:   s    r*   r   zSpooledTemporaryFile.closedM  s    xr-   sizer
   c                   K   | j         s.t                       d {V  | j                            |          S t	                                          |           d {V S r'   )rp   r   r   r   r}   r   r   r~   s     r*   r   zSpooledTemporaryFile.readQ  sk      | 	')+++++++++8==&&&WW\\$'''''''''r-   bytesc                   K   | j         s.t                       d {V  | j                            |          S t	                                          |           d {V S r'   )rp   r   r   read1r}   r   s     r*   r   zSpooledTemporaryFile.read1X  sk      | 	()+++++++++8>>$'''WW]]4(((((((((r-   c                   K   | j         s-t                       d {V  | j                                        S t	                                                       d {V S r'   )rp   r   r   readliner}   r   s    r*   r   zSpooledTemporaryFile.readline_  sk      | 	')+++++++++8$$&&&WW%%'''''''''r-   list[AnyStr]c                   K   | j         s-t                       d {V  | j                                        S t	                                                       d {V S r'   )rp   r   r   	readlinesr}   r   s    r*   r   zSpooledTemporaryFile.readlinesf  sk      | 	()+++++++++8%%'''WW&&(((((((((r-   ry   r   c                   K   | j         s.t                       d {V  | j                            |           t	                                          |           d {V S r'   )rp   r   r   readintor}   r   ry   r~   s     r*   r   zSpooledTemporaryFile.readintom  so      | 	!)+++++++++Ha   WW%%a(((((((((r-   c                   K   | j         s.t                       d {V  | j                            |           t	                                          |           d {V S r'   )rp   r   r   r   r}   	readinto1r   s     r*   r   zSpooledTemporaryFile.readinto1t  so      | 	!)+++++++++Ha   WW&&q)))))))))r-   offsetwhence
int | Nonec                   K   | j         s/t                       d {V  | j                            ||          S t	                                          ||           d {V S r'   )rp   r   r   r   r}   )r   r   r   r~   s      r*   r   zSpooledTemporaryFile.seek{  so      | 	1)+++++++++8==000WW\\&&111111111r-   c                   K   | j         s-t                       d {V  | j                                        S t	                                                       d {V S r'   )rp   r   r   r   r}   r   s    r*   r   zSpooledTemporaryFile.tell  sc      | 	#)+++++++++8==??"WW\\^^#######r-   c                   K   | j         s.t                       d {V  | j                            |          S t	                                          |           d {V S r'   )rp   r   r   truncater}   r   s     r*   r   zSpooledTemporaryFile.truncate  so      | 	+)+++++++++8$$T***WW%%d+++++++++r-   r   c                
   K   d S r'   r(   r   ry   s     r*   r   zSpooledTemporaryFile.write  s      RURUr-   strc                
   K   d S r'   r(   r   s     r*   r   zSpooledTemporaryFile.write  s      EHSr-   ReadableBuffer | strc                   K   | j         sJt                       d{V  | j                            |          }|                                  d{V  |S t                                          |           d{V S )a  
        Asynchronously write data to the spooled temporary file.

        If the file has not yet been rolled over, the data is written synchronously,
        and a rollover is triggered if the size exceeds the maximum size.

        :param s: The data to write.
        :return: The number of bytes written.
        :raises RuntimeError: If the underlying file is not initialized.

        N)rp   r   r   r   r   r}   )r   ry   resultr~   s      r*   r   zSpooledTemporaryFile.write  s       | 	)+++++++++X^^A&&F++--MWW]]1%%%%%%%%%r-   linesIterable[ReadableBuffer]c                
   K   d S r'   r(   r   r   s     r*   
writelineszSpooledTemporaryFile.writelines         sr-   Iterable[str]c                
   K   d S r'   r(   r   s     r*   r   zSpooledTemporaryFile.writelines  r   r-   (Iterable[str] | Iterable[ReadableBuffer]c                   K   | j         sJt                       d{V  | j                            |          }|                                  d{V  |S t                                          |           d{V S )aw  
        Asynchronously write a list of lines to the spooled temporary file.

        If the file has not yet been rolled over, the lines are written synchronously,
        and a rollover is triggered if the size exceeds the maximum size.

        :param lines: An iterable of lines to write.
        :raises RuntimeError: If the underlying file is not initialized.

        N)rp   r   r   r   r   r}   )r   r   r   r~   s      r*   r   zSpooledTemporaryFile.writelines  s       | 	)+++++++++X((//F++--MWW''.........r-   rm   )r   rq   rr   r   r   r   r   r   r    r!   r"   r!   r#   r!   r$   r!   r%   r!   r   r!   )r   rv   rr   r   r   r   r   r   r    r!   r"   r!   r#   r!   r$   r!   r%   r!   r   r!   )r   r0   r1   NNNNN)rr   r   r   ra   r   r   r    r!   r"   r!   r#   r!   r$   r!   r%   r!   r   r!   r3   r4   r3   r4   )r3   r[   )r1   )r   r   r3   r
   )r   rq   r   r   r3   r   )r3   r
   )r3   r   )r   rq   ry   r   r3   r   )r   r   r   r   r3   r   )r3   r   r'   )r   r   r3   r   )r   rq   ry   r   r3   r   )r   rv   ry   r   r3   r   )ry   r   r3   r   )r   rq   r   r   r3   r4   )r   rv   r   r   r3   r4   )r   r   r3   r4   )rQ   rR   rS   rT   rp   rU   r   r+   rI   r   r   propertyr   r   r   r   r   r   r   osSEEK_SETr   r   r   r   r   __classcell__)r~   s   @r*   ro   ro      s^         $ G ""!   !     X   "!   !     X  .3#"!!# "# # # # # # # #J               X( ( ( ( ( ( () ) ) ) ) ) )( ( ( ( ( () ) ) ) ) )) ) ) ) ) )* * * * * * <>; 2 2 2 2 2 2 2$ $ $ $ $ $, , , , , , , UUU XUHHH XH& & & & & &(    X    X/ / / / / / / / / /r-   ro   c                  B    e Zd ZdZ	 	 	 ddddddZddZddZddZdS )TemporaryDirectorya  
    An asynchronous temporary directory that is created and cleaned up automatically.

    This class provides an asynchronous context manager for creating a temporary
    directory. It wraps Python's standard :class:`~tempfile.TemporaryDirectory` to
    perform directory creation and cleanup operations in a background thread.

    :param suffix: Suffix to be added to the temporary directory name.
    :param prefix: Prefix to be added to the temporary directory name.
    :param dir: The parent directory where the temporary directory is created.
    :param ignore_cleanup_errors: Whether to ignore errors during cleanup
    :param delete: Whether to delete the directory upon closing (Python 3.12+).
    NFT)ignore_cleanup_errorsrZ   r#   AnyStr | Noner$   r%   r   r[   rZ   r3   r4   c               Z    || _         || _        || _        || _        || _        d | _        d S r'   )r#   r$   r%   r   rZ   _tempdir)r   r#   r$   r%   r   rZ   s         r*   r+   zTemporaryDirectory.__init__  s3     &,%+"%%:"<@r-   r   c                   K   | j         | j        | j        | j        dt          j        dk    r
| j        d<   t          j        fd           d {V | _	        t          j        | j	        j
                   d {V S )N)r#   r$   r%   r   rc   rZ   c                 &    t          j        di  S rk   )r9   r   )paramss   r*   r;   z/TemporaryDirectory.__aenter__.<locals>.<lambda>  s    H/99&99 r-   )r#   r$   r%   r   rg   rh   rZ   r   r=   r   	__enter__)r   r   s    @r*   r@   zTemporaryDirectory.__aenter__  s      kk8%)%?	"
 "
 w& 	+#{F8'09999
 
 
 
 
 
 
 
 '(?@@@@@@@@@r-   rA   rB   rC   rD   rE   rF   c                j   K   | j         )t          j        | j         j        |||           d {V  d S d S r'   )r   r   r=   __exit__rJ   s       r*   rK   zTemporaryDirectory.__aexit__  sg       = 	$&)Y          	 	r-   c                d   K   | j         &t          j        | j         j                   d {V  d S d S r'   )r   r   r=   cleanupr:   s    r*   r   zTemporaryDirectory.cleanup   sH      = 	<$T]%:;;;;;;;;;;;	< 	<r-   NNN)r#   r   r$   r   r%   r   r   r[   rZ   r[   r3   r4   r3   r   rO   r   )rQ   rR   rS   rT   r+   r@   rK   r   r(   r-   r*   r   r     s           !% $!	A ',A A A A A A"A A A A	 	 	 	< < < < < <r-   r   Fr#   r!   r$   r%   textr[   r3   tuple[int, str]c                
   K   d S r'   r(   r#   r$   r%   r   s       r*   mkstempr     s       cr-   bytes | Nonetuple[int, bytes]c                
   K   d S r'   r(   r   s       r*   r   r     s       r-   r   tuple[int, str | bytes]c                V   K   t          j        t          j        | |||           d{V S )a  
    Asynchronously create a temporary file and return an OS-level handle and the file
    name.

    This function wraps `tempfile.mkstemp` and executes it in a background thread.

    :param suffix: Suffix to be added to the file name.
    :param prefix: Prefix to be added to the file name.
    :param dir: Directory in which the temporary file is created.
    :param text: Whether the file is opened in text mode.
    :return: A tuple containing the file descriptor and the file name.

    N)r   r=   r9   r   r   s       r*   r   r     s6      & #H$4ffc4PPPPPPPPPr-   r   c                
   K   d S r'   r(   r#   r$   r%   s      r*   mkdtempr   -  s      
 #r-   r   c                
   K   d S r'   r(   r   s      r*   r   r   5  s      
 Cr-   str | bytesc                T   K   t          j        t          j        | ||           d{V S )a  
    Asynchronously create a temporary directory and return its path.

    This function wraps `tempfile.mkdtemp` and executes it in a background thread.

    :param suffix: Suffix to be added to the directory name.
    :param prefix: Prefix to be added to the directory name.
    :param dir: Parent directory where the temporary directory is created.
    :return: The path of the created temporary directory.

    N)r   r=   r9   r   r   s      r*   r   r   =  s4        #H$4ffcJJJJJJJJJr-   c                 N   K   t          j        t          j                   d{V S )z
    Asynchronously return the name of the directory used for temporary files.

    This function wraps `tempfile.gettempdir` and executes it in a background thread.

    :return: The path of the temporary directory as a string.

    N)r   r=   r9   
gettempdirr(   r-   r*   r   r   P  s.       #H$7888888888r-   c                 N   K   t          j        t          j                   d{V S )z
    Asynchronously return the name of the directory used for temporary files in bytes.

    This function wraps `tempfile.gettempdirb` and executes it in a background thread.

    :return: The path of the temporary directory as bytes.

    N)r   r=   r9   gettempdirbr(   r-   r*   r   r   \  s.       #H$8999999999r-   )NNNF)
r#   r!   r$   r!   r%   r!   r   r[   r3   r   )
r#   r   r$   r   r%   r   r   r[   r3   r   )
r#   r   r$   r   r%   r   r   r[   r3   r   r   )r#   r!   r$   r!   r%   r!   r3   r   )r#   r   r$   r   r%   r   r3   r   )r#   r   r$   r   r%   r   r3   r   r   )r3   r   )%
__future__r   r   rg   r9   collections.abcr   ior   r   typesr   typingr   r	   r
   r   r    r   _core._fileior   lowlevelr   	_typeshedr   r   r   r   r   rW   ro   r   r   r   r   r   r(   r-   r*   <module>r      s3   " " " " " " 				 



  $ $ $ $ $ $ % % % % % % % %                          % % % % % % . . . . . . XWWWWWWWWWWWW\( \( \( \( \(GFO \( \( \(~a( a( a( a( a( a( a( a(Hg/ g/ g/ g/ g/9V, g/ g/ g/T<< << << << << << << <<~ 
	    
 
	    
 ! 	Q Q Q Q Q, 
    
 
    
 ! K K K K K&	9 	9 	9 	9	: 	: 	: 	: 	: 	:r-   