[patreon] Simplify (#3390)
This commit is contained in:
parent
b27295d2ab
commit
e05f693942
2 changed files with 61 additions and 79 deletions
|
@ -1474,6 +1474,34 @@ def strip_jsonp(code):
|
|||
return re.sub(r'(?s)^[a-zA-Z0-9_]+\s*\(\s*(.*)\);?\s*?\s*$', r'\1', code)
|
||||
|
||||
|
||||
def js_to_json(code):
|
||||
def fix_kv(m):
|
||||
key = m.group(2)
|
||||
if key.startswith("'"):
|
||||
assert key.endswith("'")
|
||||
assert '"' not in key
|
||||
key = '"%s"' % key[1:-1]
|
||||
elif not key.startswith('"'):
|
||||
key = '"%s"' % key
|
||||
|
||||
value = m.group(4)
|
||||
if value.startswith("'"):
|
||||
assert value.endswith("'")
|
||||
assert '"' not in value
|
||||
value = '"%s"' % value[1:-1]
|
||||
|
||||
return m.group(1) + key + m.group(3) + value
|
||||
|
||||
res = re.sub(r'''(?x)
|
||||
([{,]\s*)
|
||||
("[^"]*"|\'[^\']*\'|[a-z0-9A-Z]+)
|
||||
(:\s*)
|
||||
([0-9.]+|true|false|"[^"]*"|\'[^\']*\'|\[|\{)
|
||||
''', fix_kv, code)
|
||||
res = re.sub(r',(\s*\])', lambda m: m.group(1), res)
|
||||
return res
|
||||
|
||||
|
||||
def qualities(quality_ids):
|
||||
""" Get a numeric quality value out of a list of possible values """
|
||||
def q(qid):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue