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