You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Sync with master
This commit is contained in:
@@ -55,16 +55,16 @@ Options:
|
||||
-V | --version show version and stop
|
||||
-h | --help show this message
|
||||
|
||||
""" % ((program,) * 5)
|
||||
""" % (
|
||||
(program,) * 5
|
||||
)
|
||||
|
||||
PATTERNS = ("*.pyc", "*.pyo")
|
||||
|
||||
|
||||
def main():
|
||||
usage_short = (
|
||||
f"""usage: {program} FILE...
|
||||
usage_short = f"""usage: {program} FILE...
|
||||
Type -h for for full help."""
|
||||
)
|
||||
|
||||
if len(sys.argv) == 1:
|
||||
sys.stderr.write("No file(s) given\n")
|
||||
@@ -76,7 +76,7 @@ Type -h for for full help."""
|
||||
sys.argv[1:], "hVU", ["help", "version", "uncompyle6"]
|
||||
)
|
||||
except getopt.GetoptError(e):
|
||||
sys.stderr.write('%s: %s' % (os.path.basename(sys.argv[0]), e))
|
||||
sys.stderr.write("%s: %s" % (os.path.basename(sys.argv[0]), e))
|
||||
sys.exit(-1)
|
||||
|
||||
for opt, val in opts:
|
||||
|
@@ -6,22 +6,17 @@
|
||||
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
|
||||
#
|
||||
|
||||
import getopt
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
from uncompyle6.verify import VerifyCmpError
|
||||
from uncompyle6.main import main, status_msg
|
||||
from uncompyle6.verify import VerifyCmpError
|
||||
from uncompyle6.version import __version__
|
||||
|
||||
program = "uncompyle6"
|
||||
|
||||
|
||||
def usage():
|
||||
print(__doc__)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
__doc__ = """
|
||||
Usage:
|
||||
%s [OPTIONS]... [ FILE | DIR]...
|
||||
@@ -74,18 +69,44 @@ Extensions of generated files:
|
||||
(program,) * 5
|
||||
)
|
||||
|
||||
program = "uncompyle6"
|
||||
|
||||
def usage():
|
||||
print(__doc__)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def main_bin():
|
||||
if not (
|
||||
sys.version_info[0:2]
|
||||
in (
|
||||
(2, 4),
|
||||
(2, 5),
|
||||
(2, 6),
|
||||
(2, 7),
|
||||
(3, 0),
|
||||
(3, 1),
|
||||
(3, 2),
|
||||
(3, 3),
|
||||
(3, 4),
|
||||
(3, 5),
|
||||
(3, 6),
|
||||
(3, 7),
|
||||
(3, 8),
|
||||
(3, 9),
|
||||
(3, 10),
|
||||
(3, 11),
|
||||
)
|
||||
):
|
||||
print('Error: %s requires Python 2.4-3.10' % program)
|
||||
sys.exit(-1)
|
||||
|
||||
recurse_dirs = False
|
||||
numproc = 0
|
||||
out_base = None
|
||||
|
||||
outfile = "-"
|
||||
out_base = None
|
||||
source_paths = []
|
||||
timestamp = False
|
||||
timestampfmt = "# %Y.%m.%d %H:%M:%S %Z"
|
||||
pyc_paths = files
|
||||
|
||||
try:
|
||||
opts, pyc_paths = getopt.getopt(
|
||||
@@ -196,17 +217,10 @@ Extensions of generated files:
|
||||
out_base = outfile
|
||||
outfile = None
|
||||
|
||||
# A second -a turns show_asm="after" into show_asm="before"
|
||||
if asm_plus or asm:
|
||||
asm_opt = "both" if asm_plus else "after"
|
||||
else:
|
||||
asm_opt = None
|
||||
|
||||
if timestamp:
|
||||
print(time.strftime(timestampfmt))
|
||||
|
||||
if numproc <= 1:
|
||||
show_ast = {"before": tree or tree_plus, "after": tree_plus}
|
||||
try:
|
||||
result = main(
|
||||
src_base,
|
||||
@@ -214,14 +228,15 @@ Extensions of generated files:
|
||||
pyc_paths,
|
||||
source_paths,
|
||||
outfile,
|
||||
showasm=asm_opt,
|
||||
showgrammar=show_grammar,
|
||||
showast=show_ast,
|
||||
do_verify=verify,
|
||||
do_linemaps=linemaps,
|
||||
start_offset=start_offset,
|
||||
stop_offset=stop_offset,
|
||||
showasm=options["showasm"],
|
||||
showgrammar=options["showgrammar"],
|
||||
showast=options["showast"],
|
||||
do_verify=options["do_verify"],
|
||||
do_linemaps=options["do_linemaps"],
|
||||
start_offset=0,
|
||||
stop_offset=-1,
|
||||
)
|
||||
result = [options.get("do_verify", None)] + list(result)
|
||||
if len(pyc_paths) > 1:
|
||||
mess = status_msg(*result)
|
||||
print("# " + mess)
|
||||
|
@@ -13,7 +13,7 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import ast
|
||||
# import ast
|
||||
import datetime
|
||||
import os
|
||||
import os.path as osp
|
||||
@@ -52,15 +52,19 @@ def _get_outstream(outfile):
|
||||
pass
|
||||
return open(outfile, 'wb')
|
||||
|
||||
def syntax_check(filename: str) -> bool:
|
||||
with open(filename) as f:
|
||||
source = f.read()
|
||||
valid = True
|
||||
try:
|
||||
ast.parse(source)
|
||||
except SyntaxError:
|
||||
valid = False
|
||||
return valid
|
||||
# def syntax_check(filename):
|
||||
# f = open(filename, "r")
|
||||
# try:
|
||||
# source = f.read()
|
||||
# finally:
|
||||
# f.close()
|
||||
# valid = True
|
||||
# try:
|
||||
# ast.parse(source)
|
||||
# except SyntaxError:
|
||||
# valid = False
|
||||
# return valid
|
||||
|
||||
|
||||
|
||||
def decompile(
|
||||
@@ -74,13 +78,13 @@ def decompile(
|
||||
source_encoding=None,
|
||||
code_objects={},
|
||||
source_size=None,
|
||||
is_pypy: bool = False,
|
||||
is_pypy=False,
|
||||
magic_int=None,
|
||||
mapstream=None,
|
||||
do_fragments=False,
|
||||
compile_mode="exec",
|
||||
start_offset: int = 0,
|
||||
stop_offset: int = -1,
|
||||
start_offset=0,
|
||||
stop_offset=-1,
|
||||
):
|
||||
"""
|
||||
ingests and deparses a given code block 'co'
|
||||
@@ -215,7 +219,7 @@ def compile_file(source_path):
|
||||
|
||||
|
||||
def decompile_file(
|
||||
filename: str,
|
||||
filename,
|
||||
outstream=None,
|
||||
showasm=None,
|
||||
showast={},
|
||||
@@ -293,12 +297,12 @@ def main(
|
||||
showasm=None,
|
||||
showast={},
|
||||
do_verify=None,
|
||||
showgrammar: bool = False,
|
||||
showgrammar = False,
|
||||
source_encoding=None,
|
||||
do_linemaps=False,
|
||||
do_fragments=False,
|
||||
start_offset: int = 0,
|
||||
stop_offset: int = -1,
|
||||
start_offset=0,
|
||||
stop_offset=-1,
|
||||
):
|
||||
"""
|
||||
in_base base directory for input files
|
||||
@@ -312,7 +316,9 @@ def main(
|
||||
- stdout out_base=None, outfile=None
|
||||
"""
|
||||
tot_files = okay_files = failed_files = 0
|
||||
verify_failed_files = 0 if do_verify else 0
|
||||
|
||||
verify_failed_files = 0
|
||||
|
||||
current_outfile = outfile
|
||||
linemap_stream = None
|
||||
|
||||
@@ -423,7 +429,9 @@ def main(
|
||||
print(result.stderr.decode())
|
||||
|
||||
else:
|
||||
valid = syntax_check(deparsed_object.f.name)
|
||||
print("Syntax checking not supported before Python 3.0")
|
||||
# valid = syntax_check(deparsed_object.f.name)
|
||||
valid = True
|
||||
|
||||
if not valid:
|
||||
verify_failed_files += 1
|
||||
|
@@ -869,29 +869,6 @@ class Python3Parser(PythonParser):
|
||||
rule = "starred ::= %s %s" % ("expr " * v, opname)
|
||||
self.addRule(rule, nop_func)
|
||||
|
||||
elif opname in ("BUILD_CONST_LIST", "BUILD_CONST_DICT", "BUILD_CONST_SET"):
|
||||
if opname == "BUILD_CONST_DICT":
|
||||
rule = (
|
||||
"""
|
||||
add_consts ::= ADD_VALUE*
|
||||
const_list ::= COLLECTION_START add_consts %s
|
||||
dict ::= const_list
|
||||
expr ::= dict
|
||||
"""
|
||||
% opname
|
||||
)
|
||||
else:
|
||||
rule = (
|
||||
"""
|
||||
add_consts ::= ADD_VALUE*
|
||||
const_list ::= COLLECTION_START add_consts %s
|
||||
expr ::= const_list
|
||||
"""
|
||||
% opname
|
||||
)
|
||||
self.addRule(rule, nop_func)
|
||||
|
||||
>>>>>>> python-3.0-to-3.2
|
||||
elif opname_base in (
|
||||
"BUILD_LIST",
|
||||
"BUILD_SET",
|
||||
|
@@ -47,4 +47,6 @@ if __name__ == "__main__":
|
||||
print(t.format())
|
||||
pass
|
||||
else:
|
||||
print("Need to be Python 3.3 to demo; I am version %s." % version_tuple_to_str())
|
||||
print(
|
||||
"Need to be Python 3.3 to demo; I am version %s." % version_tuple_to_str()
|
||||
)
|
||||
|
@@ -2054,8 +2054,8 @@ def code_deparse(
|
||||
code_objects={},
|
||||
compile_mode="exec",
|
||||
walker=FragmentsWalker,
|
||||
start_offset: int = 0,
|
||||
stop_offset: int = -1,
|
||||
start_offset=0,
|
||||
stop_offset=-1,
|
||||
):
|
||||
"""
|
||||
Convert the code object co into a python source fragment.
|
||||
@@ -2189,7 +2189,7 @@ def code_deparse_around_offset(
|
||||
co,
|
||||
out=StringIO(),
|
||||
version=None,
|
||||
is_pypy = False,
|
||||
is_pypy=False,
|
||||
debug_opts=DEFAULT_DEBUG_OPTS,
|
||||
):
|
||||
"""
|
||||
|
@@ -130,9 +130,9 @@ Python.
|
||||
# evaluating the escape code.
|
||||
|
||||
import sys
|
||||
from io import StringIO
|
||||
|
||||
from spark_parser import GenericASTTraversal
|
||||
from StringIO import StringIO
|
||||
from xdis import COMPILER_FLAG_BIT, iscode
|
||||
from xdis.version_info import PYTHON_VERSION_TRIPLE
|
||||
|
||||
@@ -221,7 +221,7 @@ class SourceWalker(GenericASTTraversal, NonterminalActions, ComprehensionMixin):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
version: tuple,
|
||||
version,
|
||||
out,
|
||||
scanner,
|
||||
showast=TREE_DEFAULT_DEBUG,
|
||||
@@ -397,7 +397,7 @@ class SourceWalker(GenericASTTraversal, NonterminalActions, ComprehensionMixin):
|
||||
i += 1
|
||||
return rv
|
||||
|
||||
def indent_if_source_nl(self, line_number, indent):
|
||||
def indent_if_source_nl(self, line_number, indent_spaces):
|
||||
if line_number != self.line_number:
|
||||
self.write("\n" + indent_spaces + INDENT_PER_LEVEL[:-1])
|
||||
return self.line_number
|
||||
@@ -1206,7 +1206,7 @@ class SourceWalker(GenericASTTraversal, NonterminalActions, ComprehensionMixin):
|
||||
is_lambda=False,
|
||||
noneInNames=False,
|
||||
is_top_level_module=False,
|
||||
) -> GenericASTTraversal:
|
||||
):
|
||||
# FIXME: DRY with fragments.py
|
||||
|
||||
# assert isinstance(tokens[0], Token)
|
||||
@@ -1294,8 +1294,8 @@ def code_deparse(
|
||||
compile_mode="exec",
|
||||
is_pypy=IS_PYPY,
|
||||
walker=SourceWalker,
|
||||
start_offset: int = 0,
|
||||
stop_offset: int = -1,
|
||||
start_offset = 0,
|
||||
stop_offset = -1,
|
||||
):
|
||||
"""
|
||||
ingests and deparses a given code block 'co'. If version is None,
|
||||
@@ -1452,9 +1452,9 @@ def deparse_code2str(
|
||||
compile_mode="exec",
|
||||
is_pypy=IS_PYPY,
|
||||
walker=SourceWalker,
|
||||
start_offset: int = 0,
|
||||
stop_offset: int = -1,
|
||||
) -> str:
|
||||
start_offset=0,
|
||||
stop_offset=-1,
|
||||
):
|
||||
"""
|
||||
Return the deparsed text for a Python code object. `out` is where
|
||||
any intermediate output for assembly or tree output will be sent.
|
||||
|
@@ -56,7 +56,7 @@ def is_docstring(node, version, co_consts):
|
||||
return node == ASSIGN_DOC_STRING(co_consts[0], doc_load)
|
||||
|
||||
|
||||
def is_not_docstring(call_stmt_node) -> bool:
|
||||
def is_not_docstring(call_stmt_node):
|
||||
try:
|
||||
return (
|
||||
call_stmt_node == "call_stmt"
|
||||
@@ -70,7 +70,7 @@ def is_not_docstring(call_stmt_node) -> bool:
|
||||
class TreeTransform(GenericASTTraversal, object):
|
||||
def __init__(
|
||||
self,
|
||||
version: tuple,
|
||||
version,
|
||||
is_pypy=False,
|
||||
show_ast=None,
|
||||
):
|
||||
@@ -462,7 +462,7 @@ class TreeTransform(GenericASTTraversal, object):
|
||||
node = self.preorder(node)
|
||||
return node
|
||||
|
||||
def transform(self, parse_tree: GenericASTTraversal, code) -> GenericASTTraversal:
|
||||
def transform(self, parse_tree, code):
|
||||
self.maybe_show_tree(parse_tree)
|
||||
self.ast = copy(parse_tree)
|
||||
del parse_tree
|
||||
|
Reference in New Issue
Block a user