本文整理汇总了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)
示例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))
示例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)
示例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)
示例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')
示例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)
示例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')
示例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)