本文整理汇总了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
示例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
示例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]
示例4: test_empty
# 需要导入模块: import codecs [as 别名]
# 或者: from codecs import escape_decode [as 别名]
def test_empty(self):
self.assertEqual(codecs.escape_decode(""), ("", 0))
示例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))
示例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)
示例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))
示例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
示例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]))
示例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))
示例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))
示例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)