
    &XhO	                    (    d Z ddlmZ  G d d      Zy)z
An implementation of a bitwise prefix tree specially built for decoding
Huffman-coded content where we already know the Huffman table.
    )annotationsc                       e Zd ZdZddZddZy)HuffmanEncoderzj
    Encodes a string according to the Huffman encoding table defined in the
    HPACK specification.
    c                     || _         || _        y )N)huffman_code_listhuffman_code_list_lengths)selfr   r   s      7/RAG/venv/lib/python3.12/site-packages/hpack/huffman.py__init__zHuffmanEncoder.__init__   s    !2)B&    c                   |syd}d}|D ];  }| j                   |   }| j                  |   d|dz   z  dz
  z  }||z  }||z  }||z  }= d|dz  z
  dz  }||z  }|d|z  dz
  z  }t        |      dd j                  d      }t	        |      dz  dk7  rd|z   n|}||z   dz  }	|	dz  }
t	        |      |
k7  r|
t	        |      z
  }d|z  |z   }t
        j                  |      S )	zm
        Given a string of bytes, encodes them according to the HPACK Huffman
        specification.
        r   r            NL0)r   r   hexrstriplenbytesfromhex)r	   bytes_to_encode	final_numfinal_int_lenbytebin_int_lenbin_intbits_to_be_paddedstotal_bytesexpected_digitsmissing_digitss               r
   encodezHuffmanEncoder.encode   s8    	
 $D88>K,,T2kAo&*G +%I I[(M $ -!"349''	a,,11	 	N12%%c* 1vzQC!GA
 %'88Q>%/q6_$,s1v5N~%*A}}Qr   N)r   	list[int]r   r$   returnNone)r   zbytes | Noner%   r   )__name__
__module____qualname____doc__r   r#    r   r
   r   r      s    
C. r   r   N)r*   
__future__r   r   r+   r   r
   <module>r-      s    #8  8 r   