当前位置: 首页>>代码示例>>Python>>正文


Python codecs.code_page_decode方法代码示例

本文整理汇总了Python中codecs.code_page_decode方法的典型用法代码示例。如果您正苦于以下问题:Python codecs.code_page_decode方法的具体用法?Python codecs.code_page_decode怎么用?Python codecs.code_page_decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在codecs的用法示例。


在下文中一共展示了codecs.code_page_decode方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: check_decode

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import code_page_decode [as 别名]
def check_decode(self, cp, tests):
        for raw, errors, expected in tests:
            if expected is not None:
                try:
                    decoded = codecs.code_page_decode(cp, raw, errors, True)
                except UnicodeDecodeError as err:
                    self.fail('Unable to decode %a from "cp%s" with '
                              'errors=%r: %s' % (raw, cp, errors, err))
                self.assertEqual(decoded[0], expected,
                    '%a.decode("cp%s", %r)=%a != %a'
                    % (raw, cp, errors, decoded[0], expected))
                # assert 0 <= decoded[1] <= len(raw)
                self.assertGreaterEqual(decoded[1], 0)
                self.assertLessEqual(decoded[1], len(raw))
            else:
                self.assertRaises(UnicodeDecodeError,
                    codecs.code_page_decode, cp, raw, errors, True) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:test_codecs.py

示例2: test_incremental

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import code_page_decode [as 别名]
def test_incremental(self):
        decoded = codecs.code_page_decode(932, b'\x82', 'strict', False)
        self.assertEqual(decoded, ('', 0))

        decoded = codecs.code_page_decode(932,
                                          b'\xe9\x80\xe9', 'strict',
                                          False)
        self.assertEqual(decoded, ('\u9a3e', 2))

        decoded = codecs.code_page_decode(932,
                                          b'\xe9\x80\xe9\x80', 'strict',
                                          False)
        self.assertEqual(decoded, ('\u9a3e\u9a3e', 4))

        decoded = codecs.code_page_decode(932,
                                          b'abc', 'strict',
                                          False)
        self.assertEqual(decoded, ('abc', 3)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:20,代码来源:test_codecs.py

示例3: check_decode

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import code_page_decode [as 别名]
def check_decode(self, cp, tests):
        for raw, errors, expected in tests:
            if expected is not None:
                try:
                    decoded = codecs.code_page_decode(cp, raw, errors)
                except UnicodeDecodeError as err:
                    self.fail('Unable to decode %a from "cp%s" with '
                              'errors=%r: %s' % (raw, cp, errors, err))
                self.assertEqual(decoded[0], expected,
                    '%a.decode("cp%s", %r)=%a != %a'
                    % (raw, cp, errors, decoded[0], expected))
                # assert 0 <= decoded[1] <= len(raw)
                self.assertGreaterEqual(decoded[1], 0)
                self.assertLessEqual(decoded[1], len(raw))
            else:
                self.assertRaises(UnicodeDecodeError,
                    codecs.code_page_decode, cp, raw, errors) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:19,代码来源:test_codecs.py

示例4: decode

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import code_page_decode [as 别名]
def decode(input, errors='strict'):
    return codecs.code_page_decode(65001, input, errors, True) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:4,代码来源:cp65001.py

示例5: test_invalid_code_page

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import code_page_decode [as 别名]
def test_invalid_code_page(self):
        self.assertRaises(ValueError, codecs.code_page_encode, -1, 'a')
        self.assertRaises(ValueError, codecs.code_page_decode, -1, b'a')
        self.assertRaises(OSError, codecs.code_page_encode, 123, 'a')
        self.assertRaises(OSError, codecs.code_page_decode, 123, b'a') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:test_codecs.py

示例6: test_code_page_name

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import code_page_decode [as 别名]
def test_code_page_name(self):
        self.assertRaisesRegex(UnicodeEncodeError, 'cp932',
            codecs.code_page_encode, 932, '\xff')
        self.assertRaisesRegex(UnicodeDecodeError, 'cp932',
            codecs.code_page_decode, 932, b'\x81\x00', 'strict', True)
        self.assertRaisesRegex(UnicodeDecodeError, 'CP_UTF8',
            codecs.code_page_decode, self.CP_UTF8, b'\xff', 'strict', True) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:9,代码来源:test_codecs.py

示例7: test_code_page_name

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import code_page_decode [as 别名]
def test_code_page_name(self):
        self.assertRaisesRegex(UnicodeEncodeError, 'cp932',
            codecs.code_page_encode, 932, '\xff')
        self.assertRaisesRegex(UnicodeDecodeError, 'cp932',
            codecs.code_page_decode, 932, b'\x81\x00')
        self.assertRaisesRegex(UnicodeDecodeError, 'CP_UTF8',
            codecs.code_page_decode, self.CP_UTF8, b'\xff') 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:9,代码来源:test_codecs.py

示例8: test_code_page_decode

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import code_page_decode [as 别名]
def test_code_page_decode(self):
        # Sanity
        self.assertEqual(codecs.code_page_decode(1252, b"aaaa"), ("aaaa", 4))
        self.assertEqual(codecs.code_page_decode(1252, array.array('I', (1633771873,))), ("aaaa", 4))

        self.assertRaises(TypeError, codecs.code_page_decode, "abc")
        self.assertRaises(TypeError, codecs.code_page_decode, None)
        self.assertRaises(TypeError, codecs.code_page_decode, None, None) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:10,代码来源:test_codecs.py


注:本文中的codecs.code_page_decode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。