
    -2iw                    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    U/var/www/html/pixcura-vrs/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   | 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 r3   )
r%   r   r"   r.   
isinstancer   r   receivelenr8   )r+   r;   chunks      r,   r?   z!BufferedByteReceiveStream.receiveC   s      < 	&%%< 	$,z	z233EZiZ(L+->?? 	,44Y????????? -5577777777E5zzI%%##E)**$5666ZiZ((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)
r@   r"   r.   r>   r   r   r?   r   r   r8   )r+   rB   	remainingretvalrA   excs         r,   receive_exactlyz)BufferedByteReceiveStream.receive_exactlyX   s     	'T\!2!22IA~~gvg.L&)V}}$.d13DEE @"&"5"="=i"H"HHHHHHHEE"&"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   TN   )r@   r"   findr.   r   r   r?   r   r   maxr8   )	r+   rH   r;   delimiter_sizeoffsetindexfoundr5   rF   s	            r,   receive_untilz'BufferedByteReceiveStream.receive_untils   s-      Y	&L%%i88EzzVeV,L!;53y>>#9!;<U||# 4<  I--'	222.!088:::::::: . . .$#-. T\**^;a?CCFL%%%)	&s   B6 6
C CCNr&   r'   )r&   r.   )r&   r1   )r5   r6   r&   r'   )r:   )r;   r<   r&   r.   )rB   r<   r&   r.   )rH   r.   r;   r<   r&   r.   )__name__
__module____qualname____doc____annotations__r   r!   r"   r%   r)   propertyr0   r4   r9   r?   rG   rQ    r-   r,   r   r      s         
 )(((E9EEEGEEEEEue444G4444    # # # X# 4 4 4 X4" " " "    *' ' ' '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,   rb   zBufferedByteStream.send_eof   s2      l##%%%%%%%%%%%r-   itemr.   c                J   K   | j                             |           d {V  d S r3   )r_   send)r+   rc   s     r,   re   zBufferedByteStream.send   s4      l%%%%%%%%%%%r-   )r[   r   rR   )rc   r.   r&   r'   )	rS   rT   rU   rV   r^   r   rb   re   __classcell__)r`   s   @r,   r   r      s         
      & & & X& & & & X& & & & &r-   r   c                  .    e Zd ZddZed	d            ZdS )
r   connectabler   c                    || _         dS )z>
        :param connectable: the connectable to wrap

        N)rh   )r+   rh   s     r,   r^   zBufferedConnectable.__init__   s    
 'r-   r&   r   c                b   K   | j                                          d {V }t          |          S r3   )rh   connectr   )r+   r[   s     r,   rk   zBufferedConnectable.connect   s:      '//11111111!&)))r-   N)rh   r   )r&   r   )rS   rT   rU   r^   r   rk   rY   r-   r,   r   r      sH        ' ' ' ' * * * 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   rY   r-   r,   <module>rv      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x& x& x& x& x& 1 x& x& x&v& & & & &2J & & &.* * * * */ * * * * *r-   