You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 09:22:40 +08:00
Hacky handling of 3.6 format string 'X'.
This commit is contained in:
Binary file not shown.
@@ -17,3 +17,10 @@ x = f"{k}={v!r}"
|
|||||||
y = f"functools.{x}({', '.join(v)})"
|
y = f"functools.{x}({', '.join(v)})"
|
||||||
assert x == "1=['2']"
|
assert x == "1=['2']"
|
||||||
assert y == "functools.1=['2'](2)"
|
assert y == "functools.1=['2'](2)"
|
||||||
|
|
||||||
|
# From 3.6 http/client.py
|
||||||
|
# Bug is in handling X
|
||||||
|
chunk = ['a', 'b', 'c']
|
||||||
|
chunk2 = 'd'
|
||||||
|
chunk = f'{len(chunk):X}' + chunk2
|
||||||
|
assert chunk == '3d'
|
||||||
|
@@ -186,6 +186,15 @@ class Python36Parser(Python35Parser):
|
|||||||
rules_str = """
|
rules_str = """
|
||||||
expr ::= fstring_single
|
expr ::= fstring_single
|
||||||
fstring_single ::= expr FORMAT_VALUE
|
fstring_single ::= expr FORMAT_VALUE
|
||||||
|
expr ::= fstring_expr
|
||||||
|
fstring_expr ::= expr FORMAT_VALUE
|
||||||
|
|
||||||
|
# FIXME: need to look inside FORMAT_VALUE to see if 4
|
||||||
|
fstring_single ::= expr expr FORMAT_VALUE
|
||||||
|
str ::= LOAD_CONST
|
||||||
|
formatted_value ::= fstring_expr
|
||||||
|
formatted_value ::= str
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.add_unique_doc_rules(rules_str, customize)
|
self.add_unique_doc_rules(rules_str, customize)
|
||||||
elif opname == 'MAKE_FUNCTION_8':
|
elif opname == 'MAKE_FUNCTION_8':
|
||||||
@@ -233,12 +242,6 @@ class Python36Parser(Python35Parser):
|
|||||||
v = token.attr
|
v = token.attr
|
||||||
joined_str_n = "formatted_value_%s" % v
|
joined_str_n = "formatted_value_%s" % v
|
||||||
rules_str = """
|
rules_str = """
|
||||||
expr ::= fstring_expr
|
|
||||||
fstring_expr ::= expr FORMAT_VALUE
|
|
||||||
str ::= LOAD_CONST
|
|
||||||
formatted_value ::= fstring_expr
|
|
||||||
formatted_value ::= str
|
|
||||||
|
|
||||||
expr ::= fstring_multi
|
expr ::= fstring_multi
|
||||||
fstring_multi ::= joined_str BUILD_STRING
|
fstring_multi ::= joined_str BUILD_STRING
|
||||||
joined_str ::= formatted_value+
|
joined_str ::= formatted_value+
|
||||||
|
@@ -324,7 +324,7 @@ def customize_for_version36(self, version):
|
|||||||
self.call36_dict = call36_dict
|
self.call36_dict = call36_dict
|
||||||
|
|
||||||
|
|
||||||
FSTRING_CONVERSION_MAP = {1: '!s', 2: '!r', 3: '!a'}
|
FSTRING_CONVERSION_MAP = {1: '!s', 2: '!r', 3: '!a', 'X':':X'}
|
||||||
|
|
||||||
def n_except_suite_finalize(node):
|
def n_except_suite_finalize(node):
|
||||||
if node[1] == 'returns' and self.hide_internal:
|
if node[1] == 'returns' and self.hide_internal:
|
||||||
@@ -351,7 +351,12 @@ def customize_for_version36(self, version):
|
|||||||
self.n_formatted_value = n_formatted_value
|
self.n_formatted_value = n_formatted_value
|
||||||
|
|
||||||
def f_conversion(node):
|
def f_conversion(node):
|
||||||
node.conversion = FSTRING_CONVERSION_MAP.get(node.data[1].attr, '')
|
fmt_node = node.data[1]
|
||||||
|
if fmt_node == 'expr' and fmt_node[0] == 'LOAD_CONST':
|
||||||
|
data = fmt_node[0].attr
|
||||||
|
else:
|
||||||
|
data = fmt_node
|
||||||
|
node.conversion = FSTRING_CONVERSION_MAP.get(data, '')
|
||||||
|
|
||||||
def fstring_expr(node):
|
def fstring_expr(node):
|
||||||
f_conversion(node)
|
f_conversion(node)
|
||||||
|
Reference in New Issue
Block a user