
    nbiV                    p    d Z ddlmZ ddlmZmZmZ ddlmZm	Z	 ddl
mZmZmZmZ dZ G d d	          Zd
S )zy
h2/frame_buffer
~~~~~~~~~~~~~~~

A data structure that provides a way to iterate over a byte buffer in terms of
frames.
    )annotations   )FrameDataMissingErrorFrameTooLargeErrorProtocolError)InvalidDataErrorInvalidFrameError)ContinuationFrameFrameHeadersFramePushPromiseFrame@   c                  8    e Zd ZdZd
dZd Zd Zd Zd Zd Z	d	S )FrameBufferz
    This is a data structure that expects to act as a buffer for HTTP/2 data
    that allows iteraton in terms of H2 frames.
    Fc                    t                      | _        d| _        |rdnd| _        t	          | j                  | _        g | _        d S )Nr   s   PRI * HTTP/2.0

SM

    )	bytearray_datamax_frame_size	_preamblelen_preamble_len_headers_buffer)selfservers     `/var/www/html/mdtn/previsions/meteo_cartes/venv/lib/python3.11/site-packages/jh2/frame_buffer.py__init__zFrameBuffer.__init__    sG    [[
@FO<<C 00!r   c                ,   | j         r|t          |          }t          | j         |          }| j        d|         |d|         k    rt	          d          ||d         }| xj         |z  c_         | j        |d         | _        | xj        |z  c_        dS )zs
        Add more data to the frame buffer.

        :param data: A bytestring containing the byte buffer.
        NzInvalid HTTP/2 preamble.)r   r   minr   r   r   )r   datadata_lenof_which_preambles       r   add_datazFrameBuffer.add_data'   s      		@4yyH #D$6 A A~0001T:L;L:L5MMM#$>???)**+D"33!^,=,>,>?DN

d



r   c                N    || j         k    rt          d|| j         fz            dS )zB
        Confirm that the frame is an appropriate length.
        z*Received overlong frame: length %d, max %dN)r   r   )r   lengths     r   _validate_frame_lengthz"FrameBuffer._validate_frame_length:   s?     D'''$<4./0   ('r   c                x   | j         r| j         d         j        }|duot          |t                    o
|j        |k    }|st	          d          | j                             |           t          | j                   t          k    rt	          d          d|j        v rX| j         d         }|j        	                    d           d
                    d | j         D                       |_        g | _         nDd}nAt          |t          t          f          r%d|j        vr| j                             |           d}|S )z
        Updates the internal header buffer. Returns a frame that should replace
        the current one. May throw exceptions if this frame is invalid.
        r   Nz"Invalid frame during header block.z&Too many continuation frames received.END_HEADERSr   c              3  $   K   | ]}|j         V  d S N)r    ).0xs     r   	<genexpr>z4FrameBuffer._update_header_buffer.<locals>.<genexpr>d   s$      !G!GQ!&!G!G!G!G!G!Gr   )r   	stream_id
isinstancer
   r   appendr   CONTINUATION_BACKLOGflagsaddjoinr    r   r   )r   fr.   valid_frames       r   _update_header_bufferz!FrameBuffer._update_header_bufferD   sU     !	,Q/9I -q"344-K9, 
  J#$HIII  ''***4'((+???#$LMMM ''(+M***!G!G$2F!G!G!GGG')$$q<)9:;;	QW,,  ''***Ar   c                    | S r*    )r   s    r   __iter__zFrameBuffer.__iter__t   s    r   c                   t          | j                  dk     rt                      	 t          j        t          | j        d d                             \  }}n8# t          t          f$ r$}t          dt          |          z            d }~ww xY wt          | j                  |dz   k     rt                      | 
                    |           	 |                    t          | j        dd|z                                 n5# t          $ r t          d          t          $ r t          d          w xY w| j        d|z   d          | _        |                     |          }||n|                                 S )N	   z&Received frame with invalid header: %sz&Received frame with non-compliant datazFrame data missing or invalid)r   r   StopIterationr   parse_frame_header
memoryviewr   r	   r   strr&   
parse_bodyr   r7   __next__)r   r5   r%   es       r   rB   zFrameBuffer.__next__w   s    tz??Q//!	S0DJrrN1K1KLLIAvv "34 	S 	S 	S H3q66 QRRR	S
 tz??VaZ''//! 	##F+++	ILLDJq1v:~$>??@@@@ 	J 	J 	J HIII  	I 	I 	I'(GHHH	I
 ZF
-
 &&q)) Mqqt}}6s#   1A B+B

B2D 2D6N)F)
__name__
__module____qualname____doc__r   r#   r&   r7   r:   rB   r9   r   r   r   r      s~         
" " " "  &  - - -`  '7 '7 '7 '7 '7r   r   N)rG   
__future__r   
exceptionsr   r   r   hyperframe.exceptionsr   r	   hyperframe.framer
   r   r   r   r1   r   r9   r   r   <module>rL      s     # " " " " " P P P P P P P P P P F F F F F F F F V V V V V V V V V V V V  D7 D7 D7 D7 D7 D7 D7 D7 D7 D7r   