
    mh                       d dl m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j2                  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)    )annotationsN)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)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    h/var/www/pru.catia.catastroantioquia-mas.com/tasa/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               :    | 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_data0   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r.   )
r#   r   r    r*   
isinstancer   r   receivelenr1   )r'   	max_byteschunks      r(   r6   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)
r7   r    r*   r5   r   r   r6   r   r   r1   )r'   nbytes	remainingretvalr9   excs         r(   receive_exactlyz)BufferedByteReceiveStream.receive_exactlyR   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   )r7   r    findr*   r   r   r6   r   r   maxr1   )	r'   	delimiterr8   delimiter_sizeoffsetindexfoundr2   r>   s	            r(   receive_untilz'BufferedByteReceiveStream.receive_untilm   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)rK   r*   )rK   zMapping[Any, Callable[[], Any]])r2   zIterable[SupportsIndex]rK   rL   )i   )r8   intrK   r*   )r;   rM   rK   r*   )rD   r*   r8   rM   rK   r*   )__name__
__module____qualname____doc____annotations__r   r   r    r#   r%   propertyr+   r/   r3   r6   r?   rI    r,   r(   r   r      sr    
 )(E9EGYEue4GT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 )BufferedByteStreamz
    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(   rY   zBufferedByteStream.__init__   s    
 	 r,   c                T   K   | j                   j                          d {    y 7 wr.   )rZ   send_eofr&   s    r(   r^   zBufferedByteStream.send_eof   s     ll##%%%s   (&(c                V   K   | j                   j                  |       d {    y 7 wr.   )rZ   send)r'   items     r(   r`   zBufferedByteStream.send   s     ll%%%s   )'))r[   r   rJ   )ra   r*   rK   rL   )	rN   rO   rP   rQ   rY   r   r^   r`   __classcell__)r\   s   @r(   rV   rV      s5    
 & & & &r,   rV   c                  &    e Zd ZddZedd       Zy)BufferedConnectablec                    || _         y)z>
        :param connectable: the connectable to wrap

        N)connectable)r'   rf   s     r(   rY   zBufferedConnectable.__init__   s    
 'r,   c                h   K   | j                   j                          d {   }t        |      S 7 wr.   )rf   connectrV   )r'   r[   s     r(   rh   zBufferedConnectable.connect   s-     ''//11!&)) 2s   202N)rf   r   )rK   rV   )rN   rO   rP   rY   r   rh   rT   r,   r(   rd   rd      s    ' * *r,   rd   )
__future__r   syscollections.abcr   r   r   dataclassesr   r   typingr	   r
    r   r   r   r   abcr   r   r   r   r   r   version_infor   typing_extensionsr   rV   rd   rT   r,   r(   <module>rr      s~    " 
 7 7 ( % R R  w* ex& 1 x& x&v&2J &.*/ *r,   