o
    ;'hðL  ã                   @  s’  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rTd dlmZmZmZmZ G dd„ dee ƒZG dd„ dee ƒZG dd„ dee ƒZG dd„ dee ƒZ e				d0d1dd„ƒZ!e				d0d2d!d„ƒZ!				d0d3d$d„Z!e			d4d5d&d'„ƒZ"e			d4d6d)d'„ƒZ"			d4d7d+d'„Z"d8d,d-„Z#d9d.d/„Z$dS ):é    )ÚannotationsN)ÚIterable)ÚBytesIOÚTextIOWrapper)ÚTracebackType)ÚTYPE_CHECKINGÚAnyÚAnyStrÚGenericÚoverloadé   )Ú	to_thread)Ú	AsyncFile)Úcheckpoint_if_cancelled)ÚOpenBinaryModeÚOpenTextModeÚReadableBufferÚWriteableBufferc                   @  s”   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d/dd „Zd0d'd(„ZdS )1Ú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          	      C  ó   d S ©N© ©	r   r   r   r   r    r!   r"   r#   r   r&   r&   úKC:\Users\shubh\Videos\agent\nova\Lib\site-packages\anyio/_core/_tempfile.pyÚ__init__/   ó   zTemporaryFile.__init__úTemporaryFile[str]r   c          	      C  r$   r%   r&   r'   r&   r&   r(   r)   <   r*   úw+béÿÿÿÿNúOpenTextMode | OpenBinaryModeÚreturnÚNonec          	      C  s4   || _ || _|| _|| _|| _|| _|| _|| _d S r%   ©r   r   r   r    r!   r"   r#   r   r'   r&   r&   r(   r)   J   s   
c                 ƒ  ó*   �t  ‡ fdd„¡I d H }t|ƒˆ _ˆ jS )Nc                
     s*   t jˆ jˆ jˆ jˆ jˆ jˆ jˆ jˆ j	d�S )Nr   )
Útempfiler   r   r   r   r    r!   r"   r#   r   r&   ©r   r&   r(   Ú<lambda>a   s    øz*TemporaryFile.__aenter__.<locals>.<lambda>©r   Úrun_syncr   r   ©r   Úfpr&   r4   r(   Ú
__aenter___   s   €

ÿ
zTemporaryFile.__aenter__Úexc_typeútype[BaseException] | NoneÚ	exc_valueúBaseException | NoneÚ	tracebackúTracebackType | Nonec                 Ã  ó   �| j  ¡ I d H  d S r%   ©r   Úaclose©r   r;   r=   r?   r&   r&   r(   Ú	__aexit__o   ó   €zTemporaryFile.__aexit__©.......)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,   r-   NNNNN)r   r.   r   r   r   r   r    r   r!   r   r"   r   r#   r   r   r   r/   r0   ©r/   r   ©r;   r<   r=   r>   r?   r@   r/   r0   ©	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r)   r:   rE   r&   r&   r&   r(   r      sH   
 ø
öø
öø
ö
r   c                   @  s    e Zd ZU dZded< e								d-dddœd.dd„ƒZe							d/dddœd0dd„ƒZ								d1dddœd2d"d„Zd3d#d$„Zd4d+d,„ZdS )5Ú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   rQ   c	                C  r$   r%   r&   ©r   r   r   r   r    r!   r"   r#   rS   r   rQ   r&   r&   r(   r)   ‘   ó   zNamedTemporaryFile.__init__úNamedTemporaryFile[str]r   c	                C  r$   r%   r&   rU   r&   r&   r(   r)       rV   r,   r-   NTúOpenBinaryMode | OpenTextModer/   r0   c	             
   C  s6   |||||||||	dœ	| _ tjdkr|
