implement 'parse_unicode_escapes()'
This commit is contained in:
@@ -174,6 +174,17 @@ def extract_from(txt, pos=0, default=""):
|
||||
return extr
|
||||
|
||||
|
||||
def parse_unicode_escapes(txt):
|
||||
"""Convert JSON Unicode escapes in 'txt' into actual characters"""
|
||||
if "\\u" in txt:
|
||||
return re.sub(r"\\u([0-9a-fA-F]{4})", _hex_to_char, txt)
|
||||
return txt
|
||||
|
||||
|
||||
def _hex_to_char(match):
|
||||
return chr(int(match.group(1), 16))
|
||||
|
||||
|
||||
def parse_bytes(value, default=0, suffixes="bkmgtp"):
|
||||
"""Convert a bytes-amount ("500k", "2.5M", ...) to int"""
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user