Ë
    oPêjÂ  ã                  ó  — d dl mZ dZd dlZd dlmZmZmZ d dlm	Z	m
Z
 d dlmZmZ ddlmZmZmZmZ dd	lmZmZmZmZmZmZ ej4                  d
k\  rd dlmZ nd dlmZ  e	d¬«       G d„ de«      «       Z G d„ dee«      Z G d„ de«      Zy)é    )Úannotations)ÚBufferedByteReceiveStreamÚBufferedByteStreamÚBufferedConnectableN)ÚCallableÚIterableÚMapping)Ú	dataclassÚfield)ÚAnyÚSupportsIndexé   )ÚClosedResourceErrorÚDelimiterNotFoundÚEndOfStreamÚIncompleteRead)ÚAnyByteReceiveStreamÚAnyByteStreamÚAnyByteStreamConnectableÚByteReceiveStreamÚ
ByteStreamÚByteStreamConnectable)é   é   )ÚoverrideF)Ú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„Zddd„Zdd„Zdd„Zy)r   z’
    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    ú[/home/oem/CyberBrain26-unified/.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*   r1   z*BufferedByteReceiveStream.extra_attributes2   s   € à×"Ñ"×3Ñ3Ð3r.   c               ó:   — | j                   j                  |«       y)a;  
        Append data directly into the buffer.

        Any data in the buffer will be consumed by receive operations before receiving
        anything from the wrapped stream.

        :param data: the data to append to the buffer (can be bytes or anything else
            that supports ``__index__()``)

        N)r"   Úextend)r)   Údatas     r*   Ú	feed_dataz#BufferedByteReceiveStream.feed_data6   s   € ð 	�‰×Ñ˜DÕ!r.   c              ƒ  óî  K  — |dk  rt        d«      ‚| j                  rt        ‚| j                  r)t	        | j                  d | «      }| j                  d |…= |S t        | j                  t        «      r#| j                  j                  |«      ƒ d {  –—† S 	 | j                  j                  «       ƒ d {  –—† x}rnŒ&t        |«      |kD  r#| j                  j                  ||d  «       |d | S |S 7 Œ^7 Œ=­w)Né   z$max_bytes must be a positive integer)Ú
