
    Ng	                     $    d Z  G d d          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.
c                       e Zd ZdZd Zd ZdS )HuffmanEncoderzj
    Encodes a string according to the Huffman encoding table defined in the
    HPACK specification.
    c                 "    || _         || _        d S )N)huffman_code_listhuffman_code_list_lengths)selfr   r   s      I/var/www/html/ai-engine/env/lib/python3.11/site-packages/hpack/huffman.py__init__zHuffmanEncoder.__init__   s    !2)B&&&    c                    |sdS d}d}|D ]7}| j         |         }| j        |         d|dz   z  dz
  z  }||z  }||z  }||z  }8d|dz  z
  dz  }||z  }|d|z  dz
  z  }t          |          dd                             d          }t	          |          dz  dk    rd|z   n|}||z   dz  }|dz  }	t	          |          |	k    r|	t	          |          z
  }
d|
z  |z   }t
                              |          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   sZ     	3	
 $ 	) 	)D8>K,T2kAo&*G +%I I[(MM -!"349''	a,,11	 	NN122&--c22	 (+9~~'9Q'>'>C)OOI	
 %'88Q>%/y>>_,,,s9~~=N~-:I}}Y'''r
   N)__name__
__module____qualname____doc__r	   r!    r
   r   r   r      s?         C C C.( .( .( .( .(r
   r   N)r%   r   r&   r
   r   <module>r'      sA    7( 7( 7( 7( 7( 7( 7( 7( 7( 7(r
   