本文整理匯總了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)