
    A>qj                    0    d dl mZ d dlmZ  G d d      Zy)    )annotations)	Generatorc                  l    e Zd ZdZddZef	 	 	 	 	 ddZddZef	 	 	 	 	 ddZddZ	ddZ
ddZdd	Zy
)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.

    c                0    t               | _        d| _        y )NF)	bytearraybuffereofselfs    Q/opt/rentech/trading_bot/.venv/lib/python3.12/site-packages/websockets/streams.py__init__zStreamReader.__init__   s    k    c              #  X  K   d}d}	 | j                   j                  d|      dz   }|dkD  rnIt        | j                         }||kD  r |d| d| d      | j                  rt	        d| d      d	 n||kD  r |d| d| d      | j                   d	| }| j                   d	|= |S w)
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.
            too_long_exc_type: exception to raise if the line ends in more
                than ``m`` bytes; defaults to :exc:`RuntimeError`.

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

        r      
   read  bytes, expected no more than  bytesstream ends after z bytes, before end of lineN)r	   findlenr
   EOFError)r   mtoo_long_exc_typenprs         r   	read_linezStreamReader.read_line   s     ,   *Q.A1uDKK A1u'A3<QCvF  xx!3A36PQRR  q5#eA3.LQCv$VWWKKOKKOs   B(B*c              #  (  K   |dk\  sJ t        | j                        |k  rP| j                  r't        | j                        }t        d| d| d      d t        | j                        |k  rP| j                  d| }| j                  d|= |S w)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   s       r   
read_exactzStreamReader.read_exact>   s      Avv$++"xx$!3A36Gs&QRR	 $++"
 KKOKKOs   A/B2 Bc              #     K   | j                   s:t        | j                        }||kD  r |d| d| d      d | j                   s:| j                  dd }| j                  dd= |S w)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.
            too_long_exc_type: exception to raise if the stream ends in more
                than ``m`` bytes; defaults to :exc:`RuntimeError`.

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

        r   r   r   N)r
   r   r	   )r   r   r   r   r   s        r   read_to_eofzStreamReader.read_to_eofU   sq     & ((DKK A1u'A3<QCvF   (( KKNKKNs   AA)	 A)c              #  J   K   	 | j                   ry| j                  ryd w)zy
        Tell whether the stream has ended and all data was read.

        This is a generator-based coroutine.

        TFN)r	   r
   r   s    r   at_eofzStreamReader.at_eofs   s)      {{xx  s   !#c                \    | j                   rt        d      | xj                  |z  c_        y)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   datas     r   	feed_datazStreamReader.feed_data   s$     88>**tr   c                @    | j                   rt        d      d| _         y)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   s    r   feed_eofzStreamReader.feed_eof   s     88>**r   c                "    | j                   dd= y)zG
        Discard all buffered data, but don't end the stream.

        N)r	   r   s    r   discardzStreamReader.discard   s    
 KKNr   N)returnNone)r   intr   ztype[Exception]r.    Generator[None, None, bytearray])r   r0   r.   r1   )r.   zGenerator[None, None, bool])r(   zbytes | bytearrayr.   r/   )__name__
__module____qualname____doc__r   RuntimeErrorr   r!   r#   r%   r)   r+   r-    r   r   r   r      sr     .:(( +( 
*	(T4 .: + 
*	< "r   r   N)
__future__r   collections.abcr   r   r7   r   r   <module>r:      s    " %a ar   