HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/.local/lib/python3.10/site-packages/anyio/streams/__pycache__/buffered.cpython-310.pyc
o

���g��@s~ddlmZddlmZmZddlmZmZddlm	Z	ddl
mZmZm
Z
mZddlmZmZedd	�Gd
d�de��ZdS)
�)�annotations)�Callable�Mapping)�	dataclass�field)�Any�)�ClosedResourceError�DelimiterNotFound�EndOfStream�IncompleteRead)�AnyByteReceiveStream�ByteReceiveStreamF)�eqc@s�eZdZUdZded<eded�Zded<eddd�Zd	ed
<d!d
d�Z	e
d"dd��Ze
d#dd��Zd$d%dd�Z
d&dd�Zd'dd�Zd 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��IdHd|_dS)NT)r�acloser��self�r�I/home/arjun/.local/lib/python3.10/site-packages/anyio/streams/buffered.pyrs�
z BufferedByteReceiveStream.aclose�bytescCs
t|j�S)z"The bytes currently in the buffer.)r rrrrr�buffers
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#)
rr	rr �
isinstancerr�receive�len�extend)rr&�chunkrrrr)#s�z!BufferedByteReceiveStream.receive�nbytesc
�s��	|t|j�}|dkr|jd|�}|jd|�=t|�Szt|jt�r/|j�|�IdH}n|j��IdH}WntyG}zt|�d}~ww|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

        TrN)
r*rr r(rrr)rrr+)rr-�	remaining�retvalr,�excrrr�receive_exactly8s$�
����z)BufferedByteReceiveStream.receive_exactly�	delimiterc	
�s��t|�}d}	|j�||�}|dkr(|jd|�}|jd|t|��=t|�St|j�|kr3t|��z
|j��IdH}WntyL}zt|�d}~wwt	t|j�|dd�}|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

        rTN�)r*r�findr r
rr)rr�maxr+)	rr2r&�delimiter_size�offset�index�found�datar0rrr�
receive_untilSs(����z'BufferedByteReceiveStream.receive_untilN)rr)rr )rr")r%)r&r'rr )r-r'rr )r2r r&r'rr )�__name__�
__module__�__qualname__�__doc__�__annotations__rrrrr�propertyr!r$r)r1r;rrrrrs


rN)�
__future__r�collections.abcrr�dataclassesrr�typingr�r	r
rr�abcr
rrrrrr�<module>s