Format: application/x-python-code
⬇ Download File (4.0 KB)
   1  o
   2  
   3  ;'h��@s~ddlmZddlmZmZddlmZmZddlm	Z	ddl
   4  mZmZm
   5  Z
   6  mZddlmZmZedd	�Gd
   7  d�de��ZdS)
   8  �)�annotations)�Callable�Mapping)�	dataclass�field)�Any�)�ClosedResourceError�DelimiterNotFound�EndOfStream�IncompleteRead)�AnyByteReceiveStream�ByteReceiveStreamF)�eqc@s�eZdZUdZded<eded�Zded<eddd�Zd	ed
   9  <d!d
  10  d�Z	e
  11  d"dd��Ze
  12  d#dd��Zd$d%dd�Z
  13  d&dd�Zd'dd�Zd S)(�BufferedByteReceiveStreamz�
  14      Wraps any bytes-based receive stream and uses a buffer to provide sophisticated
  15      receiving capabilities in the form of a byte stream.
  16      r
  17  �receive_streamF)�init�default_factory�	bytearray�_buffer)r�default�bool�_closed�return�Nonec�s�|j��IdHd|_dS)NT)r�acloser��self�r�LC:\Users\shubh\Videos\agent\nova\Lib\site-packages\anyio/streams/buffered.pyrs�
  18  z BufferedByteReceiveStream.aclose�bytescCs
  19  t|j�S)z"The bytes currently in the buffer.)r rrrrr�buffers
  20  z BufferedByteReceiveStream.buffer�Mapping[Any, Callable[[], Any]]cCs|jjS�N)r�extra_attributesrrrrr$sz*BufferedByteReceiveStream.extra_attributes��	max_bytes�intc�s��|jrt�|jrt|jd|��}|jd|�=|St|jt�r)|j�|�IdHS|j��IdH}t|�|krG|j�	||d��|d|�S|Sr#)
  21  rr	rr �
  22  isinstancerr�receive�len�extend)rr&�chunkrrrr)#s�z!BufferedByteReceiveStream.receive�nbytesc
  23  �s��	|t|j�}|dkr|jd|�}|jd|�=t|�Szt|jt�r/|j�|�IdH}n|j��IdH}WntyG}zt|�d}~ww|j�	|�q)a-
  24          Read exactly the given amount of bytes from the stream.
  25  
  26          :param nbytes: the number of bytes to read
  27          :return: the bytes read
  28          :raises ~anyio.IncompleteRead: if the stream was closed before the requested
  29              amount of bytes could be read from the stream
  30  
  31          TrN)
  32  r*rr r(rrr)rrr+)rr-�	remaining�retvalr,�excrrr�receive_exactly8s$�
  33  ����z)BufferedByteReceiveStream.receive_exactly�	delimiterc	
  34  �s��t|�}d}	|j�||�}|dkr(|jd|�}|jd|t|��=t|�St|j�|kr3t|��z
  35  |j��IdH}WntyL}zt|�d}~wwt	t|j�|dd�}|j�
  36  |�q)aM
  37          Read from the stream until the delimiter is found or max_bytes have been read.
  38  
  39          :param delimiter: the marker to look for in the stream
  40          :param max_bytes: maximum number of bytes that will be read before raising
  41              :exc:`~anyio.DelimiterNotFound`
  42          :return: the bytes read (not including the delimiter)
  43          :raises ~anyio.IncompleteRead: if the stream was closed before the delimiter
  44              was found
  45          :raises ~anyio.DelimiterNotFound: if the delimiter is not found within the
  46              bytes read up to the maximum allowed
  47  
  48          rTN�)r*r�findr r
  49  rr)rr�maxr+)	rr2r&Zdelimiter_size�offset�index�found�datar0rrr�
  50  receive_untilSs(����z'BufferedByteReceiveStream.receive_untilN)rr)rr )rr")r%)r&r'rr )r-r'rr )r2r r&r'rr )�__name__�
  51  __module__�__qualname__�__doc__�__annotations__rrrrr�propertyr!r$r)r1r:rrrrrs
  52  
  53  
  54  rN)�
  55  __future__r�collections.abcrr�dataclassesrr�typingr�r	r
  56  rr�abcr
  57  rrrrrr�<module>s