| j d< d S d S )N)	r   r   r   r    r!   r"   r#   rS   r   ©é   é   rQ   )Ú_paramsÚsysÚversion_inforU   r&   r&   r(   r)   °   s   ÷
ÿc                 ƒ  r2   )Nc                     ó   t jdi ˆ j¤ŽS ©Nr&   )r3   rP   r\   r&   r4   r&   r(   r5   Î   ó    z/NamedTemporaryFile.__aenter__.<locals>.<lambda>r6   r8   r&   r4   r(   r:   Ì   s   €

ÿ
zNamedTemporaryFile.__aenter__r;   r<   r=   r>   r?   r@   c                 Ã  rA   r%   rB   rD   r&   r&   r(   rE   Ó   rF   zNamedTemporaryFile.__aexit__©........)r   rR   r   r   r   r   r   r   r    r   r!   r   r"   r   r#   r   rS   rT   r   r   rQ   rT   rG   )r   rW   r   r   r   r   r   r   r    r   r!   r   r"   r   r#   r   rS   rT   r   r   rQ   rT   )r,   r-   NNNNNT)r   rX   r   r   r   r   r    r   r!   r   r"   r   r#   r   rS   rT   r   r   rQ   rT   r/   r0   rH   rI   rJ   r&   r&   r&   r(   rP   x   sT   
 ÷ô÷ô÷ô
rP   c                      s¢  e Zd ZU dZdZded< e								dTddœdUdd„ƒZe								dTddœdVdd„ƒZ								dWddœdX‡ fd!d„ZdY‡ fd"d#„ZdYd$d%„Z	dYd&d'„Z
edZd(d)„ƒZd[d\‡ fd,d-„Zd[d]‡ fd/d0„Zd^‡ fd1d2„Zd_‡ fd4d5„Zd`‡ fd8d9„Zd`‡ fd:d;„Zejfda‡ fd?d@„Zdb‡ fdAdB„Zdcdd‡ fdCdD„ZededFdG„ƒZedfdIdG„ƒZdg‡ fdKdG„ZedhdNdO„ƒZedidQdO„ƒZdj‡ fdSdO„Z‡  ZS )kÚ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.
    FrT   Ú_rolled.r   r   úSpooledTemporaryFile[bytes]Úmax_sizer   r   r   r   r   r   r    r!   r"   r#   r   c	          
      C  r$   r%   r&   ©
r   rf   r   r   r   r    r!   r"   r#   r   r&   r&   r(   r)   ñ   ó   zSpooledTemporaryFile.__init__úSpooledTemporaryFile[str]r   c	          
      C  r$   r%   r&   rg   r&   r&   r(   r)   ÿ   rh   r   r,   r-   NrX   r/   r0   c	          
   	     sX   ||||||||	dœ| _ || _d|v rtƒ  tƒ ¡ d S tƒ  ttƒ ||	|dd�¡ d S )Nr1   ÚbT)r   r   r    Úwrite_through)Ú_tempfile_paramsÚ	_max_sizeÚsuperr)   r   r   rg   ©Ú	__class__r&   r(   r)     s*   ø
