
    g	                         d Z  G d d      Zy)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.
c                       e Zd ZdZd Z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      B/var/www/openai/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
                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total_bytesexpected_digitsmissing_digitss              r   encodezHuffmanEncoder.encode   s:    	
 $D88>K,,T2kAo&*G +%I I[(M $ -!"349''	a,,11	 	N12&--c2	 (+9~'9Q'>C)OI	
 %'88Q>%/y>_,,s9~=N~-:I}}Y''r
   N)__name__
__module____qualname____doc__r	   r!    r
   r   r   r      s    C.(r
   r   N)r%   r   r&   r
   r   <module>r'      s   7( 7(r
   