Ë
    éÿæiw  ã                  ó  — 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    úk/Volumes/fast/ai/experiments/voice-extract-mac/.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  — | 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r0   )
r%   r   r"   r,   Ú
isinstancer   r   ÚreceiveÚlenr3   )r)   Ú	max_bytesÚchunks      r*   r8   z!BufferedByteReceiveStream.receiveC   sË   è ø€ Ø�<Š<Ü%Ð%à�<Š<Ü˜$Ÿ,™, z¨	Ð2Ó3ˆEØ—‘˜Z˜i˜ZÐ(ØˆLÜ˜×+Ñ+Ô->Ô?Ø×,Ñ,×4Ñ4°YÓ?×?Ð?ð ×-Ñ-×5Ñ5Ó7×7ˆEÜ�5‹z˜IÒ%à—‘×#Ñ# E¨)¨*Ð$5Ô6Ø˜Z˜iÐ(Ð(à�ð @øð 8ús$   ‚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)
r9   r"   r,   r7   r   r   r8   r   r   r3   )r)   ÚnbytesÚ	remainingÚretvalr;   Úexcs         r*   Úreceive_exactlyz)BufferedByteReceiveStream.receive_exactlyX   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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é   )r9   r"   Úfindr,   r   r   r8   r   r   Úmaxr3   )	r)   Ú	delimiterr:   Údelimiter_sizeÚoffsetÚindexÚfoundr4   r@   s	            r*   Úreceive_untilz'BufferedByteReceiveStream.receive_untils   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ÂC0 Â(C.Â)C0 Â-ADÃ.C0 Ã0	DÃ9D Ä DÄDN©ÚreturnÚNone)rM   r,   )rM   zMapping[Any, Callable[[], Any]])r4   zIterable[SupportsIndex]rM   rN   )i   )r:   ÚintrM   r,   )r=   rO   rM   r,   )rF   r,   r:   rO   rM   r,   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r!   r"   r%   r'   Úpropertyr-   r1   r5   r8   rA   rK   © 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*   rZ   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*   ra   zBufferedByteStream.send¬   s   è ø€ à�l‰l×Ñ Ó%×%Ò%ús   ‚)¡'¢))r\   r   rL   )rb   r,   rM   rN   )	rP   rQ   rR   rS   rZ   r   r_   ra   Ú__classcell__)r]   s   @r*   r   r   š   s5   ø„ ñõ
ð ò&ó ð&ð ò&ó ô&r.   r   c                  ó&   — e Zd Zdd„Zedd„«       Zy)r   c                ó   — || _         y)z>
        :param connectable: the connectable to wrap

        N)Úconnectable)r)   rf   s     r*   rZ   zBufferedConnectable.__init__²   s   € ð
 'ˆÕr.   c              ƒ  óh   K  — | j                   j                  «       ƒ d {  –—† }t        |«      S 7 Œ­wr0   )rf   Úconnectr   )r)   r\   s     r*   rh   zBufferedConnectable.connect¹   s-   è ø€ à×'Ñ'×/Ñ/Ó1×1ˆÜ! &Ó)Ð)ð 2ús   ‚2 0¡2N)rf   r   )rM   r   )rP   rQ   rR   rZ   r   rh   rV   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   rV   r.   r*   Ú<module>rs      s‡   ðÝ "ð€ó ß 7Ñ 7ß (ß %ç RÓ R÷÷ ð ×Ñ�wÒÞå*ñ ˆeÔôx&Ð 1ó x&ó ðx&ôv&Ð2°Jô &ô.*Ð/õ *r.   