o
    Þ­jw  ã                   @  sè   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rNd dlmZ nd dlmZ e	dd�G dd„ deƒƒZG dd„ deeƒZG d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                   @  s’   e Zd ZU dZded< eded�Zded< eddd�Zd	ed
< d%dd„Z	e
d&dd„ƒZe
d'dd„ƒZd(dd„Zd)d*dd„Zd+dd „Zd,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                 Ã  s   �| j  ¡ I d H  d| _d S )NT)r   Úacloser#   ©Úself© r)   úS/var/www/html/CropPilot/venv/lib/python3.10/site-packages/anyio/streams/buffered.pyr&   )   s   €
z BufferedByteReceiveStream.acloseÚbytesc                 C  s
   t | jƒS )z"The bytes currently in the buffer.)r+   r    r'   r)   r)   r*   Úbuffer-   s   
z BufferedByteReceiveStream.bufferúMapping[Any, Callable[[], Any]]c                 C  s   | j jS ©N)r   Úextra_attributesr'   r)   r)   r*   r/   2   s   z*BufferedByteReceiveStream.extra_attributesÚdataúIterable[SupportsIndex]c                C  s   | 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(   r0   r)   r)   r*   Ú	feed_data6   s   z#BufferedByteReceiveStream.feed_dataé   Ú	max_bytesÚintc                 Ã  s’   �| j rt‚| jrt| jd |… ƒ}| jd |…= |S t| jtƒr)| j |¡I d H S | j ¡ I d H }t|ƒ|krG| j 	||d … ¡ |d |… S |S r.   )
r#   r   r    r+   Ú
isinstancer   r   ÚreceiveÚlenr2   )r(   r5   Úchunkr)   r)   r*   r8   C   s   €z!BufferedByteReceiveStream.receiveÚnbytesc              
   Ã  sž   �	 |t | jƒ }|dkr| jd|… }| jd|…= t|ƒS zt| jtƒr/| j |¡I dH }n| j ¡ I dH }W n tyG } zt|‚d}~ww | j 	|¡ q)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)
r9   r    r+   r7   r   r   r8   r   r   r2   )r(   r;   Ú	remainingÚretvalr:   Úexcr)   r)   r*   Úreceive_exactlyX   s$   €
€€ÿñz)BufferedByteReceiveStream.receive_exactlyÚ	delimiterc           	   
   Ã  sÀ   �t |ƒ}d}	 | j ||¡}|dkr(| jd|… }| jd|t |ƒ …= t|ƒS t | jƒ|kr3t|ƒ‚z
| j ¡ I dH }W n tyL } zt|‚d}~ww t	t | jƒ| d dƒ}| j 
|¡ q)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é   )r9   r    Úfindr+   r   r   r8   r   r   Úmaxr2   )	r(   r@   r5   Údelimiter_sizeÚoffsetÚindexÚfoundr0   r>   r)   r)   r*   Úreceive_untils   s(   €€ÿìz'BufferedByteReceiveStream.receive_untilN©r$   r%   )r$   r+   )r$   r-   )r0   r1   r$   r%   )r4   )r5   r6   r$   r+   )r;   r6   r$   r+   )r@   r+   r5   r6   r$   r+   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r
   r   r    r#   r&   Úpropertyr,   r/   r3   r8   r?   rH   r)   r)   r)   r*   r      s   
 


r   c                      s>   e Zd ZdZd‡ fdd„Zeddd	„ƒZeddd„ƒZ‡  ZS )r   z…
    A full-duplex variant of :class:`BufferedByteReceiveStream`. All writes are passed
    through to the wrapped stream as-is.
    Ústreamr   c                   s   t ƒ  |¡ || _dS )z:
        :param stream: the stream to be wrapped

        N)ÚsuperÚ__init__Ú_stream©r(   rP   ©Ú	__class__r)   r*   rR       s   
zBufferedByteStream.__init__r$   r%   c                 Ã  s   �| j  ¡ I d H  d S r.   )rS   Úsend_eofr'   r)   r)   r*   rW   ¨   s   €zBufferedByteStream.send_eofÚitemr+   c                 Ã  s   �| j  |¡I d H  d S r.   )rS   Úsend)r(   rX   r)   r)   r*   rY   ¬   s   €zBufferedByteStream.send)rP   r   rI   )rX   r+   r$   r%   )	rJ   rK   rL   rM   rR   r   rW   rY   Ú__classcell__r)   r)   rU   r*   r   š   s    r   c                   @  s$   e Zd Zd
dd„Zeddd„ƒZd	S )r   Úconnectabler   c                 C  s
   || _ dS )z>
        :param connectable: the connectable to wrap

        N)r[   )r(   r[   r)   r)   r*   rR   ²   s   
zBufferedConnectable.__init__r$   r   c                 Ã  s   �| j  ¡ I d H }t|ƒS r.   )r[   Úconnectr   rT   r)   r)   r*   r\   ¹   s   €zBufferedConnectable.connectN)r[   r   )r$   r   )rJ   rK   rL   rR   r   r\   r)   r)   r)   r*   r   ±   s    
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   r)   r)   r)   r*   Ú<module>   s     
	{