X Tutup
Skip to content

Commit 9cdcdfd

Browse files
committed
Part of a much needed cleanup. Move semantics routines into its own
directory. Move out lots of stuff from __init__ to their own files. Add file loading tests. Document AST handling a tad more complete.
1 parent 6910e1b commit 9cdcdfd

File tree

13 files changed

+461
-450
lines changed

13 files changed

+461
-450
lines changed

Makefile

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,8 @@ TEST_TYPES=check-long check-short check-2.7 check-3.4
1818
#: Default target - same as "check"
1919
all: check
2020

21-
all test check check_long:
22-
@$(PYTHON) -V && PYTHON_VERSION=`$(PYTHON) -V 2>&1 | cut -d ' ' -f 2 | cut -d'.' -f1,2`; \
23-
$(MAKE) check-$$PYTHON_VERSION
24-
25-
#: Run working tests from Python 2.7
26-
check-2.7: pytest
27-
$(MAKE) -C test $@
28-
29-
#: Run working tests from Python 3.4
30-
check-3.4:
21+
#: Run working tests
22+
check check-3.4 check-2.7: pytest
3123
$(MAKE) -C test $@
3224

3325
#: Run py.test tests

bin/uncompyle6

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# Mode: -*- python -*-
33
#
44
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
5-
#
5+
# Copyright (c) 2015 by Rocky Bernstein
6+
67
"""
78
Usage: uncompyle6 [OPTIONS]... [ FILE | DIR]...
89
@@ -41,15 +42,19 @@ Extensions of generated files:
4142
"""
4243

4344
from __future__ import print_function
44-
import sys, os, getopt
45+
import sys, os, getopt, time
4546

4647
program = os.path.basename(__file__)
4748

48-
Usage_short = \
49-
"%s [--help] [--verify] [--showasm] [--showast] [-o <path>] FILE|DIR..." % program
49+
from uncompyle6 import verify, check_python_version
50+
from uncompyle6.main import main, status_msg
51+
52+
def usage():
53+
print("""usage:
54+
%s [--help] [--verify] [--showasm] [--showast] [-o <path>] FILE|DIR...
55+
""" % program)
56+
sys.exit(1)
5057

51-
from uncompyle6 import main, status_msg, verify, check_python_version
52-
import time
5358

5459
check_python_version(program)
5560

@@ -91,9 +96,8 @@ for opt, val in opts:
9196
elif opt == '-r':
9297
recurse_dirs = True
9398
else:
94-
print(opt)
95-
print(Usage_short)
96-
sys.exit(1)
99+
print(opt, file=sys.stderr)
100+
usage()
97101

98102
# expand directory if specified
99103
if recurse_dirs:
@@ -117,6 +121,11 @@ if src_base:
117121
files = [f[sb_len:] for f in files]
118122
del sb_len
119123

124+
if not files:
125+
print("No files given", file=sys.stderr)
126+
usage()
127+
128+
120129
if outfile == '-':
121130
outfile = None # use stdout
122131
elif outfile and os.path.isdir(outfile):
@@ -162,7 +171,7 @@ else:
162171
if f is None:
163172
break
164173
(t, o, f, v) = \
165-
main(src_base, out_base, [f], codes, outfile, showasm, showast, do_verify)
174+
main(src_base, out_base, [f], codes, outfile, showasm, showast, do_verify)
166175
tot_files += t
167176
okay_files += o
168177
failed_files += f

pytest/test_load.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from uncompyle6.load import load_file, check_object_path, load_module
2+
3+
def test_load():
4+
"""Basic test of load_file, check_object_path and load_module"""
5+
co = load_file(__file__)
6+
obj_path = check_object_path(__file__)
7+
co2 = load_module(obj_path)
8+
assert co == co2[2]

test/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ check-2.7: check-bytecode check-2.7-ok
2424

2525
#: Run working tests from Python 3.4
2626
check-3.4: check-bytecode
27+
$(PYTHON) test_pythonlib.py --bytecode-3.4
2728

2829
#: Check deparsing only, but from a different Python version
2930
check-disasm:
3031
$(PYTHON) dis-compare.py
3132

3233
#: Check deparsing bytecode only
33-
check-bytecode: check-bytecode-2.5 check-bytecode-2.5 check-bytecode-3.2
34+
check-bytecode:
35+
$(PYTHON) test_pythonlib.py --bytecode-2.5 --bytecode-2.7 --bytecode-3.2
3436

3537
#: Check deparsing Python 2.5
3638
check-bytecode-2.5:

test/test_pythonlib.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131

3232
import getopt, os, py_compile, sys, shutil, tempfile, time
3333

34-
from uncompyle6 import main, PYTHON_VERSION
34+
from uncompyle6 import PYTHON_VERSION
35+
from uncompyle6.main import main
3536
from fnmatch import fnmatch
3637

3738
def get_srcdir():
@@ -212,10 +213,7 @@ def file_matches(files, root, basenames, patterns):
212213
print("Can't find directory %s. Skipping" % src_dir,
213214
file=sys.stderr)
214215
continue
215-
if last_compile_version and last_compile_version != compiled_version:
216-
print("Warning: mixed python version decompylation")
217-
else:
218-
last_compile_version = compiled_version
216+
last_compile_version = compiled_version
219217
pass
220218

221219
if not checked_dirs:

0 commit comments

Comments
 (0)
X Tutup