
    ,h                        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y)    )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y)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_closedc                b   K   | j                   j                          d {    d| _        y 7 w)NT)r   acloser   selfs    X/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/anyio/streams/buffered.pyr   z BufferedByteReceiveStream.aclose   s*     !!((*** 	+s   /-/c                ,    t        | j                        S )z"The bytes currently in the buffer.)bytesr   r   s    r   bufferz BufferedByteReceiveStream.buffer   s     T\\""    c                .    | j                   j                  S N)r   extra_attributesr   s    r   r&   z*BufferedByteReceiveStream.extra_attributes   s    ""333r#   c                  K   | j                   rt        | j                  r)t        | j                  d |       }| j                  d |= |S t	        | j
                  t              r#| j
                  j                  |       d {   S | j
                  j                          d {   }t        |      |kD  r#| j                  j                  ||d         |d | S |S 7 Y7 9wr%   )
r   r
   r   r!   
isinstancer   r   receivelenextend)r   	max_byteschunks      r   r)   z!BufferedByteReceiveStream.receive#   s     <<%%<<$,,z	23EZiZ(L++->?,,44Y??? --5577E5zI%##E)*$56Zi(( @ 8s$   B C C!C $C%8C C c                  K   	 |t        | j                        z
  }|dk  r)| j                  d| }| j                  d|= t        |      S 	 t        | j                  t
              r$| j                  j                  |       d{   }n"| j                  j                          d{   }| j                  j                  |       7 C7 "# t        $ r}t        |d}~ww xY ww)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

        r   N)
r*   r   r!   r(   r   r   r)   r   r   r+   )r   nbytes	remainingretvalr-   excs         r   receive_exactlyz)BufferedByteReceiveStream.receive_exactly8   s      T\\!22IA~gv.LL&)V}$.d113DE"&"5"5"="=i"HHE"&"5"5"="="??E LL&  I? .$#-.sN   AC#8C C"C &C	'C +C#C 	C 	C CC  C#c                  K   t        |      }d}	 | j                  j                  ||      }|dk\  r5| j                  d| }| j                  d|t        |      z   = t        |      S t        | j                        |k\  rt	        |      	 | j
                  j                          d{   }t        t        | j                        |z
  dz   d      }| j                  j                  |       7 E# t        $ r}t        |d}~ww xY ww)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   N   )r*   r   findr!   r   r   r)   r   r   maxr+   )	r   	delimiterr,   delimiter_sizeoffsetindexfounddatar2   s	            r   receive_untilz'BufferedByteReceiveStream.receive_untilS   s      YLL%%i8EzVe,LL!;53y>#9!;<U|# 4<< I-'	22.!0088::
 T\\*^;a?CFLL%)  ; .$#-.s=   BDC0 (C.)C0 -AD.C0 0	D9D  DDN)returnNone)r?   r!   )r?   zMapping[Any, Callable[[], Any]])i   )r,   intr?   r!   )r/   rA   r?   r!   )r8   r!   r,   rA   r?   r!   )__name__
__module____qualname____doc____annotations__r   r   r   r   r   propertyr"   r&   r)   r3   r>    r#   r   r   r      sm    
 )(E9EGYEue4GT4 # # 4 4*'6$&r#   r   N)
__future__r   collections.abcr   r   dataclassesr   r   typingr    r
   r   r   r   abcr   r   r   rH   r#   r   <module>rO      s>    " - (  R R 9 ek& 1 k& k&r#   