+
    Qi_                       R t ^ RIHt ^ RIt^ RIHtHt ^RIHtH	t	H
t
 ^RIHt ^RIHtHt ^RIHt ^RIHtHtHt ^R	IHtHt ]'       d   ^ R
IHt ]P6                  ! ]4      tRtRtRt ]!! ^	4       U u. uF  p ^V ,          ^,
          NK  	  up t"Rt#R R lt$R R lt%R R lt&R R lt'R R lt( ! R R4      t) ! R R4      t*R# u up i )zL
Implements the HPACK header compression algorithm as detailed by RFC 7541.
)annotationsN)TYPE_CHECKINGAny)HPACKDecodingErrorInvalidTableSizeErrorOversizedHeaderListError)HuffmanEncoder)REQUEST_CODESREQUEST_CODES_LENGTH)decode_huffman)HeaderTupleHeaderWeaklyTypedNeverIndexedHeaderTuple)HeaderTabletable_entry_size)Iterable          @c               $    V ^8  d   QhRRRRRR/# )   headerr   rawboolreturnr    )formats   "`/Users/mitch_tango/dev/rabbit-r1-livekit/agent/.venv/lib/python3.14/site-packages/hpack/hpack.py__annotate__r   #   s"     
) 
)0 
)t 
) 
)    c                    \        V ^ ,          4      p\        V ^,          4      pV'       g1   V P                  VP                  R4      VP                  R4      4      # V P                  W#4      # )z^
Provides a header as a unicode string if raw is False, otherwise returns
it as a bytestring.
utf-8)bytes	__class__decode)r   r   namevalues   &&  r   _unicode_if_neededr'   #   sY    
 D&)EG 4ell76KLLD((r   c               $    V ^8  d   QhRRRRRR/# )r   integerintprefix_bitsr   	bytearrayr   )r   s   "r   r   r   0   s!      C c i r   c                   \         P                  RW4       V ^ 8  d   RV  2p\        V4      hV^8  g   V^8  d   RV 2p\        V4      h\        V,          pW8  d   \	        V .4      # V.pW,          p V ^8  d+   VP                  V ^,          ^,           4       V ^,          p K1  VP                  V 4       \	        V4      # )z]
Encodes an integer according to the wacky integer encoding rules
defined in the HPACK spec.
zEncoding %d with %d bitsz'Can only encode positive integers, got )Prefix bits must be between 1 and 8, got )logdebug
ValueError_PREFIX_BIT_MAX_NUMBERSr,   append)r)   r+   msg
max_numberelementss   &&   r   encode_integerr7   0   s    
 II('?{7yAoQ+/9+Go(5J'##|HG
S.3#-.AOOGXr   c               $    V ^8  d   QhRRRRRR/# )r   datar"   r+   r*   r   ztuple[int, int]r   )r   s   "r   r   r   O   s!     $ $ $S $_ $r   c                   V^8  g   V^8  d   RV 2p\        V4      h\        V,          p^p^ p^^V,
          ,	          p V ^ ,          V,          pWs8X  dL    W,          pV^,          pV^8  d   Wx^,
          V,          ,          pMWxV,          ,          pMV^,          pKK  \        P                  RWt4       Wt3#   \         d   p	RT : 2p\        T4      T	hRp	?	ii ; i)z
Decodes an integer according to the wacky integer encoding rules
defined in the HPACK spec. Returns a tuple of the decoded integer and the
number of bytes that were consumed from ``data`` in order to get that
integer.
r.   z3Unable to decode HPACK integer representation from NzDecoded %d, consumed %d bytes)r1   r2   
IndexErrorr   r/   r0   )
r9   r+   r4   r5   indexshiftmasknumber	next_byteerrs
   &&        r   decode_integerrB   O   s     Q+/9+Go(5JEEQ_%D/a4 K	
#3588F500F
 II-v==  /CD8L %3./s   AB; B; ;CCCc                    V ^8  d   QhRRRR/# )r   header_dictzdict[bytes | str, bytes | str]r   z)Iterable[tuple[bytes | str, bytes | str]]r   )r   s   "r   r   r   v   s     $ $#A $4$r   c              #     "   \        V \        4      '       g   R\        V 4       2p\        V4      h\	        V P                  4       R R7      pV F  pW0V,          3x  K  	  R# 5i)z
Converts a dictionary to an iterable of key-value tuples. This is a
HPACK-specific function because it pulls "special-headers" out first and
then emits them.
zheader_dict not a dict, but c                @    \        V 4      P                  R 4      '       * # )   :)	_to_bytes
startswith)ks   &r   <lambda>#_dict_to_iterable.<locals>.<lambda>   s    )A,11$77r   )keyN)
isinstancedicttype	TypeErrorsortedkeys)rD   r4   rS   rM   s   &   r   _dict_to_iterablerT   v   sc      k4((,T+->,?@n7D s### s   A#A%c                    V ^8  d   QhRRRR/# )r   r&   zbytes | str | Anyr   r"   r   )r   s   "r   r   r      s     	! 	!& 	!5 	!r   c                |    \        V 4      pV\        J d   V # V\        Jd   \        V 4      p V P                  R4      # )z:
Convert anything to bytes through a UTF-8 encoded string
r!   )rP   r"   strencode)r&   ts   & r   rH   rH      s8     	UAEz|E
<<  r   c                      ] tR t^tRtR R lt]R R l4       t]P                  R R l4       tRR R	 llt	RR
 R llt
