o
    <iO	                     @  s"   d Z ddlmZ G dd dZdS )z
An implementation of a bitwise prefix tree specially built for decoding
Huffman-coded content where we already know the Huffman table.
    )annotationsc                   @  s$   e Zd ZdZdddZdddZdS )HuffmanEncoderzj
    Encodes a string according to the Huffman encoding table defined in the
    HPACK specification.
    huffman_code_list	list[int]huffman_code_list_lengthsreturnNonec                 C  s   || _ || _d S )N)r   r   )selfr   r    r
   J/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/hpack/huffman.py__init__   s   
zHuffmanEncoder.__init__bytes_to_encodebytes | Nonebytesc                 C  s   |sdS d}d}|D ] }| j | }| j| d|d  d @ }||K }||O }||7 }q
d|d  d }||K }|d|> d O }t|dd d}t|d dkrVd| n|}|| d }	|	d }
t||
krt|
t| }d| | }t|S )	zm
        Given a string of bytes, encodes them according to the HPACK Huffman
        specification.
            r            NL0)r   r   hexrstriplenr   fromhex)r	   r   	final_numfinal_int_lenbytebin_int_lenbin_intbits_to_be_paddedstotal_bytesexpected_digitsmissing_digitsr
   r
   r   encode   s.   


zHuffmanEncoder.encodeN)r   r   r   r   r   r   )r   r   r   r   )__name__
__module____qualname____doc__r   r$   r
   r
   r
   r   r      s    
r   N)r(   
__future__r   r   r
   r
   r
   r   <module>   s    