本文整理汇总了Python中codecs.latin_1_decode方法的典型用法代码示例。如果您正苦于以下问题:Python codecs.latin_1_decode方法的具体用法?Python codecs.latin_1_decode怎么用?Python codecs.latin_1_decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类codecs
的用法示例。
在下文中一共展示了codecs.latin_1_decode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_decode_unicode
# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import latin_1_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: get_entitydefs
# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import latin_1_decode [as 别名]
def get_entitydefs():
import htmlentitydefs
from codecs import latin_1_decode
entitydefs = {}
try:
htmlentitydefs.name2codepoint
except AttributeError:
entitydefs = {}
for name, char in htmlentitydefs.entitydefs.items():
uc = latin_1_decode(char)[0]
if uc.startswith("&#") and uc.endswith(";"):
uc = unescape_charref(uc[2:-1], None)
entitydefs["&%s;" % name] = uc
else:
for name, codepoint in htmlentitydefs.name2codepoint.items():
entitydefs["&%s;" % name] = unichr(codepoint)
return entitydefs
示例3: decode
# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import latin_1_decode [as 别名]
def decode(self, input, final=False):
return codecs.latin_1_decode(input,self.errors)[0]
示例4: test_latin_1_decode
# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import latin_1_decode [as 别名]
def test_latin_1_decode(self):
#sanity
new_str, size = codecs.latin_1_decode("abc")
self.assertEqual(new_str, u'abc')
self.assertEqual(size, 3)
示例5: name2cp
# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import latin_1_decode [as 别名]
def name2cp(k):
if k == 'apos': return ord("'")
if hasattr(htmlentitydefs, "name2codepoint"): # requires Python 2.3
return htmlentitydefs.name2codepoint[k]
else:
k = htmlentitydefs.entitydefs[k]
if k.startswith("&#") and k.endswith(";"): return int(k[2:-1]) # not in latin-1
return ord(codecs.latin_1_decode(k)[0])
示例6: makestring
# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import latin_1_decode [as 别名]
def makestring(x):
return codecs.latin_1_decode(x)[0]
示例7: test_latin_1_decode
# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import latin_1_decode [as 别名]
def test_latin_1_decode(self):
#sanity
new_str, num_processed = codecs.latin_1_decode(b"abc")
self.assertEqual(new_str, 'abc')
self.assertEqual(num_processed, 3)
self.assertEqual(codecs.latin_1_decode(array.array('I', (1633771873,))), ("aaaa", 4))
self.assertRaises(TypeError, codecs.latin_1_decode, "abc")
self.assertRaises(TypeError, codecs.latin_1_decode, None)
self.assertRaises(TypeError, codecs.latin_1_decode, None, None)