R R ltRR R lltRR R lltR R ltRtR# )Encoderza
An HPACK encoder object. This object takes HTTP headers and emits encoded
HTTP/2 header blocks.
c                   V ^8  d   QhRR/# r   r   Noner   )r   s   "r   r   Encoder.__annotate__   s     0 0$ 0r   c                	d    \        4       V n        \        \        \        4      V n        . V n        R # N)r   header_tabler   r	   r
   huffman_codertable_size_changesselfs   &r   __init__Encoder.__init__   s)    'M+/
 .0r   c                   V ^8  d   QhRR/# r   r   r*   r   )r   s   "r   r   r_           ) )3 )r   c                .    V P                   P                  # z.
Controls the size of the HPACK header table.
rb   maxsizere   s   &r   header_table_sizeEncoder.header_table_size       
   (((r   c                    V ^8  d   QhRRRR/# r   r&   r*   r   r^   r   )r   s   "r   r   r_      s     2 2s 2t 2r   c                	    WP                   n        V P                   P                  '       d   V P                  P	                  V4       R # R # ra   )rb   ro   resizedrd   r3   rf   r&   s   &&r   rp   rq      s9    $)!$$$##**51 %r   c               $    V ^8  d   QhRRRRRR/# )r   headerszIterable[HeaderTuple | tuple[bytes | str, bytes | str] | tuple[bytes | str, bytes | str, bool | None]] | dict[bytes | str, bytes | str]huffmanr   r   r"   r   )r   s   "r   r   r_      s/     k k2k k ).kr   c                n   . pV P                   P                  '       d1   VP                  V P                  4       4       RV P                   n        \	        V\
        4      '       d   \        V4      pM \        V4      pV F  pRp\	        V\        4      '       d   VP                  '       * pM\        V4      ^8  d
   V^,          p\        V^ ,          4      \        V^,          4      3pVP                  V P                  WvV4      4       K  	  RP                  V4      p\        P                  RV4       V# )ah  
Takes a set of headers and encodes them into a HPACK-encoded header
block.

:param headers: The headers to encode. Must be either an iterable of
                tuples, an iterable of :class:`HeaderTuple
                <hpack.HeaderTuple>`, or a ``dict``.

                If an iterable of tuples, the tuples may be either
                two-tuples or three-tuples. If they are two-tuples, the
                tuples must be of the format ``(name, value)``. If they
                are three-tuples, they must be of the format
                ``(name, value, sensitive)``, where ``sensitive`` is a
                boolean value indicating whether the header should be
                added to header tables anywhere. If not present,
                ``sensitive`` defaults to ``False``.

                If an iterable of :class:`HeaderTuple
                <hpack.HeaderTuple>`, the tuples must always be
                two-tuples. Instead of using ``sensitive`` as a third
                tuple entry, use :class:`NeverIndexedHeaderTuple
                <hpack.NeverIndexedHeaderTuple>` to request that
                the field never be indexed.

                .. warning:: HTTP/2 requires that all special headers
                    (headers whose names begin with ``:`` characters)
                    appear at the *start* of the header block. While
                    this method will ensure that happens for ``dict``
                    subclasses, callers using any other iterable of
                    tuples **must** ensure they place their special
                    headers at the start of the iterable.

                    For efficiency reasons users should prefer to use
                    iterables of two-tuples: fixing the ordering of
                    dictionary headers is an expensive operation that
                    should be avoided if possible.

:param huffman: (optional) Whether to Huffman-encode any header sent as
                a literal value. Except for use when debugging, it is
                recommended that this be left enabled.

:returns: A bytestring containing the HPACK-encoded header block.
Fr   zEncoded header block to %s)rb   rv   r3   _encode_table_size_changerN   rO   rT   iterr   	indexablelenrH   addjoinr/   r0   )	rf   ry   rz   header_blockhpack_headersr   	sensitive
new_headerencodeds	   &&&      r   rX   Encoder.encode   s   p  $$$ > > @A(-D%gt$$ .g6M& !MM $FI&+.. & 0 00	Vq"1I	#F1I.	&)0DEJ HI $ ((<(		.8r   c               (    V ^8  d   QhRRRRRRRR/# )r   to_addztuple[bytes, bytes]r   r   rz   r   r"   r   )r   s   "r   r   r_     s*     / /- /$ / /Z_ /r   c                   \         P                  RVVV4       Vw  rEV'       g   \        M\        pV P                  P                  WE4      pVf8   V P                  WEWc4      pV'       g   V P                  P                  WE4       V# Vw  rp
V
'       d   V P                  V	4      pV# V P                  WWc4      pV'       g   V P                  P                  WE4       V# )z&
Serializes a header key-value tuple.
z7Adding %s to the header table, sensitive:%s, huffman:%s)
r/   r0   INDEX_INCREMENTALINDEX_NEVERrb   search_encode_literalr   _encode_indexed_encode_indexed_literal)rf   r   r   rz   r%   r&   indexbitmatchr   r<   perfects   &&&&       r   r   Encoder.add  s     			E		
  -6$; !!((5= **4JG!!%%d2N
  %W**51G  22hG !!%%d2r   c                    V ^8  d   QhRRRR/# )r   r<   r*   r   r"   r   )r   s   "r   r   r_   M  s      S U r   c                Z    \        V^4      pV^ ;;,          ^,          uu&   \        V4      # )z4
Encodes a header using the indexed representation.
)r7   r"   )rf   r<   fields   && r   r   Encoder._encode_indexedM  s(     ua(aDU|r   c          
     ,    V ^8  d   QhRRRRRRRRRR/# )r   r%   r"   r&   r   rz   r   r   r   )r   s   "r   r   r_   U  s1     
 
E 
% 
5 
SW 
di 
r   c                   V'       d7   V P                   P                  V4      pV P                   P                  V4      p\        \        V4      ^4      p\        \        V4      ^4      pV'       d+   V^ ;;,          ^,          uu&   V^ ;;,          ^,          uu&   RP	                  V\        V4      V\        V4      V.4      # )z
Encodes a header with a literal name and literal value. If ``indexing``
is True, the header will be added to the header table: otherwise it
will not.
r   )rc   rX   r7   r   r   r"   )rf   r%   r&   r   rz   name_len	value_lens   &&&&&  r   r   Encoder._encode_literalU  s     %%,,T2D&&--e4E!#d)Q/"3u:q1	QK4KaLD LxxuXeI.>F
 	
