You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Keep optype info in token...
It is useful for ADD_VALUE
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
SKIP_TESTS=(
|
SKIP_TESTS=(
|
||||||
[test_ast.py]=1 # FIXME: Works on c90ff51
|
[test_ast.py]=1 # FIXME: Works on c90ff51
|
||||||
[test_cmath.py]=1 # FIXME: Works on c90ff51
|
[test_cmath.py]=1 # fails on its own
|
||||||
[test_format.py]=1 # FIXME: Works on c90ff51
|
[test_format.py]=1 # FIXME: Works on c90ff51
|
||||||
[test_ftplib.py]=1 # FIXME: Works on c90ff51
|
[test_ftplib.py]=1 # FIXME: Works on c90ff51
|
||||||
[test_slice.py]=1 # FIXME: Works on c90ff51
|
[test_slice.py]=1 # FIXME: Works on c90ff51
|
||||||
|
@@ -36,7 +36,7 @@ SKIP_TESTS=(
|
|||||||
[test_bdb.py]=1 #
|
[test_bdb.py]=1 #
|
||||||
[test_buffer.py]=1 # parse error
|
[test_buffer.py]=1 # parse error
|
||||||
[test_clinic.py]=1 # it fails on its own
|
[test_clinic.py]=1 # it fails on its own
|
||||||
[test_cmath.py]=1 # test assertion failure
|
[test_cmath.py]=pytest
|
||||||
[test_cmd_line.py]=1 # Interactive?
|
[test_cmd_line.py]=1 # Interactive?
|
||||||
[test_cmd_line_script.py]=1
|
[test_cmd_line_script.py]=1
|
||||||
[test_compileall.py]=1 # fails on its own
|
[test_compileall.py]=1 # fails on its own
|
||||||
|
@@ -69,7 +69,7 @@ SKIP_TESTS=(
|
|||||||
[test_cgi.py]=1 # parse error
|
[test_cgi.py]=1 # parse error
|
||||||
[test_cgitb.py]=1 # parse error
|
[test_cgitb.py]=1 # parse error
|
||||||
[test_clinic.py]=1 # it fails on its own
|
[test_clinic.py]=1 # it fails on its own
|
||||||
[test_cmath.py]=1 # test assertion failure
|
[test_cmath.py]=pytest
|
||||||
[test_cmd.py]=1 # parse error
|
[test_cmd.py]=1 # parse error
|
||||||
[test_cmd_line.py]=1 # Interactive?
|
[test_cmd_line.py]=1 # Interactive?
|
||||||
[test_cmd_line_script.py]=1
|
[test_cmd_line_script.py]=1
|
||||||
|
@@ -189,7 +189,7 @@ if [[ -n $1 ]] ; then
|
|||||||
if (( ${#files_ary[@]} == 1 || DONT_SKIP_TESTS == 1 )) ; then
|
if (( ${#files_ary[@]} == 1 || DONT_SKIP_TESTS == 1 )) ; then
|
||||||
for file in $files; do
|
for file in $files; do
|
||||||
if (( SKIP_TESTS[$file] != "pytest" )); then
|
if (( SKIP_TESTS[$file] != "pytest" )); then
|
||||||
SKIP_TESTS[$file] = 1;
|
SKIP_TESTS[$file]=1;
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
@@ -266,6 +266,7 @@ class Scanner3(Scanner):
|
|||||||
has_arg=True,
|
has_arg=True,
|
||||||
has_extended_arg=False,
|
has_extended_arg=False,
|
||||||
opc=self.opc,
|
opc=self.opc,
|
||||||
|
optype=None,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
for j in range(collection_start, i):
|
for j in range(collection_start, i):
|
||||||
@@ -279,6 +280,7 @@ class Scanner3(Scanner):
|
|||||||
has_arg=True,
|
has_arg=True,
|
||||||
has_extended_arg=False,
|
has_extended_arg=False,
|
||||||
opc=self.opc,
|
opc=self.opc,
|
||||||
|
optype=insts[j].optype,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
new_tokens.append(
|
new_tokens.append(
|
||||||
@@ -291,6 +293,7 @@ class Scanner3(Scanner):
|
|||||||
has_arg=t.has_arg,
|
has_arg=t.has_arg,
|
||||||
has_extended_arg=False,
|
has_extended_arg=False,
|
||||||
opc=t.opc,
|
opc=t.opc,
|
||||||
|
optype=None,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return new_tokens
|
return new_tokens
|
||||||
@@ -339,6 +342,7 @@ class Scanner3(Scanner):
|
|||||||
has_arg=True,
|
has_arg=True,
|
||||||
has_extended_arg=False,
|
has_extended_arg=False,
|
||||||
opc=self.opc,
|
opc=self.opc,
|
||||||
|
optype=None,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
for j in range(collection_start, i, 2):
|
for j in range(collection_start, i, 2):
|
||||||
@@ -364,6 +368,7 @@ class Scanner3(Scanner):
|
|||||||
has_arg=True,
|
has_arg=True,
|
||||||
has_extended_arg=False,
|
has_extended_arg=False,
|
||||||
opc=self.opc,
|
opc=self.opc,
|
||||||
|
optype=insts[j + 1].optype,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
new_tokens.append(
|
new_tokens.append(
|
||||||
@@ -376,6 +381,7 @@ class Scanner3(Scanner):
|
|||||||
has_arg=t.has_arg,
|
has_arg=t.has_arg,
|
||||||
has_extended_arg=False,
|
has_extended_arg=False,
|
||||||
opc=t.opc,
|
opc=t.opc,
|
||||||
|
optype=t.optype,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return new_tokens
|
return new_tokens
|
||||||
|
@@ -24,12 +24,12 @@ scanner routine for Python 3.
|
|||||||
|
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
|
||||||
from uncompyle6.scanner import CONST_COLLECTIONS, Token
|
|
||||||
from uncompyle6.scanners.scanner37base import Scanner37Base
|
|
||||||
|
|
||||||
# bytecode verification, verify(), uses JUMP_OPs from here
|
# bytecode verification, verify(), uses JUMP_OPs from here
|
||||||
from xdis.opcodes import opcode_37 as opc
|
from xdis.opcodes import opcode_37 as opc
|
||||||
|
|
||||||
|
from uncompyle6.scanner import CONST_COLLECTIONS, Token
|
||||||
|
from uncompyle6.scanners.scanner37base import Scanner37Base
|
||||||
|
|
||||||
# bytecode verification, verify(), uses JUMP_OPS from here
|
# bytecode verification, verify(), uses JUMP_OPS from here
|
||||||
JUMP_OPs = opc.JUMP_OPS
|
JUMP_OPs = opc.JUMP_OPS
|
||||||
|
|
||||||
@@ -90,6 +90,7 @@ class Scanner37(Scanner37Base):
|
|||||||
has_arg=True,
|
has_arg=True,
|
||||||
has_extended_arg=False,
|
has_extended_arg=False,
|
||||||
opc=self.opc,
|
opc=self.opc,
|
||||||
|
optype=None,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
for j in range(collection_start, i):
|
for j in range(collection_start, i):
|
||||||
@@ -103,6 +104,7 @@ class Scanner37(Scanner37Base):
|
|||||||
has_arg=True,
|
has_arg=True,
|
||||||
has_extended_arg=False,
|
has_extended_arg=False,
|
||||||
opc=self.opc,
|
opc=self.opc,
|
||||||
|
optype=tokens[j].optype,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
new_tokens.append(
|
new_tokens.append(
|
||||||
|
@@ -355,6 +355,7 @@ class Scanner37Base(Scanner):
|
|||||||
has_arg=True,
|
has_arg=True,
|
||||||
opc=self.opc,
|
opc=self.opc,
|
||||||
has_extended_arg=False,
|
has_extended_arg=False,
|
||||||
|
optype=inst.optype,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
jump_idx += 1
|
jump_idx += 1
|
||||||
@@ -426,6 +427,7 @@ class Scanner37Base(Scanner):
|
|||||||
has_arg=inst.has_arg,
|
has_arg=inst.has_arg,
|
||||||
opc=self.opc,
|
opc=self.opc,
|
||||||
has_extended_arg=inst.has_extended_arg,
|
has_extended_arg=inst.has_extended_arg,
|
||||||
|
optype=inst.optype,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
@@ -527,6 +529,7 @@ class Scanner37Base(Scanner):
|
|||||||
has_arg=inst.has_arg,
|
has_arg=inst.has_arg,
|
||||||
opc=self.opc,
|
opc=self.opc,
|
||||||
has_extended_arg=inst.has_extended_arg,
|
has_extended_arg=inst.has_extended_arg,
|
||||||
|
optype=inst.optype,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
pass
|
pass
|
||||||
|
@@ -61,17 +61,19 @@ class Token:
|
|||||||
opname,
|
opname,
|
||||||
attr=None,
|
attr=None,
|
||||||
pattr=None,
|
pattr=None,
|
||||||
offset:Union[int, str]=-1,
|
offset: Union[int, str] = -1,
|
||||||
linestart=None,
|
linestart=None,
|
||||||
op=None,
|
op=None,
|
||||||
has_arg=None,
|
has_arg=None,
|
||||||
opc=None,
|
opc=None,
|
||||||
has_extended_arg=False,
|
has_extended_arg=False,
|
||||||
|
optype=None,
|
||||||
):
|
):
|
||||||
self.kind = intern(opname)
|
self.kind = intern(opname)
|
||||||
self.has_arg = has_arg
|
self.has_arg = has_arg
|
||||||
self.attr = attr
|
self.attr = attr
|
||||||
self.pattr = pattr
|
self.pattr = pattr
|
||||||
|
self.optype = optype
|
||||||
if has_extended_arg:
|
if has_extended_arg:
|
||||||
self.offset = "%d_%d" % (offset, offset + 2)
|
self.offset = "%d_%d" % (offset, offset + 2)
|
||||||
else:
|
else:
|
||||||
@@ -107,8 +109,8 @@ class Token:
|
|||||||
self.op = op
|
self.op = op
|
||||||
|
|
||||||
def __eq__(self, o):
|
def __eq__(self, o):
|
||||||
""" '==' on kind and "pattr" attributes.
|
"""'==' on kind and "pattr" attributes.
|
||||||
It is okay if offsets and linestarts are different"""
|
It is okay if offsets and linestarts are different"""
|
||||||
if isinstance(o, Token):
|
if isinstance(o, Token):
|
||||||
return (self.kind == o.kind) and (
|
return (self.kind == o.kind) and (
|
||||||
(self.pattr == o.pattr) or self.attr == o.attr
|
(self.pattr == o.pattr) or self.attr == o.attr
|
||||||
@@ -118,7 +120,7 @@ class Token:
|
|||||||
return self.kind == o
|
return self.kind == o
|
||||||
|
|
||||||
def __ne__(self, o):
|
def __ne__(self, o):
|
||||||
""" '!=', but it's okay if offsets and linestarts are different"""
|
"""'!=', but it's okay if offsets and linestarts are different"""
|
||||||
return not self.__eq__(o)
|
return not self.__eq__(o)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
@@ -136,7 +136,7 @@ ASSIGN_DOC_STRING = lambda doc_string, doc_load: SyntaxTree(
|
|||||||
SyntaxTree(
|
SyntaxTree(
|
||||||
"expr", [Token(doc_load, pattr=doc_string, attr=doc_string)]
|
"expr", [Token(doc_load, pattr=doc_string, attr=doc_string)]
|
||||||
),
|
),
|
||||||
SyntaxTree("store", [Token("STORE_NAME", pattr="__doc__")]),
|
SyntaxTree("store", [Token("STORE_NAME", pattr="__doc__", optype="name")]),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -148,10 +148,10 @@ NAME_MODULE = SyntaxTree(
|
|||||||
"assign",
|
"assign",
|
||||||
[
|
[
|
||||||
SyntaxTree(
|
SyntaxTree(
|
||||||
"expr", [Token("LOAD_NAME", pattr="__name__", offset=0, has_arg=True)]
|
"expr", [Token("LOAD_NAME", pattr="__name__", offset=0, has_arg=True, optype="name")]
|
||||||
),
|
),
|
||||||
SyntaxTree(
|
SyntaxTree(
|
||||||
"store", [Token("STORE_NAME", pattr="__module__", offset=3, has_arg=True)]
|
"store", [Token("STORE_NAME", pattr="__module__", offset=3, has_arg=True, optype="name")]
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
@@ -240,10 +240,15 @@ class NonterminalActions:
|
|||||||
assert len(keys) == len(flat_elems) - 1
|
assert len(keys) == len(flat_elems) - 1
|
||||||
for i, elem in enumerate(flat_elems[:-1]):
|
for i, elem in enumerate(flat_elems[:-1]):
|
||||||
assert elem.kind == "ADD_VALUE"
|
assert elem.kind == "ADD_VALUE"
|
||||||
try:
|
if elem.optype in ("local", "name"):
|
||||||
value = "%r" % elem.pattr
|
value = elem.attr
|
||||||
except Exception:
|
elif elem.optype == "const" and not isinstance(elem.attr, str):
|
||||||
value = elem.pattr
|
value = elem.attr
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
value = "%r" % elem.pattr
|
||||||
|
except Exception:
|
||||||
|
value = elem.pattr
|
||||||
if elem.linestart is not None:
|
if elem.linestart is not None:
|
||||||
if elem.linestart != self.line_number:
|
if elem.linestart != self.line_number:
|
||||||
next_indent = self.indent + INDENT_PER_LEVEL[:-1]
|
next_indent = self.indent + INDENT_PER_LEVEL[:-1]
|
||||||
@@ -266,11 +271,14 @@ class NonterminalActions:
|
|||||||
for elem in flat_elems:
|
for elem in flat_elems:
|
||||||
if elem == "add_value":
|
if elem == "add_value":
|
||||||
elem = elem[0]
|
elem = elem[0]
|
||||||
|
|
||||||
if elem == "ADD_VALUE":
|
if elem == "ADD_VALUE":
|
||||||
if self.version < (3, 0, 0):
|
if elem.optype in ("local", "name"):
|
||||||
value = "%r" % repr(elem.pattr)
|
value = elem.attr
|
||||||
|
elif elem.optype == "const" and not isinstance(elem.attr, str):
|
||||||
|
value = elem.attr
|
||||||
else:
|
else:
|
||||||
value = "%s" % str(elem.pattr)
|
value = "%s" % repr(elem.pattr)
|
||||||
else:
|
else:
|
||||||
assert elem.kind == "ADD_VALUE_VAR"
|
assert elem.kind == "ADD_VALUE_VAR"
|
||||||
value = "%s" % elem.pattr
|
value = "%s" % elem.pattr
|
||||||
|
Reference in New Issue
Block a user