o
    <ºiÏ  ã                   @  s*   d dl mZ d dlmZ G dd„ dƒZdS )é    )Úannotations)Ú	Generatorc                   @  s`   e Zd ZdZddd„Zdd	d
„Zddd„Zddd„Zddd„Zd dd„Z	ddd„Z
ddd„ZdS )!ÚStreamReaderzÄ
    Generator-based stream reader.

    This class doesn't support concurrent calls to :meth:`read_line`,
    :meth:`read_exact`, or :meth:`read_to_eof`. Make sure calls are
    serialized.

    ÚreturnÚNonec                 C  s   t ƒ | _d| _d S )NF)Ú	bytearrayÚbufferÚeof©Úself© r   úO/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/websockets/streams.pyÚ__init__   s   
zStreamReader.__init__ÚmÚintúGenerator[None, None, bytes]c                 c  sª    d}d}	 | j  d|¡d }|dkrn#t| j ƒ}||kr(td|› d|› dƒ‚| jr3td|› d	ƒ‚d
V  q||krFtd|› d|› dƒ‚| j d
|… }| j d
|…= |S )a…  
        Read a LF-terminated line from the stream.

        This is a generator-based coroutine.

        The return value includes the LF character.

        Args:
            m: Maximum number bytes to read; this is a security limit.

        Raises:
            EOFError: If the stream ends without a LF.
            RuntimeError: If the stream ends in more than ``m`` bytes.

        r   Tó   
é   úread ú bytes, expected no more than ú bytesústream ends after z bytes, before end of lineN)r   ÚfindÚlenÚRuntimeErrorr	   ÚEOFError)r   r   ÚnÚpÚrr   r   r   Ú	read_line   s&   €
÷
zStreamReader.read_liner   c                 c  st    |dksJ ‚t | jƒ|k r+| jr!t | jƒ}td|› d|› dƒ‚dV  t | jƒ|k s| jd|… }| jd|…= |S )zø
        Read a given number of bytes from the stream.

        This is a generator-based coroutine.

        Args:
            n: How many bytes to read.

        Raises:
            EOFError: If the stream ends in less than ``n`` bytes.

        r   r   z bytes, expected r   N)r   r   r	   r   )r   r   r   r   r   r   r   Ú
read_exact6   s   €
üzStreamReader.read_exactc                 c  sZ    | j st| jƒ}||krtd|› d|› dƒ‚dV  | j r| jdd… }| jdd…= |S )a  
        Read all bytes from the stream.

        This is a generator-based coroutine.

        Args:
            m: Maximum number bytes to read; this is a security limit.

        Raises:
            RuntimeError: If the stream ends in more than ``m`` bytes.

        r   r   r   N)r	   r   r   r   )r   r   r   r   r   r   r   Úread_to_eofM   s   €
üzStreamReader.read_to_eofúGenerator[None, None, bool]c                 c  s     	 | j rdS | jrdS dV  q)zy
        Tell whether the stream has ended and all data was read.

        This is a generator-based coroutine.

        TFN)r   r	   r
   r   r   r   Úat_eofc   s   €ùzStreamReader.at_eofÚdataÚbytesc                 C  s    | j rtdƒ‚|  j|7  _dS )zà
        Write data to the stream.

        :meth:`feed_data` cannot be called after :meth:`feed_eof`.

        Args:
            data: Data to write.

        Raises:
            EOFError: If the stream has ended.

        ústream endedN)r	   r   r   )r   r$   r   r   r   Ú	feed_datas   s   zStreamReader.feed_datac                 C  s   | j rtdƒ‚d| _ dS )z
        End the stream.

        :meth:`feed_eof` cannot be called more than once.

        Raises:
            EOFError: If the stream has ended.

        r&   TN)r	   r   r
   r   r   r   Úfeed_eof„   s   

zStreamReader.feed_eofc                 C  s   | j dd…= dS )zG
        Discard all buffered data, but don't end the stream.

        N)r   r
   r   r   r   Údiscard’   s   zStreamReader.discardN)r   r   )r   r   r   r   )r   r   r   r   )r   r"   )r$   r%   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r    r!   r#   r'   r(   r)   r   r   r   r   r      s    
	

"



r   N)Ú
__future__r   Úcollections.abcr   r   r   r   r   r   Ú<module>   s    