
    Mh                        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	           G d
 de                      ZdS )    )annotations)CallableMapping)	dataclassfield)Any   )ClosedResourceErrorDelimiterNotFoundEndOfStreamIncompleteRead)AnyByteReceiveStreamByteReceiveStreamF)eqc                      e Zd ZU dZded<    ede          Zded<    edd          Zd	ed
<   ddZ	e
dd            Ze
dd            ZdddZd dZ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                V   K   | j                                          d {V  d| _        d S )NT)r   acloser   selfs    V/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/anyio/streams/buffered.pyr   z BufferedByteReceiveStream.aclose   s8      !((*********    bytesc                *    t          | j                  S )z"The bytes currently in the buffer.)r#   r   r   s    r!   bufferz BufferedByteReceiveStream.buffer   s     T\"""r"   Mapping[Any, Callable[[], Any]]c                    | j         j        S N)r   extra_attributesr   s    r!   r)   z*BufferedByteReceiveStream.extra_attributes   s    "33r"      	max_bytesintc                  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)
r0   r   r#   r.   r   r   r/   r   r   r1   )r    r3   	remainingretvalr2   excs         r!   receive_exactlyz)BufferedByteReceiveStream.receive_exactly8   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   )r0   r   findr#   r   r   r/   r   r   maxr1   )	r    r9   r+   delimiter_sizeoffsetindexfounddatar7   s	            r!   receive_untilz'BufferedByteReceiveStream.receive_untilS   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N)r   r   )r   r#   )r   r&   )r*   )r+   r,   r   r#   )r3   r,   r   r#   )r9   r#   r+   r,   r   r#   )__name__
__module____qualname____doc____annotations__r   r   r   r   r   propertyr%   r)   r/   r8   rC    r"   r!   r   r      s         
 )(((E9EEEGEEEEEue444G4444    # # # X# 4 4 4 X4    *' ' ' '6$& $& $& $& $& $&r"   r   N)
__future__r   collections.abcr   r   dataclassesr   r   typingr    r
   r   r   r   abcr   r   r   rJ   r"   r!   <module>rQ      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"   