ValueErrorr%   r   r"   r,   Ú
isinstancer   r   ÚreceiveÚlenr3   )r)   Ú	max_bytesÚchunks      r*   r:   z!BufferedByteReceiveStream.receiveC   sò   è ø€ Ø�qŠ=ÜÐCÓDÐDà�<Š<Ü%Ð%à�<Š<Ü˜$Ÿ,™, z¨	Ð2Ó3ˆEØ—‘˜Z˜i˜ZÐ(ØˆLÜ˜×+Ñ+Ô->Ô?Ø×,Ñ,×4Ñ4°YÓ?×?Ð?ð Ø"&×"5Ñ"5×"=Ñ"=Ó"?×?Ð?�5Ð?Øð ô �5‹z˜IÒ%à—‘×#Ñ# E¨)¨*Ð$5Ô6Ø˜Z˜iÐ(Ð(à�ð @øð
 @ús$   ‚BC5ÂC1Â"C5Â5C3Â6<C5Ã3C5c              ƒ  óî  K  — | j                   rt        ‚	 |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
        :raises ~anyio.ClosedResourceError: if this stream has been explicitly closed

        r   N)r%   r   r;   r"   r,   r9   r   r   r:   r   r   r3   )r)   ÚnbytesÚ	remainingÚretvalr=   Úexcs         r*   Úreceive_exactlyz)BufferedByteReceiveStream.receive_exactly^   sÜ   è ø€ ð �<Š<Ü%Ð%àØ¤ T§\¡\Ó!2Ñ2ˆIØ˜AŠ~ØŸ™ g vÐ.�Ø—L‘L  & Ð)Ü˜V“}Ð$ð.Ü˜d×1Ñ1Ô3DÔEØ"&×"5Ñ"5×"=Ñ"=¸iÓ"H×H‘Eà"&×"5Ñ"5×"=Ñ"=Ó"?×?�Eð �L‰L×Ñ Ô&ð ð Iøà?ùÜò .Ü$¨#Ð-ûð.üsN   ‚AC5Á8C ÂCÂ"C Â8CÂ9C Â=C5ÃC ÃC Ã	C2Ã&C-Ã-C2Ã2C5c              ƒ  ó8  K  — | j                   rt        ‚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)a£  
        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
        :raises ~anyio.ClosedResourceError: if this stream has been explicitly closed

        r   Nr7   )r%   r   r;   r"   Úfindr,   r   r   r:   r   r   Úmaxr3   )	r)   Ú	delimiterr<   Údelimiter_sizeÚoffsetÚindexÚfoundr4   rB   s	            r*   Úreceive_untilz'BufferedByteReceiveStream.receive_until}   s  è ø€ ð �<Š<Ü%Ð%ä˜Y›ˆØˆØà—L‘L×%Ñ% i°Ó8ˆEØ˜ŠzØŸ™ V eÐ,�Ø—L‘LÐ!; 5¬3¨y«>Ñ#9Ð!;Ð<Ü˜U“|Ð#ô �4—<‘<Ó  IÒ-Ü'¨	Ó2Ð2ð.Ø!×0Ñ0×8Ñ8Ó:×:�ô
 œ˜TŸ\™\Ó*¨^Ñ;¸aÑ?ÀÓCˆFØ�L‰L×Ñ Ô%ð) ð ;ùÜò .Ü$¨#Ð-ûð.üs=   ‚BDÂD Â:D Â;D Â?ADÄ D Ä	DÄDÄDÄDN©ÚreturnÚNone)rN   r,   )rN   zMapping[Any, Callable[[], Any]])r4   zIterable[SupportsIndex]rN   rO   )i   )r<   ÚintrN   r,   )r?   rP   rN   r,   )rG   r,   r<   rP   rN   r,   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r!   r"   r%   r'   Úpropertyr-   r1   r5   r:   rC   rL   © r.   r*   r   r      sr   … ñð
 )Ó(Ù E¸9ÔE€GˆYÓEÙ˜u¨eÔ4€GˆTÓ4óð ò#ó ð#ð ò4ó ð4ó"ôó6'ô>(&r.   r   c                  óH   ‡ — e Zd ZdZdˆ fd„Zedd„«       Zedd„«       Zˆ xZS )r   z…
    A full-duplex variant of :class:`BufferedByteReceiveStream`. All writes are passed
    through to the wrapped stream as-is.
    c                ó2   •— t         ‰| �  |«       || _        y)z:
        :param stream: the stream to be wrapped

        N)ÚsuperÚ__init__Ú_stream)r)   ÚstreamÚ	__class__s     €r*   r[   zBufferedByteStream.__init__®   s   ø€ ô
 	‰Ñ˜Ô Øˆ�r.   c              ƒ  óT   K  — | j                   j                  «       ƒ d {  –—†  y 7 Œ­wr0   )r\   Úsend_eofr(   s    r*   r`   zBufferedByteStream.send_eof¶   s   è ø€ à�l‰l×#Ñ#Ó%×%Ò%ús   ‚( &¡(c              ƒ  óV   K  — | j                   j                  |«      ƒ d {  –—†  y 7 Œ­wr0   )r\   Úsend)r)   Úitems     r*   rb   zBufferedByteStream.sendº   s   è ø€ à�l‰l×Ñ Ó%×%Ò%ús   ‚)¡'¢))r]   r   rM   )rc   r,   rN   rO   )	rQ   rR   rS   rT   r[   r   r`   rb   Ú__classcell__)r^   s   @r*   r   r   ¨   s5   ø„ ñõ
ð ò&ó ð&ð ò&ó ô&r.   r   c                  ó*   — e Zd ZdZdd„Zedd„«       Zy)r   aw  
    Wraps a byte stream connectable to produce :class:`BufferedByteStream` connections.

    Use this when you want the streams returned by :meth:`connect` to have the buffered
    receive API (e.g. :meth:`~BufferedByteReceiveStream.receive_exactly` and
    :meth:`~BufferedByteReceiveStream.receive_until`).

    :param connectable: the byte stream connectable to wrap
    c                ó   — || _         y)z>
        :param connectable: the connectable to wrap

        N)Úconnectable)r)   rg   s     r*   r[   zBufferedConnectable.__init__Ê   s   € ð
 'ˆÕr.   c              ƒ  óh   K  — | j                   j                  «       ƒ d {  –—† }t        |«      S 7 Œ­wr0   )rg   Úconnectr   )r)   r]   s     r*   ri   zBufferedConnectable.connectÑ   s-   è ø€ à×'Ñ'×/Ñ/Ó1×1ˆÜ! &Ó)Ð)ð 2ús   ‚2 0¡2N)rg   r   )rN   r   )rQ   rR   rS   rT   r[   r   ri   rW   r.   r*   r   r   ¿   s    „ ñó'ð ò*ó ñ*r.   r   ) Ú
__future__r   Ú__all__ÚsysÚcollections.abcr   r   r	   Údataclassesr
   r   Útypingr   r   Ú r   r   r   r   Úabcr   r   r   r   r   r   Úversion_infor   Útyping_extensionsr   r   r   rW   r.   r*   ú<module>rt      s‡   ðÝ "ð€ó ß 7Ñ 7ß (ß %ç RÓ R÷÷ ð ×Ñ�wÒÞå*ñ ˆeÔôF&Ð 1ó F&ó ðF&ôR&Ð2°Jô &ô.*Ð/õ *r.   