From b82a8b90d5961af4c43c5bb1db42a52bf86d3b1e Mon Sep 17 00:00:00 2001 From: rocky Date: Wed, 30 Dec 2015 23:46:29 -0500 Subject: [PATCH] Allow Python 3.5 to decomplyle other versions. No Python 3.5 bytecode support just yet though. --- Makefile | 2 +- test/Makefile | 3 +++ uncompyle6/__init__.py | 4 ++-- uncompyle6/disas.py | 2 +- uncompyle6/load.py | 9 +++++---- uncompyle6/magics.py | 2 +- uncompyle6/scanner.py | 8 ++++---- uncompyle6/scanners/scanner3.py | 6 +++--- 8 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 5705b9bf..1f7568e1 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ check: $(MAKE) check-$$PYTHON_VERSION #: Tests for Python 2.7, 3.3 and 3.4 -check-2.7 check-3.3 check-3.4: pytest +check-2.7 check-3.3 check-3.4 check-3.5: pytest $(MAKE) -C test $@ #:Tests for Python 2.6 (doesn't have pytest) diff --git a/test/Makefile b/test/Makefile index 2f2530ad..b755dc04 100644 --- a/test/Makefile +++ b/test/Makefile @@ -26,6 +26,9 @@ check-2.6 check-2.7: check-bytecode check-2.7-ok check-3.3: check-bytecode $(PYTHON) test_pythonlib.py --bytecode-3.3 --verify $(COMPILE) +#: Run working tests from Python 3.5 +check-3.5: check-bytecode + #: Run working tests from Python 3.4 check-3.4: check-bytecode check-2.7-ok diff --git a/uncompyle6/__init__.py b/uncompyle6/__init__.py index b1c60eaf..42e9d337 100644 --- a/uncompyle6/__init__.py +++ b/uncompyle6/__init__.py @@ -42,8 +42,8 @@ PYTHON_VERSION_STR = "%s.%s" % (sys.version_info[0], sys.version_info[1]) sys.setrecursionlimit(5000) def check_python_version(program): - if not (sys.version_info[0:2] in ((2, 6), (2, 7), (3, 2), (3, 3), (3, 4))): - print('Error: %s requires Python 2.6, 2.7, 3.2, 3.3, or 3.4' % program, + if not (sys.version_info[0:2] in ((2, 6), (2, 7), (3, 2), (3, 3), (3, 4), (3, 5))): + print('Error: %s requires Python 2.6, 2.7, 3.2, 3.3, 3.4 or 3.5' % program, file=sys.stderr) sys.exit(-1) return diff --git a/uncompyle6/disas.py b/uncompyle6/disas.py index 82e65e76..52a3db83 100644 --- a/uncompyle6/disas.py +++ b/uncompyle6/disas.py @@ -18,7 +18,7 @@ want to run on Python 2.7. from __future__ import print_function -import inspect, os, sys +import os, sys import uncompyle6 from uncompyle6.code import iscode diff --git a/uncompyle6/load.py b/uncompyle6/load.py index f6d56fcf..f4d6bf69 100644 --- a/uncompyle6/load.py +++ b/uncompyle6/load.py @@ -77,9 +77,9 @@ def load_module(filename, code_objects={}): else: raise ImportError("Bad magic number: '%s'" % magic) - if not (2.5 <= version <= 2.7) and not (3.2 <= version <= 3.4): + if not (2.5 <= version <= 2.7) and not (3.2 <= version <= 3.5): raise ImportError("This is a Python %s file! Only " - "Python 2.5 to 2.7 and 3.2 to 3.4 files are supported." + "Python 2.5 to 2.7 and 3.2 to 3.5 files are supported." % version) # print version @@ -110,7 +110,8 @@ if __name__ == '__main__': co = load_file(__file__) obj_path = check_object_path(__file__) version, timestamp, magic_int, co2 = load_module(obj_path) - print("version ", version, "magic int", magic_int) + print("version", version, "magic int", magic_int) import datetime print(datetime.datetime.fromtimestamp(timestamp)) - assert co == co2 + if version < 3.5: + assert co == co2 diff --git a/uncompyle6/magics.py b/uncompyle6/magics.py index 6bf166b0..57674bdb 100755 --- a/uncompyle6/magics.py +++ b/uncompyle6/magics.py @@ -87,7 +87,7 @@ versions = { __build_magic(3290): '3.4', # 3.4a4 3290 (changes to __qualname__ computation) __build_magic(3300): '3.4', # 3.4a4 3300 (more changes to __qualname__ computation) __build_magic(3310): '3.4', # 3.4rc2 3310 (alter __qualname__ computation) - + __build_magic(3350): '3.5', # 3.5.0 } magics = __by_version(versions) diff --git a/uncompyle6/scanner.py b/uncompyle6/scanner.py index b156b4f1..a221069c 100755 --- a/uncompyle6/scanner.py +++ b/uncompyle6/scanner.py @@ -62,7 +62,7 @@ class Scanner(object): elif version == 3.4: self.opc = opcode_34 else: - raise TypeError("%i is not a Python version I know about") + raise TypeError("%s is not a Python version I know about" % version) # FIXME: This weird Python2 behavior is not Python3 self.resetTokenClass() @@ -298,13 +298,13 @@ def get_scanner(version): scanner = scan.Scanner25() elif version == 3.2: import uncompyle6.scanners.scanner32 as scan - scanner = scan.Scanner32() + scanner = scan.Scanner32(version) elif version == 3.3: import uncompyle6.scanners.scanner33 as scan - scanner = scan.Scanner33() + scanner = scan.Scanner33(version) elif version == 3.4: import uncompyle6.scanners.scanner34 as scan - scanner = scan.Scanner34() + scanner = scan.Scanner34(version) else: raise RuntimeError("Unsupported Python version %d" % version) return scanner diff --git a/uncompyle6/scanners/scanner3.py b/uncompyle6/scanners/scanner3.py index 007f70bb..6bf1b60d 100644 --- a/uncompyle6/scanners/scanner3.py +++ b/uncompyle6/scanners/scanner3.py @@ -15,7 +15,7 @@ from array import array from uncompyle6.code import iscode from uncompyle6.scanner import Token -from uncompyle6 import PYTHON_VERSION, PYTHON3 +from uncompyle6 import PYTHON3 # Get all the opcodes into globals @@ -27,8 +27,8 @@ import uncompyle6.scanner as scan class Scanner3(scan.Scanner): - def __init__(self): - scan.Scanner.__init__(self, PYTHON_VERSION) + def __init__(self, version): + scan.Scanner.__init__(self, version) def disassemble_generic(self, co, classname=None, code_objects={}): """