ûÿc                 ƒ  s*   �| j s| j ¡  d S tƒ  ¡ I d H  d S r%   )rd   Ú_fpÚclosern   rC   r4   ro   r&   r(   rC   3  s
   €
zSpooledTemporaryFile.aclosec                 Ã  s.   �| j s| j ¡ | jk rd S |  ¡ I d H  d S r%   )rd   rq   Útellrm   Úrolloverr4   r&   r&   r(   Ú_check:  s   €zSpooledTemporaryFile._checkc                 ƒ  s\   �ˆ j rd S dˆ _ ˆ j}| d¡ t ‡ fdd„¡I d H ˆ _ˆ  | ¡ ¡I d H  | ¡  d S )NTr   c                     r_   r`   )r3   r   rl   r&   r4   r&   r(   r5   H  ra   z/SpooledTemporaryFile.rollover.<locals>.<lambda>)rd   rq   Úseekr   r7   ÚwriteÚreadrr   )r   Úbufferr&   r4   r(   rt   @  s   €

ÿzSpooledTemporaryFile.rolloverc                 C  s   | j jS r%   )rq   Úclosedr4   r&   r&   r(   rz   M  s   zSpooledTemporaryFile.closedÚsizer	   c                 ƒ  ó2   �| j stƒ I d H  | j |¡S tƒ  |¡I d H S r%   )rd   r   rq   rx   rn   ©r   r{   ro   r&   r(   rx   Q  ó
   €zSpooledTemporaryFile.readÚbytesc                 ƒ  r|   r%   )rd   r   rq   Úread1rn   r}   ro   r&   r(   r€   X  r~   zSpooledTemporaryFile.read1c                 ƒ  ó.   �| j stƒ I d H  | j ¡ S tƒ  ¡ I d H S r%   )rd   r   rq   Úreadlinern   r4   ro   r&   r(   r‚   _  ó
   €
zSpooledTemporaryFile.readlineúlist[AnyStr]c                 ƒ  r�   r%   )rd   r   rq   Ú	readlinesrn   r4   ro   r&   r(   r…   f  rƒ   zSpooledTemporaryFile.readlinesrj   r   c                 ƒ  s2   �| j stƒ I d H  | j |¡ tƒ  |¡I d H S r%   )rd   r   rq   Úreadintorn   ©r   rj   ro   r&   r(   r†   m  r~   zSpooledTemporaryFile.readintoc                 ƒ  s2   �| j stƒ I d H  | j |¡ tƒ  |¡I d H S r%   )rd   r   rq   r†   rn   Ú	readinto1r‡   ro   r&   r(   rˆ   t  r~   zSpooledTemporaryFile.readinto1ÚoffsetÚwhenceú
int | Nonec                 ƒ  s6   �| j stƒ I d H  | j ||¡S tƒ  ||¡I d H S r%   )rd   r   rq   rv   rn   )r   r‰   rŠ   ro   r&   r(   rv   {  s
   €zSpooledTemporaryFile.seekc                 ƒ  r�   r%   )rd   r   rq   rs   rn   r4   ro   r&   r(   rs   ‚  rƒ   zSpooledTemporaryFile.tellc                 ƒ  r|   r%   )rd   r   rq   Útruncatern   r}   ro   r&   r(   rŒ   ‰  r~   zSpooledTemporaryFile.truncater   c                 Ã  ó   �d S r%   r&   r‡   r&   r&   r(   rw   �  ó   €zSpooledTemporaryFile.writeÚstrc                 Ã  r�   r%   r&   r‡   r&   r&   r(   rw   ’  rŽ   úReadableBuffer | strc                 ƒ  óD   �| j stƒ I dH  | j |¡}|  ¡ I dH  |S tƒ  |¡I dH 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)rd   r   rq   rw   ru   rn   )r   rj   Úresultro   r&   r(   rw   •  s   €ÚlinesúIterable[ReadableBuffer]c                 Ã  r�   r%   r&   ©r   r“   r&   r&   r(   Ú
writelines©  ó   €zSpooledTemporaryFile.writelinesúIterable[str]c                 Ã  r�   r%   r&   r•   r&   r&   r(   r–   ­  r—   ú(Iterable[str] | Iterable[ReadableBuffer]c                 ƒ  r‘   )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)rd   r   rq   r–   ru   rn   )r   r“   r’   ro   r&   r(   r–   ²  s   €rb   )r   re   rf   r   r   r   r   r   r   r   r    r   r!   r   r"   r   r#   r   r   r   )r   ri   rf   r   r   r   r   r   r   r   r    r   r!   r   r"   r   r#   r   r   r   )r   r,   r-   NNNNN)rf   r   r   rX   r   r   r   r   r    r   r!   r   r"   r   r#   r   r   r   r/   r0   ©r/   r0   )r/   rT   )r-   )r{   r   r/   r	   )r   re   r{   r   r/   r   )r/   r	   )r/   r„   )r   re   rj   r   r/   r   )r‰   r   rŠ   r‹   r/   r   )r/   r   r%   )r{   r‹   r/   r   )r   re   rj   r   r/   r   )r   ri   rj   r�   r/   r   )rj   r�   r/   r   )r   re   r“   r”   r/   r0   )r   ri   r“   r˜   r/   r0   )r“   r™   r/   r0   )rK   rL   rM   rN   rd   rO   r   r)   rC   ru   rt   Úpropertyrz   rx   r€   r‚   r…   r†   rˆ   ÚosÚSEEK_SETrv   rs   rŒ   rw   r–   Ú__classcell__r&   r&   ro   r(   rc   Ü   s|   
 ÷õ÷õ÷õ%

rc   c                   @  sH   e Zd ZdZ			ddddœddd„Zd dd„Zd!dd„Zd"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
        (Python 3.10+).
    :param delete: Whether to delete the directory upon closing (Python 3.12+).
    NFT)Úignore_cleanup_errorsrS   r!   úAnyStr | Noner"   r#   r    rT   rS   r/   r0   c                C  s(   || _ || _|| _|| _|| _d | _d S r%   )r!   r"   r#   r    rS   Ú_tempdir)r   r!   r"   r#   r    rS   r&   r&   r(   r)   Ö  s   	
zTemporaryDirectory.__init__r�   c                 ƒ  sj   �| j | j| jdœ‰ tjdkr| jˆ d< tjdkr| jˆ d< t ‡ fdd„¡I d H | _	t | j	j
¡I d H S )N©r!   r"   r#   )rZ   é
   r    rY   rS   c                     s   t jdi ˆ ¤ŽS r`   )r3   rŸ   r&   ©Úparamsr&   r(   r5   ô  s    z/TemporaryDirectory.__aenter__.<locals>.<lambda>)r!   r"   r#   r]   r^   r    rS   r   r7   r¢   Ú	__enter__r4   r&   r¥   r(   r:   ç  s   €ý




ÿzTemporaryDirectory.__aenter__r;   r<   r=   r>   r?   r@   c                 Ã  s.   �| j d urt | j j|||¡I d H  d S d S r%   )r¢   r   r7   Ú__exit__rD   r&   r&   r(   rE   ø  s   €
ÿÿzTemporaryDirectory.__aexit__c                 Ã  s(   �| j d urt | j j¡I d H  d S d S r%   )r¢   r   r7   Úcleanupr4   r&   r&   r(   r©     s   €
ÿzTemporaryDirectory.cleanup©NNN)r!   r¡   r"   r¡   r#   r¡   r    rT   rS   rT   r/   r0   ©r/   r�   rI   rš   )rK   rL   rM   rN   r)   r:   rE   r©   r&   r&   r&   r(   rŸ   Æ  s    üù

rŸ   Fr!   r   r"   r#   ÚtextrT   r/   útuple[int, str]c                 Ã  r�   r%   r&   ©r!   r"   r#   r¬   r&   r&   r(   Úmkstemp  ó   €r¯   úbytes | Noneútuple[int, bytes]c                 Ã  r�   r%   r&   r®   r&   r&   r(   r¯     r°   r¡   útuple[int, str | bytes]c                 Ã  s   �t  tj| |||¡I dH 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   r7   r3   r¯   r®   r&   r&   r(   r¯     s   €r�   c                 Ã  r�   r%   r&   r£   r&   r&   r(   Úmkdtemp0  ó   €r´   r   c                 Ã  r�   r%   r&   r£   r&   r&   r(   r´   8  rµ   ústr | bytesc                 Ã  s   �t  tj| ||¡I dH 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   r7   r3   r´   r£   r&   r&   r(   r´   @  s   €c                   Ã  ó   �t  tj¡I dH 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   r7   r3   Ú
gettempdirr&   r&   r&   r(   r¸   S  ó   €	r¸   c                   Ã  r·   )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   r3   Úgettempdirbr&   r&   r&   r(   rº   _  r¹   rº   )NNNF)
r!   r   r"   r   r#   r   r¬   rT   r/   r­   )
r!   r±   r"   r±   r#   r±   r¬   rT   r/   r²   )
r!   r¡   r"   r¡   r#   r¡   r¬   rT   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   )%Ú
__future__r   rœ   r]   r3   Úcollections.abcr   Úior   r   Útypesr   Útypingr   r   r	   r
   r   Ú r   Z_core._fileior   Zlowlevelr   Z	_typeshedr   r   r   r   r   rP   rc   rŸ   r¯   r´   r¸   rº   r&   r&   r&   r(   Ú<module>   sf    _d kBüü	üýýý
