o
    ;'h”  ã                   @  s~   d dl mZ d dlmZ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 ddlmZmZ edd	�G d
d„ deƒƒZdS )é    )Úannotations)ÚCallableÚMapping)Ú	dataclassÚfield)ÚAnyé   )ÚClosedResourceErrorÚDelimiterNotFoundÚEndOfStreamÚIncompleteRead)ÚAnyByteReceiveStreamÚByteReceiveStreamF)Úeqc                   @  sˆ   e Zd ZU dZded< eded�Zded< eddd�Zd	ed
< d!dd„Z	e
d"dd„ƒZe
d#dd„ƒZd$d%dd„Zd&dd„Zd'dd„Zd S )(ÚBufferedByteReceiveStreamz’
    Wraps any bytes-based receive stream and uses a buffer to provide sophisticated
    receiving capabilities in the form of a byte stream.
    r   Úreceive_streamF)ÚinitÚdefault_factoryÚ	bytearrayÚ_buffer)r   ÚdefaultÚboolÚ_closedÚreturnÚNonec                 Ã  s   �| j  ¡ I d H  d| _d S )NT)r   Úacloser   ©Úself© r   úLC:\Users\shubh\Videos\agent\nova\Lib\site-packages\anyio/streams/buffered.pyr      s   €
z BufferedByteReceiveStream.acloseÚbytesc                 C  s
   t | jƒS )z"The bytes currently in the buffer.)r    r   r   r   r   r   Úbuffer   s   
z BufferedByteReceiveStream.bufferúMapping[Any, Callable[[], Any]]c                 C  s   | j jS ©N)r   Úextra_attributesr   r   r   r   r$      s   z*BufferedByteReceiveStream.extra_attributesé   Ú	max_bytesÚintc                 Ã  s’   �| j rt‚| jrt| jd |… ƒ}| jd |…= |S t| jtƒr)| j |¡I d H S | j ¡ I d H }t|ƒ|krG| j 	||d … ¡ |d |… S |S r#   )
r   r	   r   r    Ú
isinstancer   r   ÚreceiveÚlenÚextend)r   r&   Úchunkr   r   r   r)   #   s   €z!BufferedByteReceiveStream.receiveÚnbytesc              
   Ã  sž   �	 |t | jƒ }|dkr| jd|… }| jd|…= t|ƒS zt| jtƒr/| j |¡I dH }n| j ¡ I dH }W n tyG } zt|‚d}~ww | j 	|¡ q)a-  
        Read exactly the given amount of bytes from the stream.

        :param nbytes: the number of bytes to read
        :return: the bytes read
        :raises ~anyio.IncompleteRead: if the stream was closed before the requested
            amount of bytes could be read from the stream

        Tr   N)
r*   r   r    r(   r   r   r)   r   r   r+   )r   r-   Ú	remainingÚretvalr,   Úexcr   r   r   Úreceive_exactly8   s$   €
€€ÿñz)BufferedByteReceiveStream.receive_exactlyÚ	delimiterc           	   
   Ã  sÀ   �t |ƒ}d}	 | j ||¡}|dkr(| jd|… }| jd|t |ƒ …= t|ƒS t | jƒ|kr3t|ƒ‚z
| j ¡ I dH }W n tyL } zt|‚d}~ww t	t | jƒ| d dƒ}| j 
|¡ q)aM  
        Read from the stream until the delimiter is found or max_bytes have been read.

        :param delimiter: the marker to look for in the stream
        :param max_bytes: maximum number of bytes that will be read before raising
            :exc:`~anyio.DelimiterNotFound`
        :return: the bytes read (not including the delimiter)
        :raises ~anyio.IncompleteRead: if the stream was closed before the delimiter
            was found
        :raises ~anyio.DelimiterNotFound: if the delimiter is not found within the
            bytes read up to the maximum allowed

        r   TNé   )r*   r   Úfindr    r
   r   r)   r   r   Úmaxr+   )	r   r2   r&   Zdelimiter_sizeÚoffsetÚindexÚfoundÚdatar0   r   r   r   Úreceive_untilS   s(   €€ÿìz'BufferedByteReceiveStream.receive_untilN)r   r   )r   r    )r   r"   )r%   )r&   r'   r   r    )r-   r'   r   r    )r2   r    r&   r'   r   r    )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r   r   r   r   Úpropertyr!   r$   r)   r1   r:   r   r   r   r   r      s   
 

r   N)Ú
__future__r   Úcollections.abcr   r   Údataclassesr   r   Útypingr   Ú r	   r
   r   r   Úabcr   r   r   r   r   r   r   Ú<module>   s    