
    hO	                    0    d Z ddlmZ  G 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                  "    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.
    huffman_code_list	list[int]huffman_code_list_lengthsreturnNonec                "    || _         || _        d S )N)r   r   )selfr   r   s      Q/var/www/html/e360mart/e360mart_env/lib/python3.11/site-packages/hpack/huffman.py__init__zHuffmanEncoder.__init__   s    !2)B&&&    bytes_to_encodebytes | Nonebytesc                   |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   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_digitss               r   encodezHuffmanEncoder.encode   sW     	3	
 $ 	) 	)D8>K,T2kAo&*G +%I I[(MM -!"349''	a,,11	 	NN122%%c** 1vvzQC!GGA
 %'88Q>%/q66_$$,s1vv5N~%*A}}Qr   N)r   r   r   r   r	   r
   )r   r   r	   r   )__name__
__module____qualname____doc__r   r'    r   r   r   r      sJ         
C C C C.  .  .  .  .  . r   r   N)r+   
__future__r   r   r,   r   r   <module>r.      sU     # " " " " "8  8  8  8  8  8  8  8  8  8 r   