
    vKg@                     \    S r SSKJrJr  SSKJrJrJrJr  SSK	J
r
JrJr  Sr " S S5      rg	)
zy
h2/frame_buffer
~~~~~~~~~~~~~~~

A data structure that provides a way to iterate over a byte buffer in terms of
frames.
    )InvalidFrameErrorInvalidDataError)FrameHeadersFrameContinuationFramePushPromiseFrame   )ProtocolErrorFrameTooLargeErrorFrameDataMissingError@   c                   @    \ rS rSrSrSS jrS rS rS rS r	S r
S	rg
)FrameBuffer   zv
This is a data structure that expects to act as a buffer for HTTP/2 data
that allows iteraton in terms of H2 frames.
c                     SU l         SU l        U(       a  SOSU l        [        U R                  5      U l        / U l        g )N    r   s   PRI * HTTP/2.0

SM

)datamax_frame_size	_preamblelen_preamble_len_headers_buffer)selfservers     O/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/h2/frame_buffer.py__init__FrameBuffer.__init__"   s6    	@F<C 0!r   c                 .   U R                   (       ao  [        U5      n[        U R                   U5      nU R                  SU USU :w  a  [	        S5      eXS nU =R                   U-  sl         U R                  US U l        U =R
                  U-  sl        g)z[
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   r   data_lenof_which_preambles       r   add_dataFrameBuffer.add_data)   s     4yH #D$6$6 A~~001T:L;L5MM#$>??*+D"33!^^,=,>?DN		T	r   c                 T    XR                   :  a  [        SXR                   4-  5      eg)z2
Confirm that the frame is an appropriate length.
z*Received overlong frame: length %d, max %dN)r   r   )r   lengths     r   _validate_frame_length"FrameBuffer._validate_frame_length<   s6     '''$<,,-.  (r   c                    U R                   (       Ga  U R                   S   R                  nUSL=(       a&    [        U[        5      =(       a    UR                  U:H  nU(       d  [	        S5      eU R                   R                  U5        [        U R                   5      [        :  a  [	        S5      eSUR                  ;   aZ  U R                   S   nUR                  R                  S5        SR                  S U R                    5       5      Ul        / U l         U$ Sn U$ [        U[        [        45      (       a-  SUR                  ;  a  U R                   R                  U5        SnU$ )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   6   #    U H  oR                   v   M     g 7fN)r   ).0xs     r   	<genexpr>4FrameBuffer._update_header_buffer.<locals>.<genexpr>f   s     !G2FQ&&2Fs   )r   	stream_id
isinstancer   r
   appendr   CONTINUATION_BACKLOGflagsaddjoinr   r   r   )r   fr0   valid_frames       r   _update_header_buffer!FrameBuffer._update_header_bufferF   sB    ,,Q/99I )1/0)y( 
 #$HII   ''*4''(+??#$LMM '((+M*!G$2F2F!GG')$    \+;<==QWW,   ''*Ar   c                     U $ r+    )r   s    r   __iter__FrameBuffer.__iter__t   s    r   c                    [        U R                  5      S:  a
  [        5       e [        R                  " U R                  S S 5      u  p[        U R                  5      US-   :  a
  [        5       eU R                  U5         UR                  [        U R                  SSU-    5      5        U R                  SU-   S  U l        U R                  U5      nUb  U$ U R                  5       $ ! [
        [        4 a  n[        S[        U5      -  5      eS nAff = f! [
         a    [        S5      e[         a    [        S5      ef = f)N	   z&Received frame with invalid header: %sz&Received frame with non-compliant datazFrame data missing or invalid)r   r   StopIterationr   parse_frame_headerr   r   r
   strr&   
parse_body
memoryviewr   r9   __next__)r   r7   r%   es       r   rF   FrameBuffer.__next__w   s7    tyy>A/!	002A?IA tyy>FQJ&/! 	##F+	ILLDIIa&$9:; IIahi(	 &&q) Mq6t}}6C !"34 	83q6A 	    	J HII  	I'(GHH	Is#   %C) *D )D9DD*E)r   r   r   r   r   N)F)__name__
__module____qualname____firstlineno____doc__r   r"   r&   r9   r=   rF   __static_attributes__r<   r   r   r   r      s&    "&+\)7r   r   N)rM   hyperframe.exceptionsr   r   hyperframe.framer   r   r   r   
exceptionsr
   r   r   r3   r   r<   r   r   <module>rR      s8    F    C7 C7r   