o �J�hf�@s*ddlmZddlmZGdd�d�ZdS)�)� annotations)� Generatorc@s`eZdZdZddd�Zdd d �Zdd d �Zddd�Zddd�Zd dd�Z ddd�Z ddd�Z dS)!� 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�NonecCst�|_d|_dS)NF)� bytearray�buffer�eof��self�r �PC:\pinokio\api\whisper-webui.git\app\env\lib\site-packages\websockets\streams.py�__init__s zStreamReader.__init__�m�int�Generator[None, None, bytes]ccs��d}d} |j�d|�d}|dkrn#t|j�}||kr(td|�d|�d���|jr3td|�d ���d Vq||krFtd|�d|�d���|jd |�}|jd |�=|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. rT� ��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_lines&� �  zStreamReader.read_linerccst�|dksJ�t|j�|kr+|jr!t|j�}td|�d|�d���dVt|j�|ks|jd|�}|jd|�=|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. rrz bytes, expected rN)rrr r)r rrrr r r � read_exact6s�  � zStreamReader.read_exactccsZ�|jst|j�}||krtd|�d|�d���dV|jr|jdd�}|jdd�=|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. rrrN)r rrr)r rrrr r r � read_to_eofMs� � zStreamReader.read_to_eof�Generator[None, None, bool]ccs � |jrdS|jr dSdVq)zy Tell whether the stream has ended and all data was read. This is a generator-based coroutine. TFN)rr r r r r �at_eofcs��zStreamReader.at_eof�data�bytescCs |jrtd��|j|7_dS)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 rr)r r$r r r � feed_datass zStreamReader.feed_datacCs|jrtd��d|_dS)z� End the stream. :meth:`feed_eof` cannot be called more than once. Raises: EOFError: If the stream has ended. r&TN)r rr r r r �feed_eof�s  zStreamReader.feed_eofcCs|jdd�=dS)zG Discard all buffered data, but don't end the stream. N)rr r r r �discard�szStreamReader.discardN)rr)rrrr)rrrr)rr")r$r%rr) �__name__� __module__� __qualname__�__doc__rrr r!r#r'r(r)r r r r rs  "    rN)� __future__r�collections.abcrrr r r r �<module>s 
Memory