You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 08:49:51 +08:00
python-3.3-3.5 merge
This commit is contained in:
@@ -54,6 +54,7 @@ def test_grammar():
|
||||
expect_lhs.add("except_handler_else")
|
||||
|
||||
expect_lhs.add("kwarg")
|
||||
<<<<<<< HEAD
|
||||
expect_lhs.add("load_genexpr")
|
||||
|
||||
unused_rhs = unused_rhs.union(
|
||||
@@ -88,7 +89,6 @@ def test_grammar():
|
||||
assert expect_lhs == set(lhs)
|
||||
assert unused_rhs == set(rhs)
|
||||
|
||||
>>>>>>> python-3.3-to-3.5
|
||||
assert expect_right_recursive == right_recursive
|
||||
|
||||
expect_dup_rhs = frozenset(
|
||||
|
@@ -70,7 +70,6 @@ def disco_loop(disasm, queue, real_out):
|
||||
"\n# %s %s\n"
|
||||
% (co.co_name, co.co_filename)
|
||||
)
|
||||
print(
|
||||
tokens, customize = disasm(co)
|
||||
for t in tokens:
|
||||
if iscode(t.pattr):
|
||||
|
@@ -523,11 +523,11 @@ if __name__ == '__main__':
|
||||
# Check grammar
|
||||
p = Python26Parser()
|
||||
p.check_grammar()
|
||||
from uncompyle6 import PYTHON_VERSION, IS_PYPY
|
||||
if PYTHON_VERSION == 2.6:
|
||||
from xdis import PYTHON_VERSION_TRIPLE, IS_PYPY
|
||||
if PYTHON_VERSION_TRIPLE[:2] == (2, 6):
|
||||
lhs, rhs, tokens, right_recursive, dup_rhs = p.check_sets()
|
||||
from uncompyle6.scanner import get_scanner
|
||||
s = get_scanner(PYTHON_VERSION, IS_PYPY)
|
||||
s = get_scanner(PYTHON_VERSION_TRIPLE, IS_PYPY)
|
||||
opcode_set = set(s.opc.opname).union(set(
|
||||
"""JUMP_BACK CONTINUE RETURN_END_IF COME_FROM
|
||||
LOAD_GENEXPR LOAD_ASSERT LOAD_SETCOMP LOAD_DICTCOMP
|
||||
|
@@ -361,8 +361,8 @@ if __name__ == "__main__":
|
||||
# Check grammar
|
||||
p = Python27Parser()
|
||||
p.check_grammar()
|
||||
from uncompyle6 import PYTHON_VERSION, IS_PYPY
|
||||
if PYTHON_VERSION == 2.7:
|
||||
from xdis import PYTHON_VERSION_TRIPLE, IS_PYPY
|
||||
if PYTHON_VERSION_TRIPLE[:2] == (2, 7):
|
||||
lhs, rhs, tokens, right_recursive, dup_rhs = p.check_sets()
|
||||
from uncompyle6.scanner import get_scanner
|
||||
s = get_scanner(PYTHON_VERSION, IS_PYPY)
|
||||
|
@@ -352,8 +352,8 @@ if __name__ == '__main__':
|
||||
p = Python30Parser()
|
||||
p.remove_rules_30()
|
||||
p.check_grammar()
|
||||
from uncompyle6 import PYTHON_VERSION, IS_PYPY
|
||||
if PYTHON_VERSION == 3.0:
|
||||
from xdis import PYTHON_VERSION_TRIPLE, IS_PYPY
|
||||
if PYTHON_VERSION_TRIPLE[:2] == (3, 0):
|
||||
lhs, rhs, tokens, right_recursive, dup_rhs = p.check_sets()
|
||||
from uncompyle6.scanner import get_scanner
|
||||
s = get_scanner(PYTHON_VERSION, IS_PYPY)
|
||||
|
@@ -55,8 +55,8 @@ if __name__ == '__main__':
|
||||
p = Python31Parser()
|
||||
p.remove_rules_31()
|
||||
p.check_grammar()
|
||||
from uncompyle6 import PYTHON_VERSION, IS_PYPY
|
||||
if PYTHON_VERSION == 3.1:
|
||||
from xdis import PYTHON_VERSION_TRIPLE, IS_PYPY
|
||||
if PYTHON_VERSION_TRIPLE[:2] == (3, 1):
|
||||
lhs, rhs, tokens, right_recursive, dup_rhs = p.check_sets()
|
||||
from uncompyle6.scanner import get_scanner
|
||||
s = get_scanner(PYTHON_VERSION, IS_PYPY)
|
||||
|
@@ -70,8 +70,8 @@ if __name__ == '__main__':
|
||||
# Check grammar
|
||||
p = Python34Parser()
|
||||
p.check_grammar()
|
||||
from uncompyle6 import PYTHON_VERSION, IS_PYPY
|
||||
if PYTHON_VERSION == 3.4:
|
||||
from xdis import PYTHON_VERSION_TRIPLE, IS_PYPY
|
||||
if PYTHON_VERSION_TRIPLE == (3, 4):
|
||||
lhs, rhs, tokens, right_recursive, dup_rhs = p.check_sets()
|
||||
from uncompyle6.scanner import get_scanner
|
||||
s = get_scanner(PYTHON_VERSION, IS_PYPY)
|
||||
|
@@ -272,8 +272,8 @@ if __name__ == '__main__':
|
||||
# Check grammar
|
||||
p = Python35Parser()
|
||||
p.check_grammar()
|
||||
from uncompyle6 import PYTHON_VERSION, IS_PYPY
|
||||
if PYTHON_VERSION == 3.5:
|
||||
from xdis import PYTHON_VERSION_TRIPLE, IS_PYPY
|
||||
if PYTHON_VERSION_TRIPLE[:2] == (3, 5):
|
||||
lhs, rhs, tokens, right_recursive, dup_rhs = p.check_sets()
|
||||
from uncompyle6.scanner import get_scanner
|
||||
s = get_scanner(PYTHON_VERSION, IS_PYPY)
|
||||
|
@@ -376,7 +376,7 @@ class Python36Parser(Python35Parser):
|
||||
elif opname == "GET_AITER":
|
||||
self.add_unique_doc_rules("get_aiter ::= expr GET_AITER", customize)
|
||||
|
||||
if not {"MAKE_FUNCTION_0", "MAKE_FUNCTION_CLOSURE"} in self.seen_ops:
|
||||
if not set(["MAKE_FUNCTION_0", "MAKE_FUNCTION_CLOSURE"]) in self.seen_ops:
|
||||
self.addRule(
|
||||
"""
|
||||
expr ::= dict_comp_async
|
||||
@@ -672,8 +672,8 @@ if __name__ == '__main__':
|
||||
# Check grammar
|
||||
p = Python36Parser()
|
||||
p.check_grammar()
|
||||
from uncompyle6 import PYTHON_VERSION, IS_PYPY
|
||||
if PYTHON_VERSION == 3.6:
|
||||
from xdis import PYTHON_VERSION_TRIPLE, IS_PYPY
|
||||
if PYTHON_VERSION_TRIPLE[:2] == (3, 6):
|
||||
lhs, rhs, tokens, right_recursive, dup_rhs = p.check_sets()
|
||||
from uncompyle6.scanner import get_scanner
|
||||
s = get_scanner(PYTHON_VERSION, IS_PYPY)
|
||||
|
@@ -1337,7 +1337,7 @@ class Python37Parser(Python37BaseParser):
|
||||
elif opname == "GET_AITER":
|
||||
self.add_unique_doc_rules("get_aiter ::= expr GET_AITER", customize)
|
||||
|
||||
if not {"MAKE_FUNCTION_0", "MAKE_FUNCTION_CLOSURE"} in self.seen_ops:
|
||||
if not set(["MAKE_FUNCTION_0", "MAKE_FUNCTION_CLOSURE"]) in self.seen_ops:
|
||||
self.addRule(
|
||||
"""
|
||||
expr ::= dict_comp_async
|
||||
@@ -1738,9 +1738,9 @@ if __name__ == "__main__":
|
||||
# FIXME: DRY this with other parseXX.py routines
|
||||
p = Python37Parser()
|
||||
p.check_grammar()
|
||||
from uncompyle6 import PYTHON_VERSION, IS_PYPY
|
||||
from xdis import PYTHON_VERSION_TRIPLE, IS_PYPY
|
||||
|
||||
if PYTHON_VERSION == 3.7:
|
||||
if PYTHON_VERSION_TRIPLE[:2] == (3, 7):
|
||||
lhs, rhs, tokens, right_recursive, dup_rhs = p.check_sets()
|
||||
from uncompyle6.scanner import get_scanner
|
||||
|
||||
|
@@ -344,9 +344,9 @@ if __name__ == "__main__":
|
||||
p = Python38Parser()
|
||||
p.remove_rules_38()
|
||||
p.check_grammar()
|
||||
from uncompyle6 import PYTHON_VERSION, IS_PYPY
|
||||
from xdis import PYTHON_VERSION_TRIPLE, IS_PYPY
|
||||
|
||||
if PYTHON_VERSION == 3.8:
|
||||
if PYTHON_VERSION_TRIPLE[:2] == (3, 8):
|
||||
lhs, rhs, tokens, right_recursive, dup_rhs = p.check_sets()
|
||||
from uncompyle6.scanner import get_scanner
|
||||
|
||||
|
@@ -31,4 +31,3 @@ if __name__ == "__main__":
|
||||
pass
|
||||
else:
|
||||
print("Need to be Python 3.1 to demo; I am version %s." % version_tuple_to_str())
|
||||
[<
|
||||
|
@@ -22,12 +22,18 @@ This sets up opcodes Python's 3.7 and calls a generalized
|
||||
scanner routine for Python 3.
|
||||
"""
|
||||
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
from uncompyle6.scanner import CONST_COLLECTIONS
|
||||
from uncompyle6.scanners.tok import Token
|
||||
|
||||
>>>>>>> python-3.3-to-3.5
|
||||
=======
|
||||
from uncompyle6.scanner import CONST_COLLECTIONS
|
||||
from uncompyle6.scanners.tok import Token
|
||||
|
||||
>>>>>>> python-2.4-nogood-merge
|
||||
from uncompyle6.scanners.scanner37base import Scanner37Base
|
||||
|
||||
# bytecode verification, verify(), uses JUMP_OPs from here
|
||||
@@ -38,6 +44,7 @@ JUMP_OPs = opc.JUMP_OPS
|
||||
|
||||
|
||||
class Scanner37(Scanner37Base):
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
def __init__(self, show_asm=None, is_pypy=False):
|
||||
Scanner37Base.__init__(self, (3, 7), show_asm)
|
||||
@@ -47,15 +54,23 @@ class Scanner37(Scanner37Base):
|
||||
Scanner37Base.__init__(self, (3, 7), show_asm, debug, is_pypy)
|
||||
self.debug = debug
|
||||
>>>>>>> python-3.3-to-3.5
|
||||
=======
|
||||
def __init__(self, show_asm=None, debug="", is_pypy=False):
|
||||
Scanner37Base.__init__(self, (3, 7), show_asm, debug, is_pypy)
|
||||
self.debug = debug
|
||||
>>>>>>> python-2.4-nogood-merge
|
||||
return
|
||||
|
||||
pass
|
||||
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
=======
|
||||
>>>>>>> python-2.4-nogood-merge
|
||||
def bound_collection_from_tokens(
|
||||
self, tokens: list, next_tokens: list, t: Token, i: int, collection_type: str
|
||||
) -> list:
|
||||
self, tokens, next_tokens, t, i, collection_type
|
||||
):
|
||||
count = t.attr
|
||||
assert isinstance(count, int)
|
||||
|
||||
@@ -130,7 +145,10 @@ class Scanner37(Scanner37Base):
|
||||
)
|
||||
return new_tokens
|
||||
|
||||
<<<<<<< HEAD
|
||||
>>>>>>> python-3.3-to-3.5
|
||||
=======
|
||||
>>>>>>> python-2.4-nogood-merge
|
||||
def ingest(
|
||||
self, co, classname=None, code_objects={}, show_asm=None
|
||||
):
|
||||
@@ -167,9 +185,6 @@ class Scanner37(Scanner37Base):
|
||||
collection_type = "DICT"
|
||||
else:
|
||||
collection_type = t.kind.split("_")[1]
|
||||
next_tokens = self.bound_collection_from_tokens(
|
||||
new_tokens, t, i, "CONST_%s" % collection_type
|
||||
)
|
||||
new_tokens = self.bound_collection_from_tokens(
|
||||
tokens, new_tokens, t, i, "CONST_%s" % collection_type
|
||||
)
|
||||
|
@@ -46,7 +46,7 @@ globals().update(op3.opmap)
|
||||
|
||||
|
||||
class Scanner37Base(Scanner):
|
||||
def __init__(self, version: tuple, show_asm=None, debug="", is_pypy=False):
|
||||
def __init__(self, version, show_asm=None, debug="", is_pypy=False):
|
||||
super(Scanner37Base, self).__init__(version, show_asm, is_pypy)
|
||||
self.debug = debug
|
||||
self.is_pypy = is_pypy
|
||||
|
@@ -43,7 +43,7 @@ class Scanner38(Scanner37):
|
||||
|
||||
def ingest(
|
||||
self, co, classname=None, code_objects={}, show_asm=None
|
||||
) -> tuple:
|
||||
):
|
||||
"""
|
||||
Create "tokens" the bytecode of an Python code object. Largely these
|
||||
are the opcode name, but in some cases that has been modified to make parsing
|
||||
|
@@ -269,7 +269,10 @@ class ComprehensionMixin(object):
|
||||
assert list_afor2 == "list_afor2"
|
||||
store = list_afor2[1]
|
||||
assert store == "store"
|
||||
n = list_afor2[3] if list_afor2[3] == "list_iter" else list_afor2[2]
|
||||
if list_afor2[3] == "list_iter":
|
||||
n = list_afor2[3]
|
||||
else:
|
||||
n = list_afor2[2]
|
||||
else:
|
||||
# ???
|
||||
pass
|
||||
@@ -629,7 +632,10 @@ class ComprehensionMixin(object):
|
||||
list_ifs.append(n)
|
||||
else:
|
||||
list_ifs.append([1])
|
||||
n = n[-2] if n[-1] == "come_from_opt" else n[-1]
|
||||
if n[-1] == "come_from_opt":
|
||||
n = n[-2]
|
||||
else:
|
||||
n = n[-1]
|
||||
pass
|
||||
elif n == "list_if37":
|
||||
list_ifs.append(n)
|
||||
@@ -639,7 +645,10 @@ class ComprehensionMixin(object):
|
||||
collections.append(n[0][0])
|
||||
n = n[1]
|
||||
stores.append(n[1][0])
|
||||
n = n[2] if n[2].kind == "list_iter" else n[3]
|
||||
if n[2].kind:
|
||||
n = n[2]
|
||||
else:
|
||||
n = n[3]
|
||||
pass
|
||||
|
||||
assert n == "lc_body", tree
|
||||
|
@@ -34,7 +34,7 @@ def make_function1(self, node, is_lambda, nested=1, code_node=None):
|
||||
This code is specialied for Python 2.
|
||||
"""
|
||||
|
||||
def build_param(tree, param_names: list) -> tuple:
|
||||
def build_param(tree, param_names):
|
||||
"""build parameters:
|
||||
- handle defaults
|
||||
- handle format tuple parameters
|
||||
@@ -93,7 +93,7 @@ def make_function1(self, node, is_lambda, nested=1, code_node=None):
|
||||
is_lambda=is_lambda,
|
||||
noneInNames=("None" in code.co_names),
|
||||
)
|
||||
except (ParserError, ParserError2) as p:
|
||||
except (ParserError(p), ParserError2(p)):
|
||||
self.write(str(p))
|
||||
if not self.tolerate_errors:
|
||||
self.ERROR = p
|
||||
|
Reference in New Issue
Block a user