当前位置: 首页>>代码示例>>Python>>正文


Python codecs.utf_7_decode方法代码示例

本文整理汇总了Python中codecs.utf_7_decode方法的典型用法代码示例。如果您正苦于以下问题:Python codecs.utf_7_decode方法的具体用法?Python codecs.utf_7_decode怎么用?Python codecs.utf_7_decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在codecs的用法示例。


在下文中一共展示了codecs.utf_7_decode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_errors

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_7_decode [as 别名]
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) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:25,代码来源:test_codecs.py

示例2: test_decode_unicode

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_7_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") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:22,代码来源:test_codecs.py

示例3: decode

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_7_decode [as 别名]
def decode(input, errors='strict'):
    return codecs.utf_7_decode(input, errors, True) 
开发者ID:glmcdona,项目名称:meddle,代码行数:4,代码来源:utf_7.py

示例4: test_errors

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_7_decode [as 别名]
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 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:33,代码来源:test_codecs.py

示例5: test_utf_7_decode

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_7_decode [as 别名]
def test_utf_7_decode(self):
        #sanity
        new_str, size = codecs.utf_7_decode("abc")
        self.assertEqual(new_str, u'abc')
        self.assertEqual(size, 3) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:test_codecs.py

示例6: test_errors

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_7_decode [as 别名]
def test_errors(self):
        tests = [
            (b'\xffb', '\ufffdb'),
            (b'a\xffb', 'a\ufffdb'),
            (b'a\xff\xffb', 'a\ufffd\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'),
            (b'a+IKw-b\xff', 'a\u20acb\ufffd'),
            (b'a+IKw\xffb', 'a\u20ac\ufffdb'),
        ]
        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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:30,代码来源:test_codecs.py

示例7: test_utf_7_decode

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import utf_7_decode [as 别名]
def test_utf_7_decode(self):
        #sanity
        new_str, num_processed = codecs.utf_7_decode(b"abc")
        self.assertEqual(new_str, 'abc')
        self.assertEqual(num_processed, 3)

        self.assertEqual(codecs.utf_7_decode(array.array('I', (1633771873,))), ("aaaa", 4))

        self.assertRaises(TypeError, codecs.utf_7_decode, "abc")
        self.assertRaises(TypeError, codecs.utf_7_decode, None)
        self.assertRaises(TypeError, codecs.utf_7_decode, None, None)
        self.assertEqual(codecs.utf_7_decode(b"abc", None), ("abc", 3)) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:14,代码来源:test_codecs.py


注:本文中的codecs.utf_7_decode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。