r   c          
     ,    V ^8  d   QhRRRRRRRRRR/# )	r   r<   r*   r&   r"   r   rz   r   r   r   )r   s   "r   r   r_   j  s8     B BS B B% BZ^ Bkp Br   c                |   V\         8w  d   \        V^4      pM\        V^4      pV^ ;;,          \        V4      ,          uu&   V'       d   V P                  P	                  V4      p\        \        V4      ^4      pV'       d   V^ ;;,          ^,          uu&   RP                  \        V4      \        V4      V.4      # )z^
Encodes a header with an indexed name and a literal value and performs
incremental indexing.
r   )r   r7   ordrc   rX   r   r   r"   )rf   r<   r&   r   rz   prefixr   s   &&&&&  r   r   Encoder._encode_indexed_literalj  s    
 ((#E1-F#E1-Fq	S]"	&&--e4E"3u:q1	aLD Lxxvi(8%@AAr   c                   V ^8  d   QhRR/# )r   r   r"   r   )r   s   "r   r   r_     s      5 r   c                    RpV P                    F6  p\        V^4      pV^ ;;,          ^ ,          uu&   V\        V4      ,          pK8  	  . V n         V# )zL
Produces the encoded form of all header table size change context
updates.
r   )rd   r7   r"   )rf   block
size_bytesbs   &   r   r|   !Encoder._encode_table_size_change  sO    
 11Jz1-AaDDLDU1XE 2 #%r   )rb   rc   rd   N)TF)__name__
__module____qualname____firstlineno____doc__rg   propertyrp   setterrX   r   r   r   r   r|   __static_attributes__r   r   r   r[   r[      sa    
0 ) ) 2 2
kZ/b
*B, r   r[   c                      ] tR tRtRt]3R R llt]R R l4       t]P                  R R l4       tRR	 R
 llt
R R ltR R ltR R ltR R ltR R ltR R ltRtR# )Decoderi  a  
An HPACK decoder object.

.. versionchanged:: 2.3.0
   Added ``max_header_list_size`` argument.

:param max_header_list_size: The maximum decompressed size we will allow
    for any single header block. This is a protection against DoS attacks
    that attempt to force the application to expand a relatively small
    amount of data into a really large header list, allowing enormous
    amounts of memory to be allocated.

    If this amount of data is exceeded, a `OversizedHeaderListError
    <hpack.OversizedHeaderListError>` exception will be raised. At this
    point the connection should be shut down, as the HPACK state will no
    longer be usable.

    Defaults to 64kB.
:type max_header_list_size: ``int``
c                    V ^8  d   QhRRRR/# )r   max_header_list_sizer*   r   r^   r   )r   s   "r   r   Decoder.__annotate__  s     @ @S @TX @r   c                	f    \        4       V n        Wn        V P                  P                  V n        R # ra   )r   rb   r   ro   max_allowed_table_size)rf   r   s   &&r   rg   Decoder.__init__  s*    'M  %9! '+&7&7&?&?#r   c                   V ^8  d   QhRR/# rj   r   )r   s   "r   r   r     rk   r   c                .    V P                   P                  # rm   rn   re   s   &r   rp   Decoder.header_table_size  rr   r   c                    V ^8  d   QhRRRR/# rt   r   )r   s   "r   r   r     s     * *s *t *r   c                	&    WP                   n        R # ra   rn   rw   s   &&r   rp   r     s    $)!r   c               $    V ^8  d   QhRRRRRR/# )r   r9   r"   r   r   r   zIterable[HeaderTuple]r   )r   s   "r   r   r     s'     Q3 Q35 Q3t Q38M Q3r   c                |   \         P                  RV4       \        V4      p. p\        V4      p^ p^ pWu8  Ed3   W,          p\	        V^,          4      p	\	        V^@,          4      p
\	        V^ ,          4      pV	'       d   V P                  W7R 4      w  rMfV
'       d   V P                  W7R 4      w  rMHV'       d,   V'       d   Rp\        V4      hV P                  W7R 4      pRpMV P                  W7R 4      w  rV'       d^   VP                  V4       V\        V^ ,          V^,          4      ,          pW`P                  8  d   RV P                   R2p\        V4      hW},          pEK9  V P                  4         V Uu. uF  p\        W4      NK  	  up# u upi   \          d   pRp\        T4      ThRp?ii ; i)a  
Takes an HPACK-encoded header block and decodes it into a header set.

:param data: A bytestring representing a complete HPACK-encoded header
             block.
:param raw: (optional) Whether to return the headers as tuples of raw
            byte strings or to decode them as UTF-8 before returning
            them. The default value is False, which returns tuples of
            Unicode strings
:returns: A list of two-tuples of ``(name, value)`` representing the
          HPACK-encoded headers, in the order they were decoded.
:raises HPACKDecodingError: If an error is encountered while decoding
                            the header block.
zDecoding %sNz/Table size update not at the start of the blockzA header list larger than z has been receivedz!Unable to decode headers as UTF-8)r/   r0   
memoryviewr   r   _decode_indexed_decode_literal_indexr   _update_encoding_context_decode_literal_no_indexr3   r   r   r   _assert_valid_table_sizer'   UnicodeDecodeError)rf   r9   r   data_memry   data_leninflated_sizecurrent_indexcurrentindexedliteral_indexencoding_updater   consumedr4   hrA   s   &&&              r   r$   Decoder.decode  s    			-&d#%'t9& )G7T>*G !40M #7T>2O#'#7#7^,$  #'#=#=^,$  ! KC,S1188^,  $(#@#@^,$  v&!1&)VAY!GG #<#<<6t7P7P6QQcdC2377%M
 	%%'	38?@1&q.@@@! 	35C$S)s2	3s*   =F FF F F;(F66F;c                   V ^8  d   QhRR/# r]   r   )r   s   "r   r   r     s     - -$ -r   c                V    V P                   V P                  8  d   Rp\        V4      hR# )z[
Check that the table size set by the encoder is lower than the maximum
we expect to have.
z3Encoder did not shrink table size to within the maxN)rp   r   r   )rf   r4   s   & r   r    Decoder._assert_valid_table_size  s.    
 !!D$?$??GC',, @r   c                    V ^8  d   QhRRRR/# )r   r9   r"   r   r*   r   )r   s   "r   r   r   '  s     
 
U 
s 
r   c                h    \        V^4      w  r#W P                  8  d   Rp\        V4      hW n        V# )z3
Handles a byte that updates the encoding context.
z)Encoder exceeded max allowable table size)rB   r   r   rp   )rf   r9   new_sizer   r4   s   &&   r   r    Decoder._update_encoding_context'  s:    
 ,D!4111=C',,!)r   c                    V ^8  d   QhRRRR/# r   r9   r"   r   tuple[HeaderTuple, int]r   )r   s   "r   r   r   3  s        E  .E  r   c                    \        V^4      w  r#\        V P                  P                  V4      !  p\        P                  RWC4       WC3# )z@
Decodes a header represented using the indexed representation.
zDecoded %s, consumed %d)rB   r   rb   get_by_indexr/   r0   )rf   r9   r<   r   r   s   &&   r   r   Decoder._decode_indexed3  sE     )q1d//<<UCD		+V>r   c                    V ^8  d   QhRRRR/# r   r   )r   s   "r   r   r   <  s     > >U >7N >r   c                	(    V P                  VR R7      # )Fshould_index_decode_literalrf   r9   s   &&r   r    Decoder._decode_literal_no_index<  s    ##Du#==r   c                    V ^8  d   QhRRRR/# r   r   )r   s   "r   r   r   ?  s     = =% =4K =r   c                	(    V P                  VR R7      # )Tr   r   r   s   &&r   r   Decoder._decode_literal_index?  s    ##Dt#<<r   c               $    V ^8  d   QhRRRRRR/# )r   r9   r"   r   r   r   r   r   )r   s   "r   r   r   B  s'     L& L&E L& L&BY L&r   c                z   ^ pV'       d   V^ ,          ^?,          p^pRpM&V^ ,          pV^,          p^p\        V^,          4      pV'       d5   \        W4      w  rV P                  P                  V4      ^ ,          p
T	p^ pMnVR,          p\        V^4      w  rWW,            p
\	        V
4      V8w  d   Rp\        V4      hV^ ,          ^,          '       d   \        V
4      p
W,           ^,           pWV,           R p\        V^4      w  rWW,            p\	        V4      V8w  d   Rp\        V4      hV^ ,          ^,          '       d   \        V4      pW;V	,           ,          pV'       d   \        W4      pM\        W4      pV'       d   V P                  P                  W4       \        P                  RVVV4       W3# )z.
Decodes a header represented with a literal.
F:   NNzTruncated header blockNz/Decoded %s, total consumed %d bytes, indexed %s)r   rB   rb   r   r   r   r   r   r   r   r/   r0   )rf   r9   r   total_consumedindexed_namer   not_indexable	high_byter<   r   r%   lengthr4   r&   r   s   &&&            r   r   Decoder._decode_literalB  s     7T>LH!MQI$t+LH T!12M,T<OE$$11%8;D%NF 8D-dA6F!23D4yF".(--Aw~~%d+%.2Nv%&' *$2h/0u:*C$S))7T>>"5)E 	8++
 ,T9F -F !!$.		=		
 %%r   )rb   rp   r   r   Nr   )r   r   r   r   r   DEFAULT_MAX_HEADER_LIST_SIZErg   r   rp   r   r$   r   r   r   r   r   r   r   r   r   r   r   r     sm    * 4P @8 ) ) * *Q3f-
 >=L& L&r   r   i   )+r   
__future__r   loggingtypingr   r   
exceptionsr   r   r   rz   r   huffman_constantsr	   r
   huffman_tabler   structr   r   r   tabler   r   collections.abcr   	getLoggerr   r/   
INDEX_NONEr   r   ranger2   r   r'   r7   rB   rT   rH   r[   r   )is   0r   <module>r     s    #  % [ [ # B ) K K 0(!
 
 27q:AAFa<<:   ' 
)>$N$&	!v vr@& @&e ;s   5C