a
    ((a                     @   s   d dl mZ G dd dZdS )    )	Generatorc                   @   s   e Zd ZdZddddZeddef dddZeeddef dd	d
Z	eddef dddZ
eddef dddZeddddZd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.

    N)returnc                 C   s   t  | _d| _d S )NF)	bytearraybuffereofself r
   Y/Users/bob/PycharmProjects/fastapi/venv/lib/python3.9/site-packages/websockets/streams.py__init__   s    zStreamReader.__init__c                 c   sj   d}d}| j d|d }|dkr$qLt| j }| jrDtd| ddV  q| j d| }| j d|= |S )z
        Read a LF-terminated line from the stream.

        The return value includes the LF character.

        This is a generator-based coroutine.

        :raises EOFError: if the stream ends without a LF

        r      
   stream ends after z bytes, before end of lineN)r   findlenr   EOFErrorr	   nprr
   r
   r   	read_line   s    
zStreamReader.read_line)r   r   c                 c   sf   |dksJ t | j|k rH| jr@t | j}td| d| ddV  q| jd| }| jd|= |S )z
        Read ``n`` bytes from the stream.

        This is a generator-based coroutine.

        :raises EOFError: if the stream ends in less than ``n`` bytes

        r   r   z bytes, expected z bytesN)r   r   r   r   r   r
   r
   r   
read_exact+   s    	
zStreamReader.read_exactc                 c   s,   | j sdV  q | jdd }| jdd= |S )z`
        Read all bytes from the stream.

        This is a generator-based coroutine.

        N)r   r   )r	   r   r
   r
   r   read_to_eof>   s
    zStreamReader.read_to_eofc                 c   s    | j r
dS | jrdS dV  q dS )zy
        Tell whether the stream has ended and all data was read.

        This is a generator-based coroutine.

        FTN)r   r   r   r
   r
   r   at_eofK   s
    zStreamReader.at_eof)datar   c                 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()`.

        :raises EOFError: if the stream has ended

        stream endedN)r   r   r   )r	   r   r
   r
   r   	feed_data[   s    	zStreamReader.feed_datac                 C   s   | j rtdd| _ dS )z
        End the stream.

        :meth:`feed_eof()` must be called at must once.

        :raises EOFError: if the stream has ended

        r   TN)r   r   r   r
   r
   r   feed_eofh   s    	zStreamReader.feed_eof)__name__
__module____qualname____doc__r   r   bytesr   intr   r   boolr   r   r   r
   r
   r
   r   r      s   	r   N)typingr   r   r
   r
   r
   r   <module>   s   