本文整理汇总了Python中codecs.utf_16_decode方法的典型用法代码示例。如果您正苦于以下问题:Python codecs.utf_16_decode方法的具体用法?Python codecs.utf_16_decode怎么用?Python codecs.utf_16_decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类codecs
的用法示例。
在下文中一共展示了codecs.utf_16_decode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_utf_16_decode
# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_16_decode [as 别名]
def test_utf_16_decode(self):
# When BOM present: it is removed and the proper UTF-16 variant is automatically selected
string, num_processed = codecs.utf_16_decode(codecs.BOM_UTF16_LE + b'a\0b\0c\0')
self.assertEqual(string, "abc")
self.assertEqual(num_processed, 4 * 2)
string, num_processed = codecs.utf_16_decode(codecs.BOM_UTF16_BE + b'\0a\0b\0c')
self.assertEqual(string, "abc")
self.assertEqual(num_processed, 4 * 2)
# When no BOM: on little-endian systems, UTF-16 defaults to UTF-16-LE
string, num_processed = codecs.utf_16_decode(b'a\0b\0c\0')
self.assertEqual(string, 'abc')
self.assertEqual(num_processed, 3 * 2)
self.assertEqual(codecs.utf_16_decode(array.array('I', (1633771873,))), ("慡慡", 4))
self.assertRaises(TypeError, codecs.utf_16_decode, "abc")
self.assertRaises(TypeError, codecs.utf_16_decode, None)
self.assertRaises(TypeError, codecs.utf_16_decode, None, None)
self.assertEquals(codecs.utf_16_decode(b"", None), ("", 0))
示例2: decode
# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_16_decode [as 别名]
def decode(input, errors='strict'):
return codecs.utf_16_decode(input, errors, True)
示例3: test_handlers
# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_16_decode [as 别名]
def test_handlers(self):
self.assertEqual((u'\ufffd', 1),
codecs.utf_16_decode('\x01', 'replace', True))
self.assertEqual((u'', 1),
codecs.utf_16_decode('\x01', 'ignore', True))
示例4: test_errors
# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_16_decode [as 别名]
def test_errors(self):
self.assertRaises(UnicodeDecodeError, codecs.utf_16_decode, "\xff", "strict", True)
示例5: test_utf_16_decode
# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_16_decode [as 别名]
def test_utf_16_decode(self):
#sanity
new_str, size = codecs.utf_16_decode("abc")
self.assertEqual(new_str, u'\u6261')
self.assertEqual(size, 2)
示例6: test_handlers
# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_16_decode [as 别名]
def test_handlers(self):
self.assertEqual(('\ufffd', 1),
codecs.utf_16_decode(b'\x01', 'replace', True))
self.assertEqual(('', 1),
codecs.utf_16_decode(b'\x01', 'ignore', True))
示例7: test_errors
# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_16_decode [as 别名]
def test_errors(self):
self.assertRaises(UnicodeDecodeError, codecs.utf_16_decode,
b"\xff", "strict", True)