Python codecs 模块,code_page_decode() 实例源码

我们从Python开源项目中,提取了以下24个代码示例,用于说明如何使用codecs.code_page_decode()

项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
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)
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
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))
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
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)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
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))
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
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)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
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))
项目:python-    作者:secondtonone1    | 项目源码 | 文件源码
def decode(input, errors='strict'):
    return codecs.code_page_decode(65001, input, errors, True)
项目:ivaochdoc    作者:ivaoch    | 项目源码 | 文件源码
def decode(input, errors='strict'):
    return codecs.code_page_decode(65001, input, errors, True)
项目:news-for-good    作者:thecodinghub    | 项目源码 | 文件源码
def decode(input, errors='strict'):
    return codecs.code_page_decode(65001, input, errors, True)
项目:Tencent_Cartoon_Download    作者:Fretice    | 项目源码 | 文件源码
def decode(input, errors='strict'):
    return codecs.code_page_decode(65001, input, errors, True)
项目:fieldsight-kobocat    作者:awemulya    | 项目源码 | 文件源码
def decode(input, errors='strict'):
    return codecs.code_page_decode(65001, input, errors, True)
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
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(WindowsError, codecs.code_page_encode, 123, 'a')
        self.assertRaises(WindowsError, codecs.code_page_decode, 123, b'a')
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
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')
项目:CloudPrint    作者:William-An    | 项目源码 | 文件源码
def decode(input, errors='strict'):
    return codecs.code_page_decode(65001, input, errors, True)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
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')
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
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')
项目:gardenbot    作者:GoestaO    | 项目源码 | 文件源码
def decode(input, errors='strict'):
    return codecs.code_page_decode(65001, input, errors, True)
项目:projeto    作者:BarmyPenguin    | 项目源码 | 文件源码
def decode(input, errors='strict'):
    return codecs.code_page_decode(65001, input, errors, True)
项目:flask-zhenai-mongo-echarts    作者:Fretice    | 项目源码 | 文件源码
def decode(input, errors='strict'):
    return codecs.code_page_decode(65001, input, errors, True)
项目:aweasome_learning    作者:Knight-ZXW    | 项目源码 | 文件源码
def decode(input, errors='strict'):
    return codecs.code_page_decode(65001, input, errors, True)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
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')
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
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')
项目:blog_flask    作者:momantai    | 项目源码 | 文件源码
def decode(input, errors='strict'):
    return codecs.code_page_decode(65001, input, errors, True)
项目:MyFriend-Rob    作者:lcheniv    | 项目源码 | 文件源码
def decode(input, errors='strict'):
    return codecs.code_page_decode(65001, input, errors, True)