
    vKg%                         S SK Jr  S SKrSSKJr  \R
                  " \5      rS r " S S5      r	S r
\
" 5       \	l        g)	    )dequeN   )InvalidTableIndexc                 6    S[        U 5      -   [        U5      -   $ )a7  
Calculates the size of a single entry

This size is mostly irrelevant to us and defined
specifically to accommodate memory management for
lower level implementations. The 32 extra bytes are
considered the "maximum" overhead that would be
required to represent each entry in the table.

See RFC7541 Section 4.1
    )len)namevalues     K/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/hpack/table.pytable_entry_sizer      s     D	>CJ&&    c                       \ rS rSrSrSrSr\" \5      rS r	S r
S rS rS	 r\S
 5       r\R                   S 5       rS rSrg)HeaderTable   z
Implements the combined static and dynamic header table

The name and value arguments for all the functions
should ONLY be byte strings (b'') however this is not
strictly enforced in the interface.

See RFC7541 Section 2.3
i   )=)s
   :authorityr   )   :methods   GET)r   s   POST)   :path   /)r   s   /index.html)   :schemes   http)r   s   https)   :statuss   200)r   s   204)r   s   206)r   s   304)r   s   400)r   s   404)r   s   500)s   accept-charsetr   )s   accept-encodings   gzip, deflate)s   accept-languager   )s   accept-rangesr   )s   acceptr   )s   access-control-allow-originr   )s   ager   )s   allowr   )s   authorizationr   )s   cache-controlr   )s   content-dispositionr   )s   content-encodingr   )s   content-languager   )s   content-lengthr   )s   content-locationr   )s   content-ranger   )s   content-typer   )s   cookier   )s   dater   )s   etagr   )s   expectr   )s   expiresr   )s   fromr   )s   hostr   )s   if-matchr   )s   if-modified-sincer   )s   if-none-matchr   )s   if-ranger   )s   if-unmodified-sincer   )s   last-modifiedr   )s   linkr   )s   locationr   )s   max-forwardsr   )s   proxy-authenticater   )s   proxy-authorizationr   )s   ranger   )s   refererr   )s   refreshr   )s   retry-afterr   )s   serverr   )s
   set-cookier   )s   strict-transport-securityr   )s   transfer-encodingr   )s
   user-agentr   )s   varyr   )s   viar   )s   www-authenticater   c                 h    [         R                  U l        SU l        SU l        [        5       U l        g )Nr   F)r   DEFAULT_SIZE_maxsize_current_sizeresizedr   dynamic_entriesselfs    r   __init__HeaderTable.__init__l   s(    #00$wr   c                     UnUS-  nSU::  ab  U[         R                  :  a  [         R                  U   $ U[         R                  -  nU[        U R                  5      :  a  U R                  U   $ [        SU-  5      e)a.  
Returns the entry specified by index

Note that the table is 1-based ie an index of 0 is
invalid.  This is due to the fact that a zero value
index signals that a completely unindexed header
follows.

The entry will either be from the static table or
the dynamic table depending on the value of index.
r   r   zInvalid table index %d)r   STATIC_TABLE_LENGTHSTATIC_TABLEr   r   r   )r   indexoriginal_indexs      r   get_by_indexHeaderTable.get_by_indexr   s}     
:{666"//66[444Es4//00++E22 8> IJJr   c                 N    SU R                   U R                  U R                  4-  $ )NzHeaderTable(%d, %s, %r))r   r   r   r   s    r   __repr__HeaderTable.__repr__   s+    (MMLL  ,
 
 	
r   c                     [        X5      nX0R                  :  a"  U R                  R                  5         SU l        gU R                  R                  X45        U =R                  U-  sl        U R                  5         g)zu
Adds a new entry to the table

We reduce the table size if the entry will make the
table size greater than maxsize.
r   N)r   r   r   clearr   
appendleft_shrink)r   r	   r
   sizes       r   addHeaderTable.add   sd      ,--  &&(!"D   ++TM:$&LLNr   c                 D   Sn[         R                  R                  U5      nU(       a#  US   R                  U5      nUb  XQU4$ US   US4n[         R                  S-   n[	        U R
                  5       H(  u  nu  pX:X  d  M  X:X  a  Xv-   X4s  $ Ub  M!  Xv-   US4nM*     U$ )z
Searches the table for the entry specified by name
and value

Returns one of the following:
    - ``None``, no match at all
    - ``(index, name, None)`` for partial matches on name only.
    - ``(index, name, value)`` for perfect matches.
Nr   r   )r   STATIC_TABLE_MAPPINGgetr!   	enumerater   )
r   r	   r
   partialheader_name_search_resultr#   offsetinvs
             r   searchHeaderTable.search   s     $/$D$D$H$H$N!$-a044U;E E))4Q7tD0014$T%9%9:KQy::q++_ z1d3G ; r   c                     U R                   $ )N)r   r   s    r   maxsizeHeaderTable.maxsize   s    }}r   c                    [        U5      n[        R                  SXR                  5        U R                  nXl        X:g  U l        US::  a"  U R
                  R                  5         SU l        g X!:  a  U R                  5         g g )Nz#Resizing header table to %d from %dr   )	intlogdebugr   r   r   r+   r   r-   )r   newmaxoldmaxs      r   r>   r?      sj    V		7O(Q;  &&(!"D_LLN r   c                     U R                   nXR                  :  aQ  U R                  R                  5       u  p#U[	        X#5      -  n[
        R                  SX#5        XR                  :  a  MQ  Xl         g)z5
Shrinks the dynamic table to be at or below maxsize
z%Evicting %s: %s from the header tableN)r   r   r   popr   rB   rC   )r   cursizer	   r
   s       r   r-   HeaderTable._shrink   sb     $$%..224KD'44GII=tK % %r   )r   r   r   r   N)__name__
__module____qualname____firstlineno____doc__r   r"   r   r!   r   r%   r(   r/   r;   propertyr>   setterr-   __static_attributes__ r   r   r   r      sn     L>L@ l+'K0
$:   ^^
 
	%r   r   c                      0 n [        [        R                  S5       H"  u  nu  p#U R                  X!0 45      nXS   U'   M$     U $ )z
Build static table mapping from header name to tuple with next structure:
(<minimal index of header>, <mapping from header value to it index>).

static_table_mapping used for hash searching.
r   )r4   r   r"   
setdefault)static_table_mappingr#   r	   r
   r6   s        r   _build_static_table_mappingrV      sT      )+*B*BA F}$8$C$CDRT+$V!.3!$U+ !G  r   )collectionsr   logging
exceptionsr   	getLoggerrJ   rB   r   r   rV   r2   rR   r   r   <module>r[      sD      )!'@% @%F  $?#@  r   