You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Python 2.5 try/except reduce fix
Start getting aligner up to date
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
# Copyright (c) 2020, 2022, 2024 Rocky Bernstein
|
# Copyright (c) 2020, 2022, 2024 Rocky Bernstein
|
||||||
|
|
||||||
|
|
||||||
def tryexcept(self, lhs, n: int, rule, ast, tokens, first: int, last: int):
|
def tryexcept(self, lhs, n, rule, ast, tokens, first, last):
|
||||||
come_from_except = ast[-1]
|
come_from_except = ast[-1]
|
||||||
if rule == (
|
if rule == (
|
||||||
"try_except",
|
"try_except",
|
||||||
|
@@ -22,6 +22,7 @@ scanners, e.g. for Python 2.7 or 3.4.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from abc import ABC
|
from abc import ABC
|
||||||
|
>>>>>>> Stashed changes
|
||||||
from array import array
|
from array import array
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from types import ModuleType
|
from types import ModuleType
|
||||||
|
@@ -425,7 +425,7 @@ class Scanner3(Scanner):
|
|||||||
names=co.co_names,
|
names=co.co_names,
|
||||||
constants=co.co_consts,
|
constants=co.co_consts,
|
||||||
cells=bytecode._cell_names,
|
cells=bytecode._cell_names,
|
||||||
linestarts=bytecode._linestarts,
|
line_starts=bytecode._linestarts,
|
||||||
asm_format="extended",
|
asm_format="extended",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
# Copyright (c) 2018, 2022-2023 by Rocky Bernstein
|
# Copyright (c) 2018, 2022-2024 by Rocky Bernstein
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -18,11 +18,14 @@ import sys
|
|||||||
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
|
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
|
||||||
from xdis import iscode
|
from xdis import iscode
|
||||||
|
|
||||||
from xdis.version_info import IS_PYPY
|
from xdis.version_info import IS_PYPY, PYTHON_VERSION_TRIPLE
|
||||||
|
|
||||||
from uncompyle6.scanner import get_scanner
|
from uncompyle6.scanner import get_scanner
|
||||||
|
from uncompyle6.semantics.consts import ASSIGN_DOC_STRING
|
||||||
|
|
||||||
from uncompyle6.semantics.pysource import (
|
from uncompyle6.semantics.pysource import (
|
||||||
ASSIGN_DOC_STRING,
|
|
||||||
RETURN_NONE,
|
RETURN_NONE,
|
||||||
|
TREE_DEFAULT_DEBUG,
|
||||||
SourceWalker,
|
SourceWalker,
|
||||||
SourceWalkerError,
|
SourceWalkerError,
|
||||||
find_globals_and_nonlocals
|
find_globals_and_nonlocals
|
||||||
@@ -38,7 +41,7 @@ class AligningWalker(SourceWalker, object):
|
|||||||
version,
|
version,
|
||||||
out,
|
out,
|
||||||
scanner,
|
scanner,
|
||||||
showast=False,
|
showast=TREE_DEFAULT_DEBUG,
|
||||||
debug_parser=PARSER_DEFAULT_DEBUG,
|
debug_parser=PARSER_DEFAULT_DEBUG,
|
||||||
compile_mode="exec",
|
compile_mode="exec",
|
||||||
is_pypy=False,
|
is_pypy=False,
|
||||||
@@ -48,6 +51,7 @@ class AligningWalker(SourceWalker, object):
|
|||||||
)
|
)
|
||||||
self.desired_line_number = 0
|
self.desired_line_number = 0
|
||||||
self.current_line_number = 0
|
self.current_line_number = 0
|
||||||
|
self.showast = showast
|
||||||
|
|
||||||
def println(self, *data):
|
def println(self, *data):
|
||||||
if data and not (len(data) == 1 and data[0] == ""):
|
if data and not (len(data) == 1 and data[0] == ""):
|
||||||
@@ -113,12 +117,12 @@ class AligningWalker(SourceWalker, object):
|
|||||||
key = key[i]
|
key = key[i]
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if key.type in table:
|
if key.kind in table:
|
||||||
self.template_engine(table[key.type], node)
|
self.template_engine(table[key.kind], node)
|
||||||
self.prune()
|
self.prune()
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_DEBUG_OPTS = {"asm": False, "tree": False, "grammar": False}
|
DEFAULT_DEBUG_OPTS = {"asm": False, "tree": TREE_DEFAULT_DEBUG, "grammar": False}
|
||||||
|
|
||||||
|
|
||||||
def code_deparse_align(
|
def code_deparse_align(
|
||||||
@@ -137,7 +141,7 @@ def code_deparse_align(
|
|||||||
assert iscode(co)
|
assert iscode(co)
|
||||||
|
|
||||||
if version is None:
|
if version is None:
|
||||||
version = float(sys.version[0:3])
|
version = PYTHON_VERSION_TRIPLE
|
||||||
if is_pypy is None:
|
if is_pypy is None:
|
||||||
is_pypy = IS_PYPY
|
is_pypy = IS_PYPY
|
||||||
|
|
||||||
@@ -156,11 +160,11 @@ def code_deparse_align(
|
|||||||
debug_parser["errorstack"] = True
|
debug_parser["errorstack"] = True
|
||||||
|
|
||||||
# Build a parse tree from tokenized and massaged disassembly.
|
# Build a parse tree from tokenized and massaged disassembly.
|
||||||
show_ast = debug_opts.get("ast", None)
|
show_ast = debug_opts.get("ast", TREE_DEFAULT_DEBUG)
|
||||||
deparsed = AligningWalker(
|
deparsed = AligningWalker(
|
||||||
version,
|
version,
|
||||||
scanner,
|
|
||||||
out,
|
out,
|
||||||
|
scanner,
|
||||||
showast=show_ast,
|
showast=show_ast,
|
||||||
debug_parser=debug_parser,
|
debug_parser=debug_parser,
|
||||||
compile_mode=compile_mode,
|
compile_mode=compile_mode,
|
||||||
@@ -210,4 +214,4 @@ if __name__ == "__main__":
|
|||||||
print(deparsed.text)
|
print(deparsed.text)
|
||||||
return
|
return
|
||||||
|
|
||||||
deparse_test(deparse_test.__code__)
|
deparse_test(deparse_test.func_code)
|
||||||
|
@@ -108,4 +108,4 @@ if __name__ == "__main__":
|
|||||||
# assert linemap == linemap2
|
# assert linemap == linemap2
|
||||||
return
|
return
|
||||||
|
|
||||||
deparse_test(deparse_test.__code__)
|
deparse_test(deparse_test.func_code)
|
||||||
|
Reference in New Issue
Block a user