Example #1
0
 def decode_article(self, size):
     res = ""
     while len(res) < size:
         sym_idx = self._ltArticles.decode()
         sym = self._article_symbols[sym_idx]
         if sym <= 0x80:
             if sym <= 0x3F:
                 start_pref_idx = self.bstr.read_bits(tools.bit_length(len(self.prefix)))
                 s = sym + 3
                 res += self.prefix[start_pref_idx:start_pref_idx + s]
             else:
                 start_idx = self.bstr.read_bits(tools.bit_length(size))
                 s = sym - 0x3d
                 res += res[start_idx:start_idx + s]
         else:
             res += int2unichr(sym - 0x80)
     return res
Example #2
0
 def decode_article(self, size):
     res = ""
     while len(res) < size:
         sym_idx = self._ltArticles.decode()
         sym = self._article_symbols[sym_idx]
         if sym <= 0x80:
             if sym <= 0x3F:
                 start_pref_idx = self.bstr.read_bits(
                     tools.bit_length(len(self.prefix)))
                 s = sym + 3
                 res += self.prefix[start_pref_idx:start_pref_idx + s]
             else:
                 start_idx = self.bstr.read_bits(tools.bit_length(size))
                 s = sym - 0x3d
                 res += res[start_idx:start_idx + s]
         else:
             res += unichr(sym - 0x80)
     return res
Example #3
0
    def read_reference(self, huffman_number):
        reference = ""
        code = self.bstr.read_bits(2)
        if code == 3:
            self.bstr.read_bits(32)
            return reference

        size = tools.bit_length(huffman_number)
        assert(size >= 2)
        return (code << (size - 2)) | self.bstr.read_bits(size - 2)
Example #4
0
    def read_reference(self, huffman_number):
        reference = ""
        code = self.bstr.read_bits(2)
        if code == 3:
            self.bstr.read_bits(32)
            return reference

        size = tools.bit_length(huffman_number)
        assert (size >= 2)
        return (code << (size - 2)) | self.bstr.read_bits(size - 2)
Example #5
0
 def decode_article(self, size):
     """
     decode User and Abrv dict
     """
     res = ""
     while len(res) < size:
         sym_idx = self._ltArticles.decode()
         sym = self._article_symbols[sym_idx]
         if sym >= 0x10000:
             if sym >= 0x10040:
                 start_idx = self.bstr.read_bits(tools.bit_length(size))
                 s = sym - 0x1003d
                 res += res[start_idx:start_idx + s]
             else:
                 prefix_idx = self.bstr.read_bits(tools.bit_length(len(self.prefix)))
                 s = sym - 0xfffd
                 res += self.prefix[prefix_idx:prefix_idx + s]
         else:
             res += int2unichr(sym)
     return res
Example #6
0
 def decode_article(self, size):
     """
     decode User and Abrv dict
     """
     res = ""
     while len(res) < size:
         sym_idx = self._ltArticles.decode()
         sym = self._article_symbols[sym_idx]
         if sym >= 0x10000:
             if sym >= 0x10040:
                 start_idx = self.bstr.read_bits(tools.bit_length(size))
                 s = sym - 0x1003d
                 res += res[start_idx:start_idx + s]
             else:
                 prefix_idx = self.bstr.read_bits(
                     tools.bit_length(len(self.prefix)))
                 s = sym - 0xfffd
                 res += self.prefix[prefix_idx:prefix_idx + s]
         else:
             res += unichr(sym)
     return res
Example #7
0
 def test_bit_length_0(self):
     self.assertEqual(tools.bit_length(0), 1)
Example #8
0
 def test_bit_length_4(self):
     self.assertEqual(tools.bit_length(4), 3)
Example #9
0
 def test_bit_length_2(self):
     self.assertEqual(tools.bit_length(2), 2)
Example #10
0
 def test_bit_length_0(self):
     self.assertEqual(tools.bit_length(0), 1)
Example #11
0
 def test_bit_length_4(self):
     self.assertEqual(tools.bit_length(4), 3)
Example #12
0
 def test_bit_length_2(self):
     self.assertEqual(tools.bit_length(2), 2)