Format: application/x-python-code
⬇ Download File (18.9 KB)
   1  o
   2  
   3  ;'h�L�@s�ddlmZddlZddlZddlZddlmZddlmZm	Z	ddl
   4  mZddlm
   5  Z
   6  mZmZmZmZddlmZdd	lmZdd
   7  lmZe
   8  rTddlmZmZmZmZGdd
   9  �d
  10  ee�ZGdd�dee�ZGdd�dee�ZGdd�dee�Z e				d0d1dd��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$dS):�)�annotationsN)�Iterable)�BytesIO�
  11  TextIOWrapper)�
  12  TracebackType)�
  13  TYPE_CHECKING�Any�AnyStr�Generic�overload�)�	to_thread)�	AsyncFile)�checkpoint_if_cancelled)�OpenBinaryMode�OpenTextMode�ReadableBuffer�WriteableBufferc@s�eZdZUdZded<e							d)dd�d*dd��Ze						d+dd�d,dd��Z							d-dd�d.dd�Zd/dd �Zd0d'd(�ZdS)1�
  14  TemporaryFilea�
  15      An asynchronous temporary file that is automatically created and cleaned up.
  16  
  17      This class provides an asynchronous context manager interface to a temporary file.
  18      The file is created using Python's standard `tempfile.TemporaryFile` function in a
  19      background thread, and is wrapped as an asynchronous file using `AsyncFile`.
  20  
  21      :param mode: The mode in which the file is opened. Defaults to "w+b".
  22      :param buffering: The buffering policy (-1 means the default buffering).
  23      :param encoding: The encoding used to decode or encode the file. Only applicable in
  24          text mode.
  25      :param newline: Controls how universal newlines mode works (only applicable in text
  26          mode).
  27      :param suffix: The suffix for the temporary file name.
  28      :param prefix: The prefix for the temporary file name.
  29      :param dir: The directory in which the temporary file is created.
  30      :param errors: The error handling scheme used for encoding/decoding errors.
  31      �AsyncFile[AnyStr]�_async_file.��errors�self�TemporaryFile[bytes]�moder�	buffering�int�encoding�
  32  str | None�newline�suffix�prefix�dirrc	C�dS�N��	rrrrr r!r"r#rr&r&�KC:\Users\shubh\Videos\agent\nova\Lib\site-packages\anyio/_core/_tempfile.py�__init__/�zTemporaryFile.__init__�TemporaryFile[str]rc	Cr$r%r&r'r&r&r(r)<r*�w+b�����N�OpenTextMode | OpenBinaryMode�return�Nonec	Cs4||_||_||_||_||_||_||_||_dSr%�rrrr r!r"r#rr'r&r&r(r)Js
  33  c��*�t��fdd��IdH}t|��_�jS)Nc
  34  s*tj�j�j�j�j�j�j�j�j	d�S)Nr)
  35  �tempfilerrrrr r!r"r#rr&�rr&r(�<lambda>as�z*TemporaryFile.__aenter__.<locals>.<lambda>�r
  36  �run_syncrr�r�fpr&r4r(�
  37  __aenter___s�
  38  
  39  �
  40  zTemporaryFile.__aenter__�exc_type�type[BaseException] | None�	exc_value�BaseException | None�	traceback�TracebackType | Nonec���|j��IdHdSr%�r�aclose�rr;r=r?r&r&r(�	__aexit__o��zTemporaryFile.__aexit__�.......)rrrrrrrrr rr!rr"rr#rrr)......)rr+rrrrrrr rr!rr"rr#rrr)r,r-NNNNN)rr.rrrrr rr!rr"rr#rrrr/r0�r/r�r;r<r=r>r?r@r/r0�	�__name__�
  41  __module__�__qualname__�__doc__�__annotations__rr)r:rEr&r&r&r(rsH
  42  �
  43  ��
  44  ��
  45  �
  46  rc@s�eZdZUdZded<e								d-ddd�d.dd��Ze							d/ddd�d0dd��Z								d1ddd�d2d"d�Zd3d#d$�Zd4d+d,�ZdS)5�NamedTemporaryFilea|
  47      An asynchronous named temporary file that is automatically created and cleaned up.
  48  
  49      This class provides an asynchronous context manager for a temporary file with a
  50      visible name in the file system. It uses Python's standard
  51      :func:`~tempfile.NamedTemporaryFile` function and wraps the file object with
  52      :class:`AsyncFile` for asynchronous operations.
  53  
  54      :param mode: The mode in which the file is opened. Defaults to "w+b".
  55      :param buffering: The buffering policy (-1 means the default buffering).
  56      :param encoding: The encoding used to decode or encode the file. Only applicable in
  57          text mode.
  58      :param newline: Controls how universal newlines mode works (only applicable in text
  59          mode).
  60      :param suffix: The suffix for the temporary file name.
  61      :param prefix: The prefix for the temporary file name.
  62      :param dir: The directory in which the temporary file is created.
  63      :param delete: Whether to delete the file when it is closed.
  64      :param errors: The error handling scheme used for encoding/decoding errors.
  65      :param delete_on_close: (Python 3.12+) Whether to delete the file on close.
  66      rr.)r�delete_on_closer�NamedTemporaryFile[bytes]rrrrrrr r!r"r#�delete�boolrrQc	Cr$r%r&�rrrrr r!r"r#rSrrQr&r&r(r)��zNamedTemporaryFile.__init__�NamedTemporaryFile[str]rc	Cr$r%r&rUr&r&r(r)�rVr,r-NT�OpenBinaryMode | OpenTextModer/r0c	
  67  Cs6|||||||||	d�	|_tjdkr|
  68  |jd<dSdS)N)	rrrr r!r"r#rSr���rQ)�_params�sys�version_inforUr&r&r(r)�s�
  69  �c�r2)Nc�tjdi�j��S�Nr&)r3rPr\r&r4r&r(r5��z/NamedTemporaryFile.__aenter__.<locals>.<lambda>r6r8r&r4r(r:�s�
  70  
  71  �
  72  zNamedTemporaryFile.__aenter__r;r<r=r>r?r@c�rAr%rBrDr&r&r(rE�rFzNamedTemporaryFile.__aexit__�........)rrRrrrrrrr rr!rr"rr#rrSrTrrrQrTrG)rrWrrrrrrr rr!rr"rr#rrSrTrrrQrT)r,r-NNNNNT)rrXrrrrr rr!rr"rr#rrSrTrrrQrTr/r0rHrIrJr&r&r&r(rPxsT
  73  ������
  74  rPcs�eZdZUdZdZded<e								dTdd�dUdd��Ze								dTdd�dVdd��Z								dWdd�dX�fd!d�ZdY�fd"d#�ZdYd$d%�Z	dYd&d'�Z
  75  edZd(d)��Zd[d\�fd,d-�
  76  Z
  77  d[d]�fd/d0�
  78  Zd^�fd1d2�Zd_�fd4d5�Zd`�fd8d9�Zd`�fd:d;�Zejfda�fd?d@�
  79  Zdb�fdAdB�Zdcdd�fdCdD�
  80  ZededFdG��ZedfdIdG��Zdg�fdKdG�ZedhdNdO��ZedidQdO��Zdj�fdSdO�Z�ZS)k�SpooledTemporaryFilea�
  81      An asynchronous spooled temporary file that starts in memory and is spooled to disk.
  82  
  83      This class provides an asynchronous interface to a spooled temporary file, much like
  84      Python's standard :class:`~tempfile.SpooledTemporaryFile`. It supports asynchronous
  85      write operations and provides a method to force a rollover to disk.
  86  
  87      :param max_size: Maximum size in bytes before the file is rolled over to disk.
  88      :param mode: The mode in which the file is opened. Defaults to "w+b".
  89      :param buffering: The buffering policy (-1 means the default buffering).
  90      :param encoding: The encoding used to decode or encode the file (text mode only).
  91      :param newline: Controls how universal newlines mode works (text mode only).
  92      :param suffix: The suffix for the temporary file name.
  93      :param prefix: The prefix for the temporary file name.
  94      :param dir: The directory in which the temporary file is created.
  95      :param errors: The error handling scheme used for encoding/decoding errors.
  96      FrT�_rolled.rr�SpooledTemporaryFile[bytes]�max_sizerrrrrrr r!r"r#rc	
  97  Cr$r%r&�
  98  rrfrrrr r!r"r#rr&r&r(r)��
  99  zSpooledTemporaryFile.__init__�SpooledTemporaryFile[str]rc	
 100  Cr$r%r&rgr&r&r(r)�rhrr,r-NrXr/r0c	
 101  	sX||||||||	d�|_||_d|vrt��t��dSt��tt�||	|dd��dS)Nr1�bT)rrr �
 102  write_through)�_tempfile_params�	_max_size�superr)rrrg��	__class__r&r(r)s*�
 103  ��c�s*�|js|j��dSt���IdHdSr%)rd�_fp�closernrCr4ror&r(rC3s
 104  �
 105  zSpooledTemporaryFile.aclosec�s.�|js|j��|jkrdS|��IdHdSr%)rdrq�tellrm�rolloverr4r&r&r(�_check:s�zSpooledTemporaryFile._checkc�s\��jrdSd�_�j}|�d�t��fdd��IdH�_��|���IdH|��dS)NTrcr_r`)r3rrlr&r4r&r(r5Hraz/SpooledTemporaryFile.rollover.<locals>.<lambda>)rdrq�seekr
 106  r7�write�readrr)r�bufferr&r4r(rt@s�
 107  
 108  �zSpooledTemporaryFile.rollovercCs|jjSr%)rq�closedr4r&r&r(rzMszSpooledTemporaryFile.closed�sizer	c��2�|jst�IdH|j�|�St��|�IdHSr%)rdrrqrxrn�rr{ror&r(rxQ�
 109  �zSpooledTemporaryFile.read�bytesc�r|r%)rdrrq�read1rnr}ror&r(r�Xr~zSpooledTemporaryFile.read1c��.�|jst�IdH|j��St���IdHSr%)rdrrq�readlinernr4ror&r(r�_�
 110  �
 111  zSpooledTemporaryFile.readline�list[AnyStr]c�r�r%)rdrrq�	readlinesrnr4ror&r(r�fr�zSpooledTemporaryFile.readlinesrjrc�s2�|jst�IdH|j�|�t��|�IdHSr%)rdrrq�readintorn�rrjror&r(r�mr~zSpooledTemporaryFile.readintoc�s2�|jst�IdH|j�|�t��|�IdHSr%)rdrrqr�rn�	readinto1r�ror&r(r�tr~zSpooledTemporaryFile.readinto1�offset�whence�
 112  int | Nonec�s6�|jst�IdH|j�||�St��||�IdHSr%)rdrrqrvrn)rr�r�ror&r(rv{s
 113  �zSpooledTemporaryFile.seekc�r�r%)rdrrqrsrnr4ror&r(rs�r�zSpooledTemporaryFile.tellc�r|r%)rdrrq�truncaternr}ror&r(r��r~zSpooledTemporaryFile.truncaterc���dSr%r&r�r&r&r(rw���zSpooledTemporaryFile.write�strc�r�r%r&r�r&r&r(rw�r��ReadableBuffer | strc��D�|jst�IdH|j�|�}|��IdH|St��|�IdHS)a�
 114          Asynchronously write data to the spooled temporary file.
 115  
 116          If the file has not yet been rolled over, the data is written synchronously,
 117          and a rollover is triggered if the size exceeds the maximum size.
 118  
 119          :param s: The data to write.
 120          :return: The number of bytes written.
 121          :raises RuntimeError: If the underlying file is not initialized.
 122  
 123          N)rdrrqrwrurn)rrj�resultror&r(rw�s��lines�Iterable[ReadableBuffer]c�r�r%r&�rr�r&r&r(�
 124  writelines���zSpooledTemporaryFile.writelines�
 125  Iterable[str]c�r�r%r&r�r&r&r(r��r��(Iterable[str] | Iterable[ReadableBuffer]c�r�)aw
 126          Asynchronously write a list of lines to the spooled temporary file.
 127  
 128          If the file has not yet been rolled over, the lines are written synchronously,
 129          and a rollover is triggered if the size exceeds the maximum size.
 130  
 131          :param lines: An iterable of lines to write.
 132          :raises RuntimeError: If the underlying file is not initialized.
 133  
 134          N)rdrrqr�rurn)rr�r�ror&r(r��s�rb)rrerfrrrrrrrr rr!rr"rr#rrr)rrirfrrrrrrrr rr!rr"rr#rrr)rr,r-NNNNN)rfrrrXrrrrr rr!rr"rr#rrrr/r0�r/r0)r/rT)r-)r{rr/r	)rrer{rr/r)r/r	)r/r�)rrerjrr/r)r�rr�r�r/r)r/rr%)r{r�r/r)rrerjrr/r)rrirjr�r/r)rjr�r/r)rrer�r�r/r0)rrir�r�r/r0)r�r�r/r0)rKrLrMrNrdrOrr)rCrurt�propertyrzrxr�r�r�r�r��os�SEEK_SETrvrsr�rwr��
 135  __classcell__r&r&ror(rc�s|
 136  ��
 137  ����%
 138  
 139  
 140  rcc@sHeZdZdZ			dddd�ddd�Zd dd�Zd!dd�Zd"dd�ZdS)#�TemporaryDirectorya�
 141      An asynchronous temporary directory that is created and cleaned up automatically.
 142  
 143      This class provides an asynchronous context manager for creating a temporary
 144      directory. It wraps Python's standard :class:`~tempfile.TemporaryDirectory` to
 145      perform directory creation and cleanup operations in a background thread.
 146  
 147      :param suffix: Suffix to be added to the temporary directory name.
 148      :param prefix: Prefix to be added to the temporary directory name.
 149      :param dir: The parent directory where the temporary directory is created.
 150      :param ignore_cleanup_errors: Whether to ignore errors during cleanup
 151          (Python 3.10+).
 152      :param delete: Whether to delete the directory upon closing (Python 3.12+).
 153      NFT)�ignore_cleanup_errorsrSr!�
 154  AnyStr | Noner"r#r�rTrSr/r0cCs(||_||_||_||_||_d|_dSr%)r!r"r#r�rS�_tempdir)rr!r"r#r�rSr&r&r(r)�s	
 155  zTemporaryDirectory.__init__r�c�sj�|j|j|jd��tjdkr|j�d<tjdkr|j�d<t��fdd��IdH|_	t�|j	j
 156  �IdHS)N�r!r"r#)rZ�
 157  r�rYrScstjdi���Sr`)r3r�r&��paramsr&r(r5�sz/TemporaryDirectory.__aenter__.<locals>.<lambda>)r!r"r#r]r^r�rSr
 158  r7r��	__enter__r4r&r�r(r:�s��
 159  
 160  
 161  
 162  
 163  �zTemporaryDirectory.__aenter__r;r<r=r>r?r@c�s.�|jdurt�|jj|||�IdHdSdSr%)r�r
 164  r7�__exit__rDr&r&r(rE�s�
 165  ��zTemporaryDirectory.__aexit__c�s(�|jdurt�|jj�IdHdSdSr%)r�r
 166  r7�cleanupr4r&r&r(r�s�
 167  �zTemporaryDirectory.cleanup�NNN)r!r�r"r�r#r�r�rTrSrTr/r0�r/r�rIr�)rKrLrMrNr)r:rEr�r&r&r&r(r��s��
 168  
 169  r�Fr!rr"r#�textrTr/�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�tj||||�IdHS)a�
 170      Asynchronously create a temporary file and return an OS-level handle and the file
 171      name.
 172  
 173      This function wraps `tempfile.mkstemp` and executes it in a background thread.
 174  
 175      :param suffix: Suffix to be added to the file name.
 176      :param prefix: Prefix to be added to the file name.
 177      :param dir: Directory in which the temporary file is created.
 178      :param text: Whether the file is opened in text mode.
 179      :return: A tuple containing the file descriptor and the file name.
 180  
 181      N)r
 182  r7r3r�r�r&r&r(r�s�r�c�r�r%r&r�r&r&r(�mkdtemp0��r�rc�r�r%r&r�r&r&r(r�8r��str | bytesc�s�t�tj|||�IdHS)a�
 183      Asynchronously create a temporary directory and return its path.
 184  
 185      This function wraps `tempfile.mkdtemp` and executes it in a background thread.
 186  
 187      :param suffix: Suffix to be added to the directory name.
 188      :param prefix: Prefix to be added to the directory name.
 189      :param dir: Parent directory where the temporary directory is created.
 190      :return: The path of the created temporary directory.
 191  
 192      N)r
 193  r7r3r�r�r&r&r(r�@s�c���t�tj�IdHS)z�
 194      Asynchronously return the name of the directory used for temporary files.
 195  
 196      This function wraps `tempfile.gettempdir` and executes it in a background thread.
 197  
 198      :return: The path of the temporary directory as a string.
 199  
 200      N)r
 201  r7r3�
 202  gettempdirr&r&r&r(r�S��	r�c�r�)z�
 203      Asynchronously return the name of the directory used for temporary files in bytes.
 204  
 205      This function wraps `tempfile.gettempdirb` and executes it in a background thread.
 206  
 207      :return: The path of the temporary directory as bytes.
 208  
 209      N)r
 210  r7r3�gettempdirbr&r&r&r(r�_r�r�)NNNF)
 211  r!rr"rr#rr�rTr/r�)
 212  r!r�r"r�r#r�r�rTr/r�)
 213  r!r�r"r�r#r�r�rTr/r�r�)r!rr"rr#rr/r�)r!r�r"r�r#r�r/r)r!r�r"r�r#r�r/r�r�)r/r)%�
 214  __future__rr�r]r3�collections.abcr�iorr�typesr�typingrrr	r
 215  r�r
 216  Z
 217  _core._fileiorZlowlevelrZ	_typeshedrrrrrrPrcr�r�r�r�r�r&r&r&r(�<module>sf_dkB��	����
 218