§
    #ˆtjZ  ã                  ó4  — 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j        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dS )é    )Ú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dS )&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Ú_closedÚreturnÚNonec              ƒ  óV   K  — | j                              ¦   «         ƒ d {V —† d| _        d S )NT)r   Úacloser%   ©Úselfs    úT/var/www/html/CA-Chatbot/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,   r4   z*BufferedByteReceiveStream.extra_attributes2   s   € àÔ"Ô3Ð3r-   ÚdataúIterable[SupportsIndex]c               ó:   — | j                              |¦  «         dS )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+   r5   s     r,   Ú	feed_dataz#BufferedByteReceiveStream.feed_data6   s    € ð 	Œ×Ò˜DÑ!Ô!Ð!Ð!Ð!r-   é   Ú	max_bytesÚintc              ƒ  óÞ  K  — |dk     rt          d¦  «        ‚| 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 )Né   z$max_bytes must be a positive integer)Ú
ValueErrorr%   r   r"   r.   Ú
isinstancer   r   ÚreceiveÚlenr8   )r+   r;   Úchunks      r,   rA   z!BufferedByteReceiveStream.receiveC   s  è è € Ø�qŠ=ˆ=ÝÐCÑDÔDÐDàŒ<ð 	&Ý%Ð%àŒ<ð 	Ý˜$œ, z¨	 zÔ2Ñ3Ô3ˆEØ”˜Z˜i˜ZÐ(ØˆLÝ˜Ô+Õ->Ñ?Ô?ð 	ØÔ,×4Ò4°YÑ?Ô?Ð?Ð?Ð?Ð?Ð?Ð?Ð?ð Ô-×5Ò5Ñ7Ô7Ð7Ð7Ð7Ð7Ð7Ð7ˆEÝ�5‰zŒz˜IÒ%Ð%à”×#Ò# E¨)¨*¨*Ô$5Ñ6Ô6Ð6Ø˜Z˜i˜ZÔ(Ð(à�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)
rB   r"   r.   r@   r   r   rA   r   r   r8   )r+   rD   Ú	remainingÚretvalrC   Úexcs         r,   Úreceive_exactlyz)BufferedByteReceiveStream.receive_exactly[   s  è è € ð	'Ø¥ T¤\Ñ!2Ô!2Ñ2ˆIØ˜AŠ~ˆ~Øœ g v gÔ.�Ø”L  & Ð)Ý˜V‘}”}Ð$ð.Ý˜dÔ1Õ3DÑEÔEð @Ø"&Ô"5×"=Ò"=¸iÑ"HÔ"HÐHÐHÐHÐHÐHÐH�E�Eà"&Ô"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   TNr>   )rB   r"   Úfindr.   r   r   rA   r   r   Úmaxr8   )	r+   rJ   r;   Údelimiter_sizeÚoffsetÚindexÚfoundr5   rH   s	            r,   Úreceive_untilz'BufferedByteReceiveStream.receive_untilv   s-  è è € õ ˜Y™œˆØˆð	&à”L×%Ò% i°Ñ8Ô8ˆEØ˜ŠzˆzØœ V e VÔ,�Ø”LÐ!; 5­3¨y©>¬>Ñ#9Ð!;Ð<Ý˜U‘|”|Ð#õ �4”<Ñ Ô  IÒ-Ð-Ý'¨	Ñ2Ô2Ð2ð.Ø!Ô0×8Ò8Ñ:Ô:Ð:Ð:Ð:Ð:Ð:Ð:��øÝð .ð .ð .Ý$¨#Ð-øøøøð.øøøõ �˜Tœ\Ñ*Ô*¨^Ñ;¸aÑ?ÀÑCÔCˆFØŒL×Ò Ñ%Ô%Ð%ð)	&s   ÂB6 Â6
CÃ CÃCN©r&   r'   )r&   r.   )r&   r1   )r5   r6   r&   r'   )r:   )r;   r<   r&   r.   )rD   r<   r&   r.   )rJ   r.   r;   r<   r&   r.   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r!   r"   r%   r)   Úpropertyr0   r4   r9   rA   rI   rR   © r-   r,   r   r      s  € € € € € € ðð ð
 )Ð(Ð(Ñ(Ø˜ E¸9ÐEÑEÔE€GÐEÐEÐEÑEØ�E˜u¨eÐ4Ñ4Ô4€GÐ4Ð4Ð4Ñ4ðð ð ð ð ð#ð #ð #ñ „Xð#ð ð4ð 4ð 4ñ „Xð4ð"ð "ð "ð "ðð ð ð ð ð0'ð 'ð 'ð 'ð6$&ð $&ð $&ð $&ð $&ð $&r-   r   c                  óT   ‡ — 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.
    Ústreamr   c                óX   •— t          ¦   «                              |¦  «         || _        dS )z:
        :param stream: the stream to be wrapped

        N)ÚsuperÚ__init__Ú_stream)r+   r\   Ú	__class__s     €r,   r_   zBufferedByteStream.__init__£   s(   ø€ õ
 	‰Œ×Ò˜Ñ Ô Ð ØˆŒˆˆr-   r&   r'   c              ƒ  óH   K  — | j                              ¦   «         ƒ d {V —† d S r3   )r`   Úsend_eofr*   s    r,   rc   zBufferedByteStream.send_eof«   s2   è è € àŒl×#Ò#Ñ%Ô%Ð%Ð%Ð%Ð%Ð%Ð%Ð%Ð%Ð%r-   Úitemr.   c              ƒ  óJ   K  — | j                              |¦  «        ƒ d {V —† d S r3   )r`   Úsend)r+   rd   s     r,   rf   zBufferedByteStream.send¯   s4   è è € àŒl×Ò Ñ%Ô%Ð%Ð%Ð%Ð%Ð%Ð%Ð%Ð%Ð%r-   )r\   r   rS   )rd   r.   r&   r'   )	rT   rU   rV   rW   r_   r   rc   rf   Ú__classcell__)ra   s   @r,   r   r   �   s‡   ø€ € € € € ðð ð
ð ð ð ð ð ð ð&ð &ð &ñ „Xð&ð ð&ð &ð &ñ „Xð&ð &ð &ð &ð &r-   r   c                  ó2   — e Zd ZdZd	d„Zed
d„¦   «         ZdS )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
    Úconnectabler   c                ó   — || _         dS )z>
        :param connectable: the connectable to wrap

        N)ri   )r+   ri   s     r,   r_   zBufferedConnectable.__init__¿   s   € ð
 'ˆÔÐÐr-   r&   r   c              ƒ  ób   K  — | j                              ¦   «         ƒ d {V —†}t          |¦  «        S r3   )ri   Úconnectr   )r+   r\   s     r,   rl   zBufferedConnectable.connectÆ   s:   è è € àÔ'×/Ò/Ñ1Ô1Ð1Ð1Ð1Ð1Ð1Ð1ˆÝ! &Ñ)Ô)Ð)r-   N)ri   r   )r&   r   )rT   rU   rV   rW   r_   r   rl   rZ   r-   r,   r   r   ´   sR   € € € € € ðð ð'ð 'ð 'ð 'ð ð*ð *ð *ñ „Xð*ð *ð *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   rZ   r-   r,   ú<module>rw      sÒ  ðØ "Ð "Ð "Ð "Ð "Ð "ð€ð €
€
€
Ø 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ø (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ø %Ð %Ð %Ð %Ð %Ð %Ð %Ð %à RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ Rðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð Ô�wÒÐØÐÐÐÐÐÐà*Ð*Ð*Ð*Ð*Ð*ð €ˆeÐÑÔð{&ð {&ð {&ð {&ð {&Ð 1ñ {&ô {&ñ Ôð{&ð|&ð &ð &ð &ð &Ð2°Jñ &ô &ð &ð.*ð *ð *ð *ð *Ð/ñ *ô *ð *ð *ð *r-   