o
    _c                     @  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   =/usr/local/lib/python3.10/dist-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   typingr   r   r   r   r   r   <module>   s    