當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。