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


Python codecs.escape_decode方法代码示例

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


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

示例1: value_from_fsnative

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import escape_decode [as 别名]
def value_from_fsnative(arg, escape):
    """Takes an item from argv and returns a text_type value without
    surrogate escapes or raises ValueError.
    """

    assert isinstance(arg, fsnative)

    if escape:
        bytes_ = fsn2bytes(arg)
        if PY2:
            bytes_ = bytes_.decode("string_escape")
        else:
            bytes_ = codecs.escape_decode(bytes_)[0]
        arg = bytes2fsn(bytes_)

    text = fsn2text(arg, strict=True)
    return text 
开发者ID:bugatsinho,项目名称:bugatsinho.github.io,代码行数:19,代码来源:mid3v2.py

示例2: understat_players_data

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import escape_decode [as 别名]
def understat_players_data(session):
    """Returns a dict containing general player data retrieved from
    https://understat.com/.
    """
    logger.info("Getting Understat players data.")
    html = await fetch(session, "https://understat.com/league/EPL/")

    soup = BeautifulSoup(html, "html.parser")
    scripts = soup.find_all("script")
    pattern = re.compile(r"var\s+playersData\s+=\s+JSON.parse\(\'(.*?)\'\);")

    for script in scripts:
        match = re.search(pattern, script.string)
        if match:
            break

    byte_data = codecs.escape_decode(match.group(1))
    player_data = json.loads(byte_data[0].decode("utf-8"))

    # Convert Understat player name to FPL player name
    for player in player_data:
        player["team_title"] = understat_team_converter(player["team_title"])
        player["player_name"] = understat_player_converter(player["player_name"])

    return player_data 
开发者ID:amosbastian,项目名称:FPLbot,代码行数:27,代码来源:utils.py

示例3: decode

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

示例4: test_empty

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

示例5: test_raw

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

示例6: test_escape

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

示例7: test_errors

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import escape_decode [as 别名]
def test_errors(self):
        decode = codecs.escape_decode
        self.assertRaises(ValueError, decode, br"\x")
        self.assertRaises(ValueError, decode, br"[\x]")
        self.assertEqual(decode(br"[\x]\x", "ignore"), (b"[]", 6))
        self.assertEqual(decode(br"[\x]\x", "replace"), (b"[?]?", 6))
        self.assertRaises(ValueError, decode, br"\x0")
        self.assertRaises(ValueError, decode, br"[\x0]")
        self.assertEqual(decode(br"[\x0]\x0", "ignore"), (b"[]", 8))
        self.assertEqual(decode(br"[\x0]\x0", "replace"), (b"[?]?", 8)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_codecs.py

示例8: to_byte

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import escape_decode [as 别名]
def to_byte(val):
    unicode_type = str if PY3 else unicode
    if isinstance(val, unicode_type):
        try:
            return val.encode(ENCODING)
        except UnicodeEncodeError:
            if PY3:
                return codecs.escape_decode(val)[0]
            else:
                return val.encode("unicode-escape").decode("string-escape")

    return val 
开发者ID:Qix-,项目名称:better-exceptions,代码行数:14,代码来源:encoding.py

示例9: load_string

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import escape_decode [as 别名]
def load_string(self):
        data = self.readline()[:-1]
        # Strip outermost quotes
        if len(data) >= 2 and data[0] == data[-1] and data[0] in b'"\'':
            data = data[1:-1]
        else:
            raise UnpicklingError("the STRING opcode argument must be quoted")
        self.append(self._decode_string(codecs.escape_decode(data)[0])) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:pickle.py

示例10: test_empty

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import escape_decode [as 别名]
def test_empty(self):
        self.assertEqual(codecs.escape_decode(b""), (b"", 0))
        self.assertEqual(codecs.escape_decode(bytearray()), (b"", 0)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_codecs.py

示例11: test_raw

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import escape_decode [as 别名]
def test_raw(self):
        decode = codecs.escape_decode
        for b in range(256):
            b = bytes([b])
            if b != b'\\':
                self.assertEqual(decode(b + b'0'), (b + b'0', 2)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:test_codecs.py

示例12: test_escape

# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import escape_decode [as 别名]
def test_escape(self):
        decode = codecs.escape_decode
        check = coding_checker(self, decode)
        check(b"[\\\n]", b"[]")
        check(br'[\"]', b'["]')
        check(br"[\']", b"[']")
        check(br"[\\]", br"[\]")
        check(br"[\a]", b"[\x07]")
        check(br"[\b]", b"[\x08]")
        check(br"[\t]", b"[\x09]")
        check(br"[\n]", b"[\x0a]")
        check(br"[\v]", b"[\x0b]")
        check(br"[\f]", b"[\x0c]")
        check(br"[\r]", b"[\x0d]")
        check(br"[\7]", b"[\x07]")
        check(br"[\8]", br"[\8]")
        check(br"[\78]", b"[\x078]")
        check(br"[\41]", b"[!]")
        check(br"[\418]", b"[!8]")
        check(br"[\101]", b"[A]")
        check(br"[\1010]", b"[A0]")
        check(br"[\501]", b"[A]")
        check(br"[\x41]", b"[A]")
        check(br"[\X41]", br"[\X41]")
        check(br"[\x410]", b"[A0]")
        for b in range(256):
            if b not in b'\n"\'\\abtnvfr01234567x':
                b = bytes([b])
                check(b'\\' + b, b'\\' + b) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:31,代码来源:test_codecs.py


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