當前位置: 首頁>>代碼示例>>Python>>正文


Python binascii.rledecode_hqx方法代碼示例

本文整理匯總了Python中binascii.rledecode_hqx方法的典型用法代碼示例。如果您正苦於以下問題:Python binascii.rledecode_hqx方法的具體用法?Python binascii.rledecode_hqx怎麽用?Python binascii.rledecode_hqx使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在binascii的用法示例。


在下文中一共展示了binascii.rledecode_hqx方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _fill

# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import rledecode_hqx [as 別名]
def _fill(self, wtd):
        self.pre_buffer = self.pre_buffer + self.ifp.read(wtd+4)
        if self.ifp.eof:
            self.post_buffer = self.post_buffer + \
                binascii.rledecode_hqx(self.pre_buffer)
            self.pre_buffer = ''
            return

        #
        # Obfuscated code ahead. We have to take care that we don't
        # end up with an orphaned RUNCHAR later on. So, we keep a couple
        # of bytes in the buffer, depending on what the end of
        # the buffer looks like:
        # '\220\0\220' - Keep 3 bytes: repeated \220 (escaped as \220\0)
        # '?\220' - Keep 2 bytes: repeated something-else
        # '\220\0' - Escaped \220: Keep 2 bytes.
        # '?\220?' - Complete repeat sequence: decode all
        # otherwise: keep 1 byte.
        #
        mark = len(self.pre_buffer)
        if self.pre_buffer[-3:] == RUNCHAR + '\0' + RUNCHAR:
            mark = mark - 3
        elif self.pre_buffer[-1] == RUNCHAR:
            mark = mark - 2
        elif self.pre_buffer[-2:] == RUNCHAR + '\0':
            mark = mark - 2
        elif self.pre_buffer[-2] == RUNCHAR:
            pass # Decode all
        else:
            mark = mark - 1

        self.post_buffer = self.post_buffer + \
            binascii.rledecode_hqx(self.pre_buffer[:mark])
        self.pre_buffer = self.pre_buffer[mark:] 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:36,代碼來源:binhex.py

示例2: test_hqx

# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import rledecode_hqx [as 別名]
def test_hqx(self):
        # Perform binhex4 style RLE-compression
        # Then calculate the hexbin4 binary-to-ASCII translation
        rle = binascii.rlecode_hqx(self.data)
        a = binascii.b2a_hqx(self.type2test(rle))
        b, _ = binascii.a2b_hqx(self.type2test(a))
        res = binascii.rledecode_hqx(b)

        self.assertEqual(res, self.rawdata) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:11,代碼來源:test_binascii.py

示例3: test_not_implemented

# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import rledecode_hqx [as 別名]
def test_not_implemented(self):
        test_cases = [
                        lambda: binascii.a2b_qp(None),
                        lambda: binascii.a2b_qp(None, None),
                        lambda: binascii.a2b_hqx(None),
                        lambda: binascii.rledecode_hqx(None),
                        lambda: binascii.rlecode_hqx(None),
                        lambda: binascii.b2a_hqx(None),
                        ]
        for temp_func in test_cases:
            self.assertRaises(NotImplementedError, temp_func) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:13,代碼來源:test_binascii.py

示例4: _fill

# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import rledecode_hqx [as 別名]
def _fill(self, wtd):
        self.pre_buffer = self.pre_buffer + self.ifp.read(wtd + 4)
        if self.ifp.eof:
            self.post_buffer = self.post_buffer + \
                binascii.rledecode_hqx(self.pre_buffer)
            self.pre_buffer = b''
            return

        #
        # Obfuscated code ahead. We have to take care that we don't
        # end up with an orphaned RUNCHAR later on. So, we keep a couple
        # of bytes in the buffer, depending on what the end of
        # the buffer looks like:
        # '\220\0\220' - Keep 3 bytes: repeated \220 (escaped as \220\0)
        # '?\220' - Keep 2 bytes: repeated something-else
        # '\220\0' - Escaped \220: Keep 2 bytes.
        # '?\220?' - Complete repeat sequence: decode all
        # otherwise: keep 1 byte.
        #
        mark = len(self.pre_buffer)
        if self.pre_buffer[-3:] == RUNCHAR + b'\0' + RUNCHAR:
            mark = mark - 3
        elif self.pre_buffer[-1:] == RUNCHAR:
            mark = mark - 2
        elif self.pre_buffer[-2:] == RUNCHAR + b'\0':
            mark = mark - 2
        elif self.pre_buffer[-2:-1] == RUNCHAR:
            pass # Decode all
        else:
            mark = mark - 1

        self.post_buffer = self.post_buffer + \
            binascii.rledecode_hqx(self.pre_buffer[:mark])
        self.pre_buffer = self.pre_buffer[mark:] 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:36,代碼來源:binhex.py

示例5: test_unicode_b2a

# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import rledecode_hqx [as 別名]
def test_unicode_b2a(self):
        # Unicode strings are not accepted by b2a_* functions.
        for func in set(all_functions) - set(a2b_functions) | {'rledecode_hqx'}:
            try:
                self.assertRaises(TypeError, getattr(binascii, func), "test")
            except Exception as err:
                self.fail('{}("test") raises {!r}'.format(func, err))
        # crc_hqx needs 2 arguments
        self.assertRaises(TypeError, binascii.crc_hqx, "test", 0) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:11,代碼來源:test_binascii.py

示例6: test_unicode_a2b

# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import rledecode_hqx [as 別名]
def test_unicode_a2b(self):
        # Unicode strings are accepted by a2b_* functions.
        MAX_ALL = 45
        raw = self.rawdata[:MAX_ALL]
        for fa, fb in zip(a2b_functions, b2a_functions):
            if fa == 'rledecode_hqx':
                # Takes non-ASCII data
                continue
            a2b = getattr(binascii, fa)
            b2a = getattr(binascii, fb)
            try:
                a = b2a(self.type2test(raw))
                binary_res = a2b(a)
                a = a.decode('ascii')
                res = a2b(a)
            except Exception as err:
                self.fail("{}/{} conversion raises {!r}".format(fb, fa, err))
            if fb == 'b2a_hqx':
                # b2a_hqx returns a tuple
                res, _ = res
                binary_res, _ = binary_res
            self.assertEqual(res, raw, "{}/{} conversion: "
                             "{!r} != {!r}".format(fb, fa, res, raw))
            self.assertEqual(res, binary_res)
            self.assertIsInstance(res, bytes)
            # non-ASCII string
            self.assertRaises(ValueError, a2b, "\x80") 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:29,代碼來源:test_binascii.py

示例7: test_unicode_b2a

# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import rledecode_hqx [as 別名]
def test_unicode_b2a(self):
        # Unicode strings are not accepted by b2a_* functions.
        for func in set(all_functions) - set(a2b_functions) | {'rledecode_hqx'}:
            if sys.implementation.name == "ironpython" and func == 'rledecode_hqx': continue
            try:
                self.assertRaises(TypeError, getattr(binascii, func), "test")
            except Exception as err:
                self.fail('{}("test") raises {!r}'.format(func, err))
        # crc_hqx needs 2 arguments
        self.assertRaises(TypeError, binascii.crc_hqx, "test", 0) 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:12,代碼來源:test_binascii.py


注:本文中的binascii.rledecode_hqx方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。