diff --git a/test/bytecode_3.4/if.cpython-34.pyc b/test/bytecode_3.4/if.cpython-34.pyc deleted file mode 100644 index e25e3951..00000000 Binary files a/test/bytecode_3.4/if.cpython-34.pyc and /dev/null differ diff --git a/test/bytecode_3.4/if.pyc b/test/bytecode_3.4/if.pyc new file mode 100644 index 00000000..896df400 Binary files /dev/null and b/test/bytecode_3.4/if.pyc differ diff --git a/test/bytecode_3.4/ifelse.cpython-34.pyc b/test/bytecode_3.4/ifelse.cpython-34.pyc deleted file mode 100644 index 3ef9891e..00000000 Binary files a/test/bytecode_3.4/ifelse.cpython-34.pyc and /dev/null differ diff --git a/test/bytecode_3.4/ifelse.pyc b/test/bytecode_3.4/ifelse.pyc new file mode 100644 index 00000000..593999eb Binary files /dev/null and b/test/bytecode_3.4/ifelse.pyc differ diff --git a/test/bytecode_3.4/keyword.cpython-34.pyc b/test/bytecode_3.4/keyword.cpython-34.pyc deleted file mode 100644 index 96307627..00000000 Binary files a/test/bytecode_3.4/keyword.cpython-34.pyc and /dev/null differ diff --git a/test/bytecode_3.4/keyword.pyc b/test/bytecode_3.4/keyword.pyc new file mode 100644 index 00000000..aa97f8b4 Binary files /dev/null and b/test/bytecode_3.4/keyword.pyc differ diff --git a/test/bytecode_3.4/positional.pyc b/test/bytecode_3.4/positional.pyc new file mode 100644 index 00000000..caf301e1 Binary files /dev/null and b/test/bytecode_3.4/positional.pyc differ diff --git a/test/bytecode_3.4/positional.python-34.pyc b/test/bytecode_3.4/positional.python-34.pyc deleted file mode 100644 index 0584455f..00000000 Binary files a/test/bytecode_3.4/positional.python-34.pyc and /dev/null differ diff --git a/test/bytecompile-tests b/test/bytecompile-tests index fac38d74..15b6d4d2 100755 --- a/test/bytecompile-tests +++ b/test/bytecompile-tests @@ -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'] diff --git a/test/simple-source/branching/if.py b/test/simple-source/branching/if.py index 6b23f642..59bcb560 100644 --- a/test/simple-source/branching/if.py +++ b/test/simple-source/branching/if.py @@ -1,2 +1,4 @@ +# Tests: +# ifstmt ::= testexpr _ifstmts_jump if a: b = c diff --git a/test/simple-source/branching/ifelse.py b/test/simple-source/branching/ifelse.py index dafa42cd..1f21e49b 100644 --- a/test/simple-source/branching/ifelse.py +++ b/test/simple-source/branching/ifelse.py @@ -1,3 +1,6 @@ + +# Tests +# ifelsestmt ::= testexpr c_stmts_opt JUMP_FORWARD else_suite COME_FROM if a: b = c else: diff --git a/test/simple-source/looping/for.py b/test/simple-source/looping/for.py index 87a3bd55..a1ec00e3 100644 --- a/test/simple-source/looping/for.py +++ b/test/simple-source/looping/for.py @@ -1,2 +1,5 @@ +# Tests: +# forstmt ::= SETUP_LOOP expr _for designator +# for_block POP_BLOCK COME_FROM for a in b: c = d diff --git a/uncompyle6/__init__.py b/uncompyle6/__init__.py index 06a8cdfd..d9a29202 100644 --- a/uncompyle6/__init__.py +++ b/uncompyle6/__init__.py @@ -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() diff --git a/uncompyle6/disas.py b/uncompyle6/disas.py index 9634245b..0daff2d3 100644 --- a/uncompyle6/disas.py +++ b/uncompyle6/disas.py @@ -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): diff --git a/uncompyle6/parsers/spark.py b/uncompyle6/parsers/spark.py index a0122f5a..cd7b877b 100644 --- a/uncompyle6/parsers/spark.py +++ b/uncompyle6/parsers/spark.py @@ -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 = []