我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用codecs.utf_7_decode()。
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")
def test_errors(self): tests = [ (b'a\xffb', 'a\ufffdb'), (b'a+IK', 'a\ufffd'), (b'a+IK-b', 'a\ufffdb'), (b'a+IK,b', 'a\ufffdb'), (b'a+IKx', 'a\u20ac\ufffd'), (b'a+IKx-b', 'a\u20ac\ufffdb'), (b'a+IKwgr', 'a\u20ac\ufffd'), (b'a+IKwgr-b', 'a\u20ac\ufffdb'), (b'a+IKwgr,', 'a\u20ac\ufffd'), (b'a+IKwgr,-b', 'a\u20ac\ufffd-b'), (b'a+IKwgrB', 'a\u20ac\u20ac\ufffd'), (b'a+IKwgrB-b', 'a\u20ac\u20ac\ufffdb'), (b'a+/,+IKw-b', 'a\ufffd\u20acb'), (b'a+//,+IKw-b', 'a\ufffd\u20acb'), (b'a+///,+IKw-b', 'a\uffff\ufffd\u20acb'), (b'a+////,+IKw-b', 'a\uffff\ufffd\u20acb'), ] for raw, expected in tests: self.assertRaises(UnicodeDecodeError, codecs.utf_7_decode, raw, 'strict', True) self.assertEqual(raw.decode('utf-7', 'replace'), expected)
def test_errors(self): tests = [ ('a\xffb', u'a\ufffdb'), ('a+IK', u'a\ufffd'), ('a+IK-b', u'a\ufffdb'), ('a+IK,b', u'a\ufffdb'), ('a+IKx', u'a\u20ac\ufffd'), ('a+IKx-b', u'a\u20ac\ufffdb'), ('a+IKwgr', u'a\u20ac\ufffd'), ('a+IKwgr-b', u'a\u20ac\ufffdb'), ('a+IKwgr,', u'a\u20ac\ufffd'), ('a+IKwgr,-b', u'a\u20ac\ufffd-b'), ('a+IKwgrB', u'a\u20ac\u20ac\ufffd'), ('a+IKwgrB-b', u'a\u20ac\u20ac\ufffdb'), ('a+/,+IKw-b', u'a\ufffd\u20acb'), ('a+//,+IKw-b', u'a\ufffd\u20acb'), ('a+///,+IKw-b', u'a\uffff\ufffd\u20acb'), ('a+////,+IKw-b', u'a\uffff\ufffd\u20acb'), ] for raw, expected in tests: self.assertRaises(UnicodeDecodeError, codecs.utf_7_decode, raw, 'strict', True) self.assertEqual(raw.decode('utf-7', 'replace'), expected)
def test_errors(self): tests = [ (b'a\xffb', 'a\ufffdb'), (b'a+IK', 'a\ufffd'), (b'a+IK-b', 'a\ufffdb'), (b'a+IK,b', 'a\ufffdb'), (b'a+IKx', 'a\u20ac\ufffd'), (b'a+IKx-b', 'a\u20ac\ufffdb'), (b'a+IKwgr', 'a\u20ac\ufffd'), (b'a+IKwgr-b', 'a\u20ac\ufffdb'), (b'a+IKwgr,', 'a\u20ac\ufffd'), (b'a+IKwgr,-b', 'a\u20ac\ufffd-b'), (b'a+IKwgrB', 'a\u20ac\u20ac\ufffd'), (b'a+IKwgrB-b', 'a\u20ac\u20ac\ufffdb'), (b'a+/,+IKw-b', 'a\ufffd\u20acb'), (b'a+//,+IKw-b', 'a\ufffd\u20acb'), (b'a+///,+IKw-b', 'a\uffff\ufffd\u20acb'), (b'a+////,+IKw-b', 'a\uffff\ufffd\u20acb'), ] for raw, expected in tests: with self.subTest(raw=raw): self.assertRaises(UnicodeDecodeError, codecs.utf_7_decode, raw, 'strict', True) self.assertEqual(raw.decode('utf-7', 'replace'), expected)
def decode(input, errors='strict'): return codecs.utf_7_decode(input, errors, True)
def test_errors(self): tests = [ ('\xe1b', u'\ufffdb'), ('a\xe1b', u'a\ufffdb'), ('a\xe1\xe1b', u'a\ufffd\ufffdb'), ('a+IK', u'a\ufffd'), ('a+IK-b', u'a\ufffdb'), ('a+IK,b', u'a\ufffdb'), ('a+IKx', u'a\u20ac\ufffd'), ('a+IKx-b', u'a\u20ac\ufffdb'), ('a+IKwgr', u'a\u20ac\ufffd'), ('a+IKwgr-b', u'a\u20ac\ufffdb'), ('a+IKwgr,', u'a\u20ac\ufffd'), ('a+IKwgr,-b', u'a\u20ac\ufffd-b'), ('a+IKwgrB', u'a\u20ac\u20ac\ufffd'), ('a+IKwgrB-b', u'a\u20ac\u20ac\ufffdb'), ('a+/,+IKw-b', u'a\ufffd\u20acb'), ('a+//,+IKw-b', u'a\ufffd\u20acb'), ('a+///,+IKw-b', u'a\uffff\ufffd\u20acb'), ('a+////,+IKw-b', u'a\uffff\ufffd\u20acb'), ('a+IKw-b\xe1', u'a\u20acb\ufffd'), ('a+IKw\xe1b', u'a\u20ac\ufffdb'), ] for raw, expected in tests: try: with self.assertRaises(UnicodeDecodeError): codecs.utf_7_decode(raw, 'strict', True) self.assertEqual(raw.decode('utf-7', 'replace'), expected) except: print 'raw=%r' % raw raise