
    ܈hL                    @   S SK Jr  S SKrS SKrS SKrS SKJr  S SKJrJ	r	  S SK
Jr  S SKJrJrJrJrJr  SSKJr  SS	KJr  SS
KJr  \(       a  S SKJrJrJrJr   " S S\\   5      r " S S\\   5      r " S S\\   5      r " S S\\   5      r \    S         SS jj5       r!\    S         SS jj5       r!    S         SS jjr!\   S        S!S jj5       r"\   S        S"S jj5       r"   S        S#S jjr"S$S jr#S%S jr$g)&    )annotationsN)Iterable)BytesIOTextIOWrapper)TracebackType)TYPE_CHECKINGAnyAnyStrGenericoverload   )	to_thread)	AsyncFile)checkpoint_if_cancelled)OpenBinaryModeOpenTextModeReadableBufferWriteableBufferc                  ,   \ rS rSr% SrS\S'   \       SSS.                 SS jjj5       r\      SSS.                 SS jjj5       r       SS	S.                 SS
 jjjrSS jr        SS jr	Sr
g	)TemporaryFile   a  
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.errorsc                   g N 	selfmode	bufferingencodingnewlinesuffixprefixdirr   s	            =D:\TimeStamps\venv\Lib\site-packages\anyio/_core/_tempfile.py__init__TemporaryFile.__init__/            c                   g r   r   r   s	            r(   r)   r*   <   r+   r,   Nc               d    Xl         X l        X0l        X@l        XPl        X`l        Xpl        Xl        g r   r!   r"   r#   r$   r%   r&   r'   r   r   s	            r(   r)   r*   J   s,     	" "("("r,   c                   ^ #    [         R                  " U 4S j5      I S h  vN n[        U5      T l        T R                  $  N 7f)Nc                    > [         R                  " T R                  T R                  T R                  T R
                  T R                  T R                  T R                  T R                  S9$ )Nr   )
tempfiler   r!   r"   r#   r$   r%   r&   r'   r   r    s   r(   <lambda>*TemporaryFile.__aenter__.<locals>.<lambda>a   sH    H**		{{	r,   r   run_syncr   r   r    fps   ` r(   
__aenter__TemporaryFile.__aenter___   s?     %%	
 
 %R=
   AA!Ac                T   #    U R                   R                  5       I S h  vN   g  N7fr   r   acloser    exc_type	exc_value	tracebacks       r(   	__aexit__TemporaryFile.__aexit__o         %%'''   (&()	r   r"   r'   r#   r   r!   r$   r&   r%   .......)r    zTemporaryFile[bytes]r!   r   r"   intr#   
str | Noner$   rJ   r%   rJ   r&   rJ   r'   rJ   r   rJ   )......)r    zTemporaryFile[str]r!   r   r"   rI   r#   rJ   r$   rJ   r%   rJ   r&   rJ   r'   rJ   r   rJ   )w+bNNNNN)r!   zOpenTextMode | OpenBinaryModer"   rI   r#   rJ   r$   rJ   r%   rJ   r&   rJ   r'   rJ   r   rJ   returnNonerM   r   rA   ztype[BaseException] | NonerB   zBaseException | NonerC   zTracebackType | NonerM   rN   __name__
__module____qualname____firstlineno____doc____annotations__r   r)   r:   rD   __static_attributes__r   r,   r(   r   r      s   & #"  #"!   !"  	
        "!   !   	
       /4#"!! "+  	
      
*  (,( (( (	(
 
(r,   r   c                  P   \ rS rSr% SrS\S'   \        SSSS.                     SS jjj5       r\       SSSS.                     SS jjj5       r        SS	S
S.                     SS jjjrSS jr        SS jr	Sr
g	)NamedTemporaryFilex   a4  
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_closec	                   g r   r   r    r!   r"   r#   r$   r%   r&   r'   deleter   r\   s              r(   r)   NamedTemporaryFile.__init__        r,   c	                   g r   r   r^   s              r(   r)   r`      ra   r,   NTc	          
     l    UUUUUUUUU	S.	U l         [        R                  S:  a  XR                   S'   g g )N)	r!   r"   r#   r$   r%   r&   r'   r_   r         r\   )_paramssysversion_infor^   s              r(   r)   r`      sJ     " 
(
 w&.=LL*+ 'r,   c                   ^ #    [         R                  " U 4S j5      I S h  vN n[        U5      T l        T R                  $  N 7f)Nc                 D   > [         R                  " S0 T R                  D6$ Nr   )r2   rZ   rg   r3   s   r(   r4   /NamedTemporaryFile.__aenter__.<locals>.<lambda>   s    H//?$,,?r,   r6   r8   s   ` r(   r:   NamedTemporaryFile.__aenter__   s=     %%?
 
 %R=	
r<   c                T   #    U R                   R                  5       I S h  vN   g  N7fr   r>   r@   s       r(   rD   NamedTemporaryFile.__aexit__   rF   rG   )r   rg   ........)r    zNamedTemporaryFile[bytes]r!   r   r"   rI   r#   rJ   r$   rJ   r%   rJ   r&   rJ   r'   rJ   r_   boolr   rJ   r\   rr   rH   )r    zNamedTemporaryFile[str]r!   r   r"   rI   r#   rJ   r$   rJ   r%   rJ   r&   rJ   r'   rJ   r_   rr   r   rJ   r\   rr   )rK   rL   NNNNNT)r!   OpenBinaryMode | OpenTextModer"   rI   r#   rJ   r$   rJ   r%   rJ   r&   rJ   r'   rJ   r_   rr   r   rJ   r\   rr   rM   rN   rO   rP   rQ   r   r,   r(   rZ   rZ   x   s   , #"  #"!   ! #'  	
          "!   ! #%  	
        " /4#"!!> " $>+> > 	>
 > > > > > > > 
>8 (,( (( (	(
 
(r,   rZ   c                    ^  \ rS rSr% SrSrS\S'   \        S SS.                   S!S jjj5       r\        S SS.                   S"S	 jjj5       r        S#S
S.                   S$U 4S jjjjrS%U 4S jjr	S%S jr
S%S jr\S&S j5       rS'S(U 4S jjjrS'S)U 4S jjjrS*U 4S jjrS+U 4S jjrS,U 4S jjrS,U 4S jjr\R*                  4S-U 4S jjjrS.U 4S jjrS/S0U 4S jjjr\S1S j5       r\S2S j5       rS3U 4S jjr\      S4S j5       r\      S5S j5       rS6U 4S jjrSrU =r$ )7SpooledTemporaryFile   a  
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.
Frr   _rolled.r   c	                   g r   r   
r    max_sizer!   r"   r#   r$   r%   r&   r'   r   s
             r(   r)   SpooledTemporaryFile.__init__        r,   c	                   g r   r   ry   s
             r(   r)   r{      r|   r,   Nc	          
        > UUUUUUUU	S.U l         Xl        SU;   a  [        T
U ]  [	        5       5        g [        T
U ]  [        [	        5       UU	USS95        g )Nr/   bT)r#   r   r$   write_through)_tempfile_params	_max_sizesuperr)   r   r   )r    rz   r!   r"   r#   r$   r%   r&   r'   r   	__class__s             r(   r)   r{     sj     " 	1
 "$;GWY'GI%!#"&r,   c                   >#    U R                   (       d  U R                  R                  5         g [        TU ]  5       I S h  vN   g  N7fr   )rw   _fpcloser   r?   r    r   s    r(   r?   SpooledTemporaryFile.aclose3  s.     ||HHNNgns   >A	AA	c                   #    U R                   (       d(  U R                  R                  5       U R                  ::  a  g U R	                  5       I S h  vN   g  N7fr   )rw   r   tellr   rolloverr3   s    r(   _checkSpooledTemporaryFile._check:  s3     <<488==?dnn<mmos   AAAAc                >  ^ #    T R                   (       a  g ST l         T R                  nUR                  S5        [        R                  " U 4S j5      I S h  vN T l        T R                  UR                  5       5      I S h  vN   UR                  5         g  NA N7f)NTr   c                 D   > [         R                  " S0 T R                  D6$ rl   )r2   r   r   r3   s   r(   r4   /SpooledTemporaryFile.rollover.<locals>.<lambda>H  s    H**CT-B-BCr,   )rw   r   seekr   r7   writereadr   )r    buffers   ` r(   r   SpooledTemporaryFile.rollover@  sr     <<A"++C
 
 jj'''	
 	(s$   ABB+BBBBc                .    U R                   R                  $ r   )r   closedr3   s    r(   r   SpooledTemporaryFile.closedM  s    xxr,   c                   >#    U R                   (       d-  [        5       I S h  vN   U R                  R                  U5      $ [        TU ]  U5      I S h  vN $  N6 N7fr   )rw   r   r   r   r   r    sizer   s     r(   r   SpooledTemporaryFile.readQ  sH     ||)+++88==&&W\$''' , (!   AA1AAAAc                   >#    U R                   (       d-  [        5       I S h  vN   U R                  R                  U5      $ [        TU ]  U5      I S h  vN $  N6 N7fr   )rw   r   r   read1r   r   s     r(   r   SpooledTemporaryFile.read1X  sH     ||)+++88>>$''W]4((( , )r   c                   >#    U R                   (       d,  [        5       I S h  vN   U R                  R                  5       $ [        TU ]  5       I S h  vN $  N4 N7fr   )rw   r   r   readliner   r   s    r(   r   SpooledTemporaryFile.readline_  sG     ||)+++88$$&&W%''' , (!   AA/AAAAc                   >#    U R                   (       d,  [        5       I S h  vN   U R                  R                  5       $ [        TU ]  5       I S h  vN $  N4 N7fr   )rw   r   r   	readlinesr   r   s    r(   r   SpooledTemporaryFile.readlinesf  sG     ||)+++88%%''W&((( , )r   c                   >#    U R                   (       d-  [        5       I S h  vN   U R                  R                  U5        [        TU ]  U5      I S h  vN $  N6 N7fr   )rw   r   r   readintor   r    r   r   s     r(   r   SpooledTemporaryFile.readintom  sH     ||)+++HHa W%a((( , )r   c                   >#    U R                   (       d-  [        5       I S h  vN   U R                  R                  U5        [        TU ]  U5      I S h  vN $  N6 N7fr   )rw   r   r   r   r   	readinto1r   s     r(   r   SpooledTemporaryFile.readinto1t  sH     ||)+++HHa W&q))) , *r   c                   >#    U R                   (       d-  [        5       I S h  vN   U R                  R                  X5      $ [        TU ]  X5      I S h  vN $  N6 N7fr   )rw   r   r   r   r   )r    offsetwhencer   s      r(   r   SpooledTemporaryFile.seek{  sH     ||)+++88==00W\&111 , 2r   c                   >#    U R                   (       d,  [        5       I S h  vN   U R                  R                  5       $ [        TU ]  5       I S h  vN $  N4 N7fr   )rw   r   r   r   r   r   s    r(   r   SpooledTemporaryFile.tell  sB     ||)+++88==?"W\^## , $r   c                   >#    U R                   (       d-  [        5       I S h  vN   U R                  R                  U5      $ [        TU ]  U5      I S h  vN $  N6 N7fr   )rw   r   r   truncater   r   s     r(   r   SpooledTemporaryFile.truncate  sK     ||)+++88$$T**W%d+++ , ,r   c                   #    g 7fr   r   r    r   s     r(   r   SpooledTemporaryFile.write  s     RU   c                   #    g 7fr   r   r   s     r(   r   r     s     EHr   c                   >#    U R                   (       dG  [        5       I Sh  vN   U R                  R                  U5      nU R	                  5       I Sh  vN   U$ [
        TU ]  U5      I Sh  vN $  NP N N7f)aP  
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)rw   r   r   r   r   r   )r    r   resultr   s      r(   r   r     s`      ||)+++XX^^A&F++-MW]1%%% , &3   A9A32A9A5A9.A7/A95A97A9c                   #    g 7fr   r   r    liness     r(   
writelinesSpooledTemporaryFile.writelines  
      r   c                   #    g 7fr   r   r   s     r(   r   r     r   r   c                   >#    U R                   (       dG  [        5       I Sh  vN   U R                  R                  U5      nU R	                  5       I Sh  vN   U$ [
        TU ]  U5      I Sh  vN $  NP N N7f)aG  
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)rw   r   r   r   r   r   )r    r   r   r   s      r(   r   r     sc      ||)+++XX((/F++-MW'... , /r   )r   r   rw   r   rq   )r    SpooledTemporaryFile[bytes]rz   rI   r!   r   r"   rI   r#   rJ   r$   rJ   r%   rJ   r&   rJ   r'   rJ   r   rJ   )r    SpooledTemporaryFile[str]rz   rI   r!   r   r"   rI   r#   rJ   r$   rJ   r%   rJ   r&   rJ   r'   rJ   r   rJ   )r   rK   rL   NNNNN)rz   rI   r!   rs   r"   rI   r#   rJ   r$   rJ   r%   rJ   r&   rJ   r'   rJ   r   rJ   rM   rN   rM   rN   )rM   rr   )rL   )r   rI   rM   r
   )r    r   r   rI   rM   bytes)rM   r
   )rM   zlist[AnyStr])r    r   r   r   rM   rI   )r   rI   r   
int | NonerM   rI   )rM   rI   r   )r   r   rM   rI   )r    r   r   r   rM   rI   )r    r   r   strrM   rI   )r   zReadableBuffer | strrM   rI   )r    r   r   zIterable[ReadableBuffer]rM   rN   )r    r   r   zIterable[str]rM   rN   )r   z(Iterable[str] | Iterable[ReadableBuffer]rM   rN   )rR   rS   rT   rU   rV   rw   rW   r   r)   r?   r   r   propertyr   r   r   r   r   r   r   osSEEK_SETr   r   r   r   r   rX   __classcell__)r   s   @r(   ru   ru      s   $ GT ""!   !)  	
          "!   !'  	
         .3#"!!# "## ,# 	#
 # # # # # # 
# #J  ( () )())* <>;; 2 2$, , U UH H&( )2J	  '0=	 / /r,   ru   c                  z    \ rS rSrSr   SSSS.           SS jjjrSS jr        SS	 jrSS
 jrSr	g)TemporaryDirectoryi  a  
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
    (Python 3.10+).
:param delete: Whether to delete the directory upon closing (Python 3.12+).
NFT)ignore_cleanup_errorsr_   c               N    Xl         X l        X0l        X@l        XPl        S U l        g r   )r%   r&   r'   r   r_   _tempdir)r    r%   r&   r'   r   r_   s         r(   r)   TemporaryDirectory.__init__  s%     &,%+"%%:"<@r,   c                  ^#    U R                   U R                  U R                  S.m[        R                  S:  a  U R
                  TS'   [        R                  S:  a  U R                  TS'   [        R                  " U4S j5      I S h  vN U l	        [        R                  " U R                  R                  5      I S h  vN $  N; N7f)Nr%   r&   r'   )re   
   r   rd   r_   c                 0   > [         R                  " S0 T D6$ rl   )r2   r   )paramss   r(   r4   /TemporaryDirectory.__aenter__.<locals>.<lambda>  s    H//9&9r,   )r%   r&   r'   rh   ri   r   r_   r   r7   r   	__enter__)r    r   s    @r(   r:   TemporaryDirectory.__aenter__  s     kkkk88"

 w&.2.H.HF*+w&#{{F8'009
 
 ''(?(?@@@
 As$   BCC6CC	C	Cc                   #    U R                   b5  [        R                  " U R                   R                  XU5      I S h  vN   g g  N7fr   )r   r   r7   __exit__r@   s       r(   rD   TemporaryDirectory.__aexit__  sD      ==$$$&&Y   %s   =AA Ac                   #    U R                   b3  [        R                  " U R                   R                  5      I S h  vN   g g  N7fr   )r   r   r7   cleanupr3   s    r(   r   TemporaryDirectory.cleanup  s5     ==$$$T]]%:%:;;; %;s   ;AAA)r   r_   r'   r   r&   r%   NNN)r%   AnyStr | Noner&   r   r'   r   r   rr   r_   rr   rM   rN   rM   r   rP   r   )
rR   rS   rT   rU   rV   r)   r:   rD   r   rX   r   r,   r(   r   r     s    " !% $!	A ',AA A 	A  $A A 
A"A"	,	 (	 (		
 
	<r,   r   c                   #    g 7fr   r   r%   r&   r'   texts       r(   mkstempr     s
      r   c                   #    g 7fr   r   r   s       r(   r   r     s
      r   c                j   #    [         R                  " [        R                  XX#5      I Sh  vN $  N7f)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   r7   r2   r   r   s       r(   r   r     s(     & ##H$4$4fcPPPP   *313c                   #    g 7fr   r   r   s      r(   mkdtempr   0  s
     
 r   c                   #    g 7fr   r   r   s      r(   r   r   8  s
     
 r   c                j   #    [         R                  " [        R                  XU5      I Sh  vN $  N7f)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   r7   r2   r   r   s      r(   r   r   @  s(       ##H$4$4fcJJJJr   c                 f   #    [         R                  " [        R                  5      I Sh  vN $  N7f)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   r7   r2   
gettempdirr   r,   r(   r   r   S  s$      ##H$7$78888   (1/1c                 f   #    [         R                  " [        R                  5      I Sh  vN $  N7f)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   r7   r2   gettempdirbr   r,   r(   r   r   _  s$      ##H$8$89999r   )NNNF)
r%   rJ   r&   rJ   r'   rJ   r   rr   rM   ztuple[int, str])
r%   bytes | Noner&   r   r'   r   r   rr   rM   ztuple[int, bytes])
r%   r   r&   r   r'   r   r   rr   rM   ztuple[int, str | bytes]r   )r%   rJ   r&   rJ   r'   rJ   rM   r   )r%   r   r&   r   r'   r   rM   r   )r%   r   r&   r   r'   r   rM   zstr | bytesr   )rM   r   )%
__future__r   r   rh   r2   collections.abcr   ior   r   typesr   typingr   r	   r
   r   r    r   _core._fileior   lowlevelr   	_typeshedr   r   r   r   r   rZ   ru   r   r   r   r   r   r   r,   r(   <module>r     s+   " 	 
  $ %    % .WW\(GFO \(~a( a(Hg/9V, g/T?< ?<D 
	 
 	
  
 
	 
 	
  
 ! 	QQQ 
Q 	Q
 Q, 
 
 		 
 
 
 	 
 ! KKK 
K 	K&	9	:r,   