
    "dU                         d dl mZmZ d dlmZmZmZ ddlmZm	Z	m
Z
mZ ddlmZmZ  ed           G d d	e                      Zd
S )    )	dataclassfield)AnyCallableMapping   )ClosedResourceErrorDelimiterNotFoundEndOfStreamIncompleteRead)AnyByteReceiveStreamByteReceiveStreamF)eqc                       e Zd ZU dZeed<    ede          Zeed<    edd          Z	e
ed<   dd
Zedefd            Zedeeeg ef         f         fd            ZddedefdZdedefdZdededef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.
    receive_streamF)initdefault_factory_buffer)r   default_closedreturnNc                 V   K   | j                                          d {V  d| _        d S )NT)r   acloser   selfs    :D:\api_v1\venv\Lib\site-packages\anyio/streams/buffered.pyr   z BufferedByteReceiveStream.aclose   s8      !((*********    c                 *    t          | j                  S )z"The bytes currently in the buffer.)bytesr   r   s    r   bufferz BufferedByteReceiveStream.buffer   s     T\"""r   c                     | j         j        S N)r   extra_attributesr   s    r   r$   z*BufferedByteReceiveStream.extra_attributes   s    "33r      	max_bytesc                   K   | j         rt          | j        r(t          | j        d |                   }| j        d |= |S t	          | j        t                    r | j                            |           d {V S | j                                         d {V }t          |          |k    r,| j        	                    ||d                     |d |         S |S r#   )
r   r	   r   r    
isinstancer   r   receivelenextend)r   r&   chunks      r   r)   z!BufferedByteReceiveStream.receive    s      < 	&%%< 	$,z	z233EZiZ(L+->?? 	,44Y????????? -5577777777E5zzI%%##E)**$5666ZiZ((r   nbytesc                   K   	 |t          | j                  z
  }|dk    r(| j        d|         }| j        d|= t          |          S 	 t          | j        t
                    r!| j                            |           d{V }n| j                                         d{V }n# t          $ r}t          |d}~ww xY w| j        	                    |           )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,   excs         r   receive_exactlyz)BufferedByteReceiveStream.receive_exactly5   s     	'T\!2!22IA~~gvg.L&)V}}$.d13DEE @"&"5"="=i"H"HHHHHHHEE"&"5"="="?"???????E . . .$#-. L&&&	's   
AB% %
B</B77B<	delimiterc                 &  K   t          |          }d}	 | j                            ||          }|dk    r8| j        d|         }| j        d|t          |          z   = t          |          S t          | j                  |k    rt	          |          	 | j                                         d{V }n# t          $ r}t          |d}~ww xY wt          t          | j                  |z
  dz   d          }| j        
                    |           )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   r3   r&   delimiter_sizeoffsetindexfounddatar1   s	            r   receive_untilz'BufferedByteReceiveStream.receive_untilP   s-      Y	&L%%i88EzzVeV,L!;53y>>#9!;<U||# 4<  I--'	222.!088:::::::: . . .$#-. T\**^;a?CCFL%%%)	&s   B6 6
C CC)r   N)r%   )__name__
__module____qualname____doc__r   __annotations__r   	bytearrayr   r   boolr   propertyr    r!   r   r   r   r$   intr)   r2   r=    r   r   r   r      sS         
 )(((E9EEEGYEEEEue444GT444    # # # # X# 4'#xC/@*@"A 4 4 4 X4 s u    *'C 'E ' ' ' '6$&U $&s $&u $& $& $& $& $& $&r   r   N)dataclassesr   r   typingr   r   r    r	   r
   r   r   abcr   r   r   rG   r   r   <module>rL      s    ( ( ( ( ( ( ( ( ) ) ) ) ) ) ) ) ) ) R R R R R R R R R R R R 9 9 9 9 9 9 9 9 ek& k& k& k& k& 1 k& k& k& k& k&r   