← Back
Editing: streams.cpython-311.pyc
� �=Xc� � �8 � d dl mZ d dlmZ G d� d� � ZdS )� )�annotations)� Generatorc �R � e Zd ZdZdd�Zdd�Zdd �Zdd�Zdd �Zdd�Z dd�Z dd�ZdS )�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 �: � t � � | _ d| _ d S )NF)� bytearray�buffer�eof��selfs �4/usr/lib/python3/dist-packages/websockets/streams.py�__init__zStreamReader.__init__ s � ��k�k�������� �m�int�Generator[None, None, bytes]c # �f K � d}d} | j � d|� � dz }|dk rnOt | j � � }||k rt d|� d|� d�� � �| j rt d|� d �� � �d V � �t||k rt 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�rs r � read_linezStreamReader.read_line s� � � � � �� �� ��� � ���*�*�Q�.�A��1�u�u���D�K� � �A��1�u�u�"�#U�1�#U�#U�A�#U�#U�#U�V�V�V��x� S��Q�A�Q�Q�Q�R�R�R��E�E�E� � �q�5�5��Q�q�Q�Q��Q�Q�Q�R�R�R��K����O���K����O��r r c # � K � |dk sJ �t | j � � |k rM| j r*t | j � � }t d|� d|� d�� � �dV � t | j � � |k �M| 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"