本文整理匯總了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)