o
    D“hÙ	  ã                   @   s(   d Z ddlmZmZ G dd„ deƒZdS )zµ
hpack/huffman_decoder
~~~~~~~~~~~~~~~~~~~~~

An implementation of a bitwise prefix tree specially built for decoding
Huffman-coded content where we already know the Huffman table.
é   )Úto_byteÚ
decode_hexc                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚHuffmanEncoderzj
    Encodes a string according to the Huffman encoding table defined in the
    HPACK specification.
    c                 C   s   || _ || _d S )N)Úhuffman_code_listÚhuffman_code_list_lengths)Úselfr   r   © r   úH/var/www/html/env_mimamsha/lib/python3.10/site-packages/hpack/huffman.pyÚ__init__   s   
zHuffmanEncoder.__init__c                 C   sø   |sdS d}d}|D ]$}t |ƒ}| j| }| j| d|d  d @ }||K }||O }||7 }q
d|d  d }||K }|d|> d O }t|ƒdd…  d¡}t|ƒd dkrZd| n|}|| d }	|	d }
t|ƒ|
krx|
t|ƒ }d| | }t|ƒS )	zm
        Given a string of bytes, encodes them according to the HPACK Huffman
        specification.
        ó    é    é   r   é   NÚLÚ0)r   r   r   ÚhexÚrstripÚlenr   )r   Úbytes_to_encodeÚ	final_numÚfinal_int_lenÚcharÚbyteÚbin_int_lenÚbin_intÚbits_to_be_paddedÚtotal_bytesÚexpected_digitsÚmissing_digitsr   r   r	   Úencode   s0   
ÿ
zHuffmanEncoder.encodeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   r   r   r   r   r	   r      s    r   N)r#   Úcompatr   r   Úobjectr   r   r   r   r	   Ú<module>   s   