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


Python codecs.unicode_escape_decode方法代码示例

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


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

示例1: test_unicode_escape

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import unicode_escape_decode [as 别名]
def test_unicode_escape(self):
        # Escape-decoding an unicode string is supported ang gives the same
        # result as decoding the equivalent ASCII bytes string.
        self.assertEqual(codecs.unicode_escape_decode(r"\u1234"), ("\u1234", 6))
        self.assertEqual(codecs.unicode_escape_decode(br"\u1234"), ("\u1234", 6))
        self.assertEqual(codecs.raw_unicode_escape_decode(r"\u1234"), ("\u1234", 6))
        self.assertEqual(codecs.raw_unicode_escape_decode(br"\u1234"), ("\u1234", 6))

        self.assertRaises(UnicodeDecodeError, codecs.unicode_escape_decode, br"\U00110000")
        self.assertEqual(codecs.unicode_escape_decode(r"\U00110000", "replace"), ("\ufffd", 10))
        self.assertEqual(codecs.unicode_escape_decode(r"\U00110000", "backslashreplace"),
                         (r"\x5c\x55\x30\x30\x31\x31\x30\x30\x30\x30", 10))

        self.assertRaises(UnicodeDecodeError, codecs.raw_unicode_escape_decode, br"\U00110000")
        self.assertEqual(codecs.raw_unicode_escape_decode(r"\U00110000", "replace"), ("\ufffd", 10))
        self.assertEqual(codecs.raw_unicode_escape_decode(r"\U00110000", "backslashreplace"),
                         (r"\x5c\x55\x30\x30\x31\x31\x30\x30\x30\x30", 10)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:test_codecs.py

示例2: test_unicode_escape_decode_errors_ignore

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import unicode_escape_decode [as 别名]
def test_unicode_escape_decode_errors_ignore(self):
        test_data = [
            (b"abc\\xyz", "abcyz"),
            (b"abc\\x0xyz", "abcxyz"),
            (b"abc\\u20klm\xffxyz", "abcklm\xffxyz"),
            (b"abc\\U0001F44xyz", "abcxyz"),
            (b"abc\\U00110011xyz", "abcxyz"),
            (b"abc\\N{EURO}xyz", "abcxyz"),
            (b"abc\\Nxyz", "abcxyz"),
            (b"abc\\N", "abc"),
            (b"abc\\N{xyz", "abc"),
            (b"abc\\N{", "abc"),
            (b"abc\\N{}xyz", "abc}xyz"),
            (b"abc\\N{}", "abc}"),
            (b"abc\\", "abc"),
        ]

        for sample in test_data:
            self.assertEqual(codecs.unicode_escape_decode(sample[0], 'ignore')[0], sample[1]) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:21,代码来源:test_codecs.py

示例3: test_unicode_escape_decode_errors_replace

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import unicode_escape_decode [as 别名]
def test_unicode_escape_decode_errors_replace(self):
        test_data = [
            (b"abc\\xyz", "abc�yz"),
            (b"abc\\x0xyz", "abc�xyz"),
            (b"abc\\u20klm\xffxyz", "abc�klm\xffxyz"),
            (b"abc\\U0001F44xyz", "abc�xyz"),
            (b"abc\\U00110011xyz", "abc�xyz"),
            (b"abc\\N{EURO}xyz", "abc�xyz"),
            (b"abc\\Nxyz", "abc�xyz"),
            (b"abc\\N", "abc�"),
            (b"abc\\N{xyz", "abc�"),
            (b"abc\\N{", "abc�"),
            (b"abc\\N{}xyz", "abc�}xyz"),
            (b"abc\\N{}", "abc�}"),
            (b"abc\\", "abc�"),
        ]

        for sample in test_data:
            self.assertEqual(codecs.unicode_escape_decode(sample[0], 'replace')[0], sample[1]) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:21,代码来源:test_codecs.py

示例4: test_unicode_escape

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import unicode_escape_decode [as 别名]
def test_unicode_escape(self):
        # Escape-decoding a unicode string is supported and gives the same
        # result as decoding the equivalent ASCII bytes string.
        self.assertEqual(codecs.unicode_escape_decode(r"\u1234"), ("\u1234", 6))
        self.assertEqual(codecs.unicode_escape_decode(br"\u1234"), ("\u1234", 6))
        self.assertEqual(codecs.raw_unicode_escape_decode(r"\u1234"), ("\u1234", 6))
        self.assertEqual(codecs.raw_unicode_escape_decode(br"\u1234"), ("\u1234", 6))

        self.assertRaises(UnicodeDecodeError, codecs.unicode_escape_decode, br"\U00110000")
        self.assertEqual(codecs.unicode_escape_decode(r"\U00110000", "replace"), ("\ufffd", 10))
        self.assertEqual(codecs.unicode_escape_decode(r"\U00110000", "backslashreplace"),
                         (r"\x5c\x55\x30\x30\x31\x31\x30\x30\x30\x30", 10))

        self.assertRaises(UnicodeDecodeError, codecs.raw_unicode_escape_decode, br"\U00110000")
        self.assertEqual(codecs.raw_unicode_escape_decode(r"\U00110000", "replace"), ("\ufffd", 10))
        self.assertEqual(codecs.raw_unicode_escape_decode(r"\U00110000", "backslashreplace"),
                         (r"\x5c\x55\x30\x30\x31\x31\x30\x30\x30\x30", 10)) 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:19,代码来源:test_codecs.py

示例5: u

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import unicode_escape_decode [as 别名]
def u(x):
        return codecs.unicode_escape_decode(x)[0] 
开发者ID:tdw1980,项目名称:tdw,代码行数:4,代码来源:addons_xml_generator_new.py

示例6: decode

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

示例7: test_empty

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import unicode_escape_decode [as 别名]
def test_empty(self):
        self.assertEqual(codecs.unicode_escape_encode(u""), ("", 0))
        self.assertEqual(codecs.unicode_escape_decode(""), (u"", 0)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_codecs.py

示例8: test_raw_decode

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import unicode_escape_decode [as 别名]
def test_raw_decode(self):
        decode = codecs.unicode_escape_decode
        for b in range(256):
            if b != ord('\\'):
                self.assertEqual(decode(chr(b) + '0'), (unichr(b) + u'0', 2)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:test_codecs.py

示例9: test_escape_decode

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import unicode_escape_decode [as 别名]
def test_escape_decode(self):
        decode = codecs.unicode_escape_decode
        check = coding_checker(self, decode)
        check("[\\\n]", u"[]")
        check(r'[\"]', u'["]')
        check(r"[\']", u"[']")
        check(r"[\\]", ur"[\]")
        check(r"[\a]", u"[\x07]")
        check(r"[\b]", u"[\x08]")
        check(r"[\t]", u"[\x09]")
        check(r"[\n]", u"[\x0a]")
        check(r"[\v]", u"[\x0b]")
        check(r"[\f]", u"[\x0c]")
        check(r"[\r]", u"[\x0d]")
        check(r"[\7]", u"[\x07]")
        check(r"[\8]", ur"[\8]")
        check(r"[\78]", u"[\x078]")
        check(r"[\41]", u"[!]")
        check(r"[\418]", u"[!8]")
        check(r"[\101]", u"[A]")
        check(r"[\1010]", u"[A0]")
        check(r"[\x41]", u"[A]")
        check(r"[\x410]", u"[A0]")
        check(r"\u20ac", u"\u20ac")
        check(r"\U0001d120", u"\U0001d120")
        for b in range(256):
            if chr(b) not in '\n"\'\\abtnvfr01234567xuUN':
                check('\\' + chr(b), u'\\' + unichr(b)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:30,代码来源:test_codecs.py

示例10: test_decode_errors

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import unicode_escape_decode [as 别名]
def test_decode_errors(self):
        decode = codecs.unicode_escape_decode
        for c, d in ('x', 2), ('u', 4), ('U', 4):
            for i in range(d):
                self.assertRaises(UnicodeDecodeError, decode,
                                  "\\" + c + "0"*i)
                self.assertRaises(UnicodeDecodeError, decode,
                                  "[\\" + c + "0"*i + "]")
                data = "[\\" + c + "0"*i + "]\\" + c + "0"*i
                self.assertEqual(decode(data, "ignore"), (u"[]", len(data)))
                self.assertEqual(decode(data, "replace"),
                                 (u"[\ufffd]\ufffd", len(data)))
        self.assertRaises(UnicodeDecodeError, decode, r"\U00110000")
        self.assertEqual(decode(r"\U00110000", "ignore"), (u"", 10))
        self.assertEqual(decode(r"\U00110000", "replace"), (u"\ufffd", 10)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:17,代码来源:test_codecs.py

示例11: u

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import unicode_escape_decode [as 别名]
def u(self, string):
        """Create a unicode string, compatible across all versions of Python."""
        # NOTE(cbro): Python 3-3.2 does not have the u'' syntax.
        return codecs.unicode_escape_decode(string)[0] 
开发者ID:googlemaps,项目名称:google-maps-services-python,代码行数:6,代码来源:__init__.py

示例12: u

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import unicode_escape_decode [as 别名]
def u(obj):
        """Make unicode object"""
        return codecs.unicode_escape_decode(obj)[0] 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:5,代码来源:py3compat.py

示例13: u

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import unicode_escape_decode [as 别名]
def u(string):
        return codecs.unicode_escape_decode(string)[0]

# dict.iteritems(), dict.iterkeys() is also incompatible 
开发者ID:yyht,项目名称:BERT,代码行数:6,代码来源:python3_compat.py

示例14: decode_css_url

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import unicode_escape_decode [as 别名]
def decode_css_url(url: str) -> str:
    url = re.sub(r'\\(..) ', r'\\x\g<1>', url)
    url, _ = codecs.unicode_escape_decode(url)
    return url 
开发者ID:kevinzg,项目名称:facebook-scraper,代码行数:6,代码来源:utils.py

示例15: u

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import unicode_escape_decode [as 别名]
def u(string):
        return codecs.unicode_escape_decode(string)[0] 
开发者ID:tinybike,项目名称:coinbridge,代码行数:4,代码来源:__init__.py


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