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