當前位置: 首頁>>代碼示例>>Python>>正文


Python codecs.code_page_decode方法代碼示例

本文整理匯總了Python中codecs.code_page_decode方法的典型用法代碼示例。如果您正苦於以下問題:Python codecs.code_page_decode方法的具體用法?Python codecs.code_page_decode怎麽用?Python codecs.code_page_decode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在codecs的用法示例。


在下文中一共展示了codecs.code_page_decode方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: check_decode

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import code_page_decode [as 別名]
def check_decode(self, cp, tests):
        for raw, errors, expected in tests:
            if expected is not None:
                try:
                    decoded = codecs.code_page_decode(cp, raw, errors, True)
                except UnicodeDecodeError as err:
                    self.fail('Unable to decode %a from "cp%s" with '
                              'errors=%r: %s' % (raw, cp, errors, err))
                self.assertEqual(decoded[0], expected,
                    '%a.decode("cp%s", %r)=%a != %a'
                    % (raw, cp, errors, decoded[0], expected))
                # assert 0 <= decoded[1] <= len(raw)
                self.assertGreaterEqual(decoded[1], 0)
                self.assertLessEqual(decoded[1], len(raw))
            else:
                self.assertRaises(UnicodeDecodeError,
                    codecs.code_page_decode, cp, raw, errors, True) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:19,代碼來源:test_codecs.py

示例2: test_incremental

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import code_page_decode [as 別名]
def test_incremental(self):
        decoded = codecs.code_page_decode(932, b'\x82', 'strict', False)
        self.assertEqual(decoded, ('', 0))

        decoded = codecs.code_page_decode(932,
                                          b'\xe9\x80\xe9', 'strict',
                                          False)
        self.assertEqual(decoded, ('\u9a3e', 2))

        decoded = codecs.code_page_decode(932,
                                          b'\xe9\x80\xe9\x80', 'strict',
                                          False)
        self.assertEqual(decoded, ('\u9a3e\u9a3e', 4))

        decoded = codecs.code_page_decode(932,
                                          b'abc', 'strict',
                                          False)
        self.assertEqual(decoded, ('abc', 3)) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:20,代碼來源:test_codecs.py

示例3: check_decode

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import code_page_decode [as 別名]
def check_decode(self, cp, tests):
        for raw, errors, expected in tests:
            if expected is not None:
                try:
                    decoded = codecs.code_page_decode(cp, raw, errors)
                except UnicodeDecodeError as err:
                    self.fail('Unable to decode %a from "cp%s" with '
                              'errors=%r: %s' % (raw, cp, errors, err))
                self.assertEqual(decoded[0], expected,
                    '%a.decode("cp%s", %r)=%a != %a'
                    % (raw, cp, errors, decoded[0], expected))
                # assert 0 <= decoded[1] <= len(raw)
                self.assertGreaterEqual(decoded[1], 0)
                self.assertLessEqual(decoded[1], len(raw))
            else:
                self.assertRaises(UnicodeDecodeError,
                    codecs.code_page_decode, cp, raw, errors) 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:19,代碼來源:test_codecs.py

示例4: decode

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import code_page_decode [as 別名]
def decode(input, errors='strict'):
    return codecs.code_page_decode(65001, input, errors, True) 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:4,代碼來源:cp65001.py

示例5: test_invalid_code_page

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import code_page_decode [as 別名]
def test_invalid_code_page(self):
        self.assertRaises(ValueError, codecs.code_page_encode, -1, 'a')
        self.assertRaises(ValueError, codecs.code_page_decode, -1, b'a')
        self.assertRaises(OSError, codecs.code_page_encode, 123, 'a')
        self.assertRaises(OSError, codecs.code_page_decode, 123, b'a') 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:7,代碼來源:test_codecs.py

示例6: test_code_page_name

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import code_page_decode [as 別名]
def test_code_page_name(self):
        self.assertRaisesRegex(UnicodeEncodeError, 'cp932',
            codecs.code_page_encode, 932, '\xff')
        self.assertRaisesRegex(UnicodeDecodeError, 'cp932',
            codecs.code_page_decode, 932, b'\x81\x00', 'strict', True)
        self.assertRaisesRegex(UnicodeDecodeError, 'CP_UTF8',
            codecs.code_page_decode, self.CP_UTF8, b'\xff', 'strict', True) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:9,代碼來源:test_codecs.py

示例7: test_code_page_name

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import code_page_decode [as 別名]
def test_code_page_name(self):
        self.assertRaisesRegex(UnicodeEncodeError, 'cp932',
            codecs.code_page_encode, 932, '\xff')
        self.assertRaisesRegex(UnicodeDecodeError, 'cp932',
            codecs.code_page_decode, 932, b'\x81\x00')
        self.assertRaisesRegex(UnicodeDecodeError, 'CP_UTF8',
            codecs.code_page_decode, self.CP_UTF8, b'\xff') 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:9,代碼來源:test_codecs.py

示例8: test_code_page_decode

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import code_page_decode [as 別名]
def test_code_page_decode(self):
        # Sanity
        self.assertEqual(codecs.code_page_decode(1252, b"aaaa"), ("aaaa", 4))
        self.assertEqual(codecs.code_page_decode(1252, array.array('I', (1633771873,))), ("aaaa", 4))

        self.assertRaises(TypeError, codecs.code_page_decode, "abc")
        self.assertRaises(TypeError, codecs.code_page_decode, None)
        self.assertRaises(TypeError, codecs.code_page_decode, None, None) 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:10,代碼來源:test_codecs.py


注:本文中的codecs.code_page_decode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。