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


Python codecs.raw_unicode_escape_decode方法代碼示例

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


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

示例1: test_unicode_escape

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import raw_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

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import raw_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

示例3: decode

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import raw_unicode_escape_decode [as 別名]
def decode(self, input, final=False):
        return codecs.raw_unicode_escape_decode(input, self.errors)[0] 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:4,代碼來源:raw_unicode_escape.py

示例4: test_empty

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import raw_unicode_escape_decode [as 別名]
def test_empty(self):
        self.assertEqual(codecs.raw_unicode_escape_encode(u""), ("", 0))
        self.assertEqual(codecs.raw_unicode_escape_decode(""), (u"", 0)) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:5,代碼來源:test_codecs.py

示例5: test_raw_decode

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import raw_unicode_escape_decode [as 別名]
def test_raw_decode(self):
        decode = codecs.raw_unicode_escape_decode
        for b in range(256):
            self.assertEqual(decode(chr(b) + '0'), (unichr(b) + u'0', 2)) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:6,代碼來源:test_codecs.py

示例6: test_escape_decode

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import raw_unicode_escape_decode [as 別名]
def test_escape_decode(self):
        decode = codecs.raw_unicode_escape_decode
        check = coding_checker(self, decode)
        for b in range(256):
            if chr(b) not in 'uU':
                check('\\' + chr(b), u'\\' + unichr(b))
        check(r"\u20ac", u"\u20ac")
        check(r"\U0001d120", u"\U0001d120") 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:10,代碼來源:test_codecs.py

示例7: test_decode_errors

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import raw_unicode_escape_decode [as 別名]
def test_decode_errors(self):
        decode = codecs.raw_unicode_escape_decode
        for c, d in ('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

示例8: test_empty

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import raw_unicode_escape_decode [as 別名]
def test_empty(self):
        self.assertEqual(codecs.raw_unicode_escape_encode(""), (b"", 0))
        self.assertEqual(codecs.raw_unicode_escape_decode(b""), ("", 0)) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:5,代碼來源:test_codecs.py

示例9: test_raw_decode

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import raw_unicode_escape_decode [as 別名]
def test_raw_decode(self):
        decode = codecs.raw_unicode_escape_decode
        for b in range(256):
            self.assertEqual(decode(bytes([b]) + b'0'), (chr(b) + '0', 2)) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:6,代碼來源:test_codecs.py

示例10: test_escape_decode

# 需要導入模塊: import codecs [as 別名]
# 或者: from codecs import raw_unicode_escape_decode [as 別名]
def test_escape_decode(self):
        decode = codecs.raw_unicode_escape_decode
        check = coding_checker(self, decode)
        for b in range(256):
            if b not in b'uU':
                check(b'\\' + bytes([b]), '\\' + chr(b))
        check(br"\u20ac", "\u20ac")
        check(br"\U0001d120", "\U0001d120") 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:10,代碼來源:test_codecs.py


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