You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-02 16:44:46 +08:00
Add spark grammar debugging. Start to comment grammer construct covered
by simple tests.
This commit is contained in:
Binary file not shown.
BIN
test/bytecode_3.4/if.pyc
Normal file
BIN
test/bytecode_3.4/if.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
test/bytecode_3.4/ifelse.pyc
Normal file
BIN
test/bytecode_3.4/ifelse.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
test/bytecode_3.4/keyword.pyc
Normal file
BIN
test/bytecode_3.4/keyword.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/positional.pyc
Normal file
BIN
test/bytecode_3.4/positional.pyc
Normal file
Binary file not shown.
Binary file not shown.
@@ -12,6 +12,7 @@ for further information
|
||||
from __future__ import print_function
|
||||
|
||||
import py_compile, os, sys, getopt
|
||||
from fnmatch import fnmatch
|
||||
|
||||
work_dir = os.path.dirname(sys.argv[0])
|
||||
src_dir = work_dir
|
||||
@@ -61,14 +62,22 @@ tests['2.7'] = [
|
||||
# 'simple-source/call_arguments/positional'
|
||||
]
|
||||
|
||||
tests['3.4'] = [
|
||||
# 'simple-source/branching/ifelse',
|
||||
# 'simple-source/branching/if'
|
||||
# 'simple-source/call_arguments/keyword',
|
||||
# 'simple-source/call_arguments/positional'
|
||||
'simple-source/looping/for',
|
||||
'simple-source/looping/while'
|
||||
]
|
||||
def file_matches(files, root, basenames, patterns):
|
||||
files.extend(
|
||||
[os.path.normpath(os.path.join(root, n))
|
||||
for n in basenames for pat in patterns
|
||||
if fnmatch(n, pat)])
|
||||
|
||||
PY = ('*.py', )
|
||||
files = ['simple-source']
|
||||
simple_source = []
|
||||
for root, dirs, basenames in os.walk('simple-source'):
|
||||
for basename in basenames:
|
||||
if basename.endswith('.py'):
|
||||
simple_source.append(os.path.join(root, basename)[0:-3])
|
||||
pass
|
||||
|
||||
tests['3.4'] = simple_source
|
||||
|
||||
total_tests = len(tests['2.7'])
|
||||
#tests['2.2'].sort(); print tests['2.2']
|
||||
|
@@ -1,2 +1,4 @@
|
||||
# Tests:
|
||||
# ifstmt ::= testexpr _ifstmts_jump
|
||||
if a:
|
||||
b = c
|
||||
|
@@ -1,3 +1,6 @@
|
||||
|
||||
# Tests
|
||||
# ifelsestmt ::= testexpr c_stmts_opt JUMP_FORWARD else_suite COME_FROM
|
||||
if a:
|
||||
b = c
|
||||
else:
|
||||
|
@@ -1,2 +1,5 @@
|
||||
# Tests:
|
||||
# forstmt ::= SETUP_LOOP expr _for designator
|
||||
# for_block POP_BLOCK COME_FROM
|
||||
for a in b:
|
||||
c = d
|
||||
|
@@ -38,6 +38,7 @@ PYTHON3 = (sys.version_info >= (3, 0))
|
||||
|
||||
import uncompyle6
|
||||
from uncompyle6.scanner import get_scanner
|
||||
from uncompyle6.disas import check_object_path
|
||||
import uncompyle6.marsh
|
||||
from uncompyle6 import walker, verify, magics
|
||||
|
||||
@@ -158,6 +159,7 @@ def uncompyle_file(filename, outstream=None, showasm=False, showast=False):
|
||||
"""
|
||||
decompile Python byte-code file (.pyc)
|
||||
"""
|
||||
check_object_path(filename)
|
||||
version, co = load_module(filename)
|
||||
if type(co) == list:
|
||||
for con in co:
|
||||
@@ -246,6 +248,9 @@ def main(in_base, out_base, files, codes, outfile=None,
|
||||
try:
|
||||
uncompyle_file(infile, outstream, showasm, showast)
|
||||
tot_files += 1
|
||||
except FileNotFoundError as e:
|
||||
sys.stderr.write("\n# %s" % e)
|
||||
failed_files += 1
|
||||
except KeyboardInterrupt:
|
||||
if outfile:
|
||||
outstream.close()
|
||||
@@ -259,8 +264,6 @@ def main(in_base, out_base, files, codes, outfile=None,
|
||||
os.rename(outfile, outfile + '_failed')
|
||||
else:
|
||||
sys.stderr.write("\n# Can't uncompyle %s\n" % infile)
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
else: # uncompyle successfull
|
||||
if outfile:
|
||||
outstream.close()
|
||||
|
@@ -28,7 +28,8 @@ def check_object_path(path):
|
||||
path = importlib.util.cache_from_source(path)
|
||||
return path
|
||||
if not path.endswith(".pyc") and not path.endswith(".pyo"):
|
||||
raise ValueError("path must point to a .py or .pyc file")
|
||||
raise FileNotFoundError("path %s must point to a .py or .pyc file" %
|
||||
path)
|
||||
return path
|
||||
|
||||
def disco(version, co, out=None):
|
||||
|
@@ -56,13 +56,14 @@ class GenericParser:
|
||||
Parsing", unpublished paper, 2001.
|
||||
'''
|
||||
|
||||
def __init__(self, start):
|
||||
def __init__(self, start, debug=False):
|
||||
self.rules = {}
|
||||
self.rule2func = {}
|
||||
self.rule2name = {}
|
||||
self.collectRules()
|
||||
self.augment(start)
|
||||
self.ruleschanged = 1
|
||||
self.ruleschanged = True
|
||||
self.debug = debug
|
||||
|
||||
_NULLABLE = '\e_'
|
||||
_START = 'START'
|
||||
@@ -82,7 +83,7 @@ class GenericParser:
|
||||
self.newrules = {}
|
||||
self.new2old = {}
|
||||
self.makeNewRules()
|
||||
self.ruleschanged = 0
|
||||
self.ruleschanged = False
|
||||
self.edges, self.cores = {}, {}
|
||||
self.states = { 0: self.makeState0() }
|
||||
self.makeState(0, self._BOF)
|
||||
@@ -149,7 +150,7 @@ class GenericParser:
|
||||
self.rules[lhs] = [ rule ]
|
||||
self.rule2func[rule] = fn
|
||||
self.rule2name[rule] = func.__name__[2:]
|
||||
self.ruleschanged = 1
|
||||
self.ruleschanged = True
|
||||
|
||||
def collectRules(self):
|
||||
for name in _namelist(self):
|
||||
@@ -263,7 +264,7 @@ class GenericParser:
|
||||
self.newrules = {}
|
||||
self.new2old = {}
|
||||
self.makeNewRules()
|
||||
self.ruleschanged = 0
|
||||
self.ruleschanged = False
|
||||
self.edges, self.cores = {}, {}
|
||||
self.states = { 0: self.makeState0() }
|
||||
self.makeState(0, self._BOF)
|
||||
@@ -400,6 +401,7 @@ class GenericParser:
|
||||
return rv
|
||||
|
||||
def gotoT(self, state, t):
|
||||
if self.debug: print("Terminal", t)
|
||||
return [self.goto(state, t)]
|
||||
|
||||
def gotoST(self, state, st):
|
||||
@@ -565,6 +567,8 @@ class GenericParser:
|
||||
return self.rule2func[self.new2old[rule]](attr)
|
||||
|
||||
def buildTree(self, nt, item, tokens, k):
|
||||
if self.debug:
|
||||
print("NT", nt)
|
||||
state, parent = item
|
||||
|
||||
choices = []
|
||||
|
Reference in New Issue
Block a user