本文整理汇总了Python中codecs.utf_16_ex_decode方法的典型用法代码示例。如果您正苦于以下问题:Python codecs.utf_16_ex_decode方法的具体用法?Python codecs.utf_16_ex_decode怎么用?Python codecs.utf_16_ex_decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类codecs
的用法示例。
在下文中一共展示了codecs.utf_16_ex_decode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_decode_unicode
# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_16_ex_decode [as 别名]
def test_decode_unicode(self):
# Most decoders don't accept unicode input
decoders = [
codecs.utf_7_decode,
codecs.utf_8_decode,
codecs.utf_16_le_decode,
codecs.utf_16_be_decode,
codecs.utf_16_ex_decode,
codecs.utf_32_decode,
codecs.utf_32_le_decode,
codecs.utf_32_be_decode,
codecs.utf_32_ex_decode,
codecs.latin_1_decode,
codecs.ascii_decode,
codecs.charmap_decode,
]
if hasattr(codecs, "mbcs_decode"):
decoders.append(codecs.mbcs_decode)
for decoder in decoders:
self.assertRaises(TypeError, decoder, "xxx")
示例2: _buffer_decode
# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_16_ex_decode [as 别名]
def _buffer_decode(self, input, errors, final):
if self.decoder is None:
(output, consumed, byteorder) = \
codecs.utf_16_ex_decode(input, errors, 0, final)
if byteorder == -1:
self.decoder = codecs.utf_16_le_decode
elif byteorder == 1:
self.decoder = codecs.utf_16_be_decode
elif consumed >= 2:
raise UnicodeError("UTF-16 stream does not start with BOM")
return (output, consumed)
return self.decoder(input, self.errors, final)
示例3: decode
# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_16_ex_decode [as 别名]
def decode(self, input, errors='strict'):
(object, consumed, byteorder) = \
codecs.utf_16_ex_decode(input, errors, 0, False)
if byteorder == -1:
self.decode = codecs.utf_16_le_decode
elif byteorder == 1:
self.decode = codecs.utf_16_be_decode
elif consumed>=2:
raise UnicodeError,"UTF-16 stream does not start with BOM"
return (object, consumed)
### encodings module API
示例4: test_errors
# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_16_ex_decode [as 别名]
def test_errors(self):
self.assertRaises(UnicodeDecodeError, codecs.utf_16_ex_decode, "\xff", "strict", 0, True)
示例5: test_bad_args
# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_16_ex_decode [as 别名]
def test_bad_args(self):
self.assertRaises(TypeError, codecs.utf_16_ex_decode)
示例6: test_utf_16_ex_decode
# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_16_ex_decode [as 别名]
def test_utf_16_ex_decode(self):
#sanity
new_str, size, zero = codecs.utf_16_ex_decode("abc")
self.assertEqual(new_str, u'\u6261')
self.assertEqual(size, 2)
self.assertEqual(zero, 0)
示例7: decode
# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_16_ex_decode [as 别名]
def decode(self, input, errors='strict'):
(object, consumed, byteorder) = \
codecs.utf_16_ex_decode(input, errors, 0, False)
if byteorder == -1:
self.decode = codecs.utf_16_le_decode
elif byteorder == 1:
self.decode = codecs.utf_16_be_decode
elif consumed>=2:
raise UnicodeError("UTF-16 stream does not start with BOM")
return (object, consumed)
### encodings module API