From 62e60817f64e75bc640f3ab6123eb97784274b37 Mon Sep 17 00:00:00 2001 From: rocky Date: Fri, 8 Jul 2016 14:56:57 -0400 Subject: [PATCH] Start handling Pyton 2.4 bytecodes --- __pkginfo__.py | 2 +- test/Makefile | 6 ++- test/add-test.py | 16 ++++---- test/bytecode_2.4/03_if_elif.pyc | Bin 0 -> 266 bytes test/bytecode_2.4/04_raise.pyc | Bin 0 -> 307 bytes test/bytecode_2.7/03_if_elif.pyc | Bin 0 -> 261 bytes test/bytecode_2.7/04_raise.pyc | Bin 0 -> 333 bytes test/bytecode_2.7/04_withas.pyc | Bin 0 -> 294 bytes test/test_pyenvlib.py | 3 +- test/test_pythonlib.py | 2 +- uncompyle6/parser.py | 6 +++ uncompyle6/parsers/parse24.py | 28 +++++++++++++ uncompyle6/parsers/parse25.py | 4 +- uncompyle6/scanner.py | 2 +- uncompyle6/scanners/scanner24.py | 68 +++++++++++++++++++++++++++++++ uncompyle6/scanners/scanner25.py | 4 -- uncompyle6/semantics/pysource.py | 5 ++- 17 files changed, 125 insertions(+), 21 deletions(-) create mode 100644 test/bytecode_2.4/03_if_elif.pyc create mode 100644 test/bytecode_2.4/04_raise.pyc create mode 100644 test/bytecode_2.7/03_if_elif.pyc create mode 100644 test/bytecode_2.7/04_raise.pyc create mode 100644 test/bytecode_2.7/04_withas.pyc create mode 100644 uncompyle6/parsers/parse24.py create mode 100755 uncompyle6/scanners/scanner24.py diff --git a/__pkginfo__.py b/__pkginfo__.py index b7fb7c14..7edfb3dc 100644 --- a/__pkginfo__.py +++ b/__pkginfo__.py @@ -37,7 +37,7 @@ entry_points={ ]} ftp_url = None install_requires = ['spark-parser >= 1.4.0', - 'xdis >= 1.1.4'] + 'xdis >= 1.1.5'] license = 'MIT' mailing_list = 'python-debugger@googlegroups.com' modname = 'uncompyle6' diff --git a/test/Makefile b/test/Makefile index 5f45e985..08c26c93 100644 --- a/test/Makefile +++ b/test/Makefile @@ -43,7 +43,7 @@ check-disasm: #: Check deparsing bytecode 2.x only check-bytecode-2: - $(PYTHON) test_pythonlib.py --bytecode-2.3 --bytecode-2.5 --bytecode-2.6 --bytecode-2.7 + $(PYTHON) test_pythonlib.py --bytecode-2.3 --bytecode-2.4 --bytecode-2.5 --bytecode-2.6 --bytecode-2.7 #: Check deparsing bytecode 3.x only check-bytecode-3: @@ -57,6 +57,10 @@ check-bytecode: check-bytecode-3 check-bytecode-2.3: $(PYTHON) test_pythonlib.py --bytecode-2.3 +#: Check deparsing Python 2.4 +check-bytecode-2.4: + $(PYTHON) test_pythonlib.py --bytecode-2.4 + #: Check deparsing Python 2.5 check-bytecode-2.5: $(PYTHON) test_pythonlib.py --bytecode-2.5 diff --git a/test/add-test.py b/test/add-test.py index 09ed8211..3ee7d996 100755 --- a/test/add-test.py +++ b/test/add-test.py @@ -2,12 +2,12 @@ """ Trivial helper program to bytecompile and run an uncompile """ import os, sys, py_compile -assert len(sys.argv) == 2 -path = sys.argv[1] -short = os.path.basename(path) +assert len(sys.argv) >= 2 version = sys.version[0:3] -cfile = "bytecode_%s/%s" % (version, short) + 'c' -print("byte-compiling %s to %s" % (path, cfile)) -py_compile.compile(path, cfile) -if sys.version >= (2, 6, 0): - os.system("../bin/uncompyle6 -a -t %s" % cfile) +for path in sys.argv[1:]: + short = os.path.basename(path) + cfile = "bytecode_%s/%s" % (version, short) + 'c' + print("byte-compiling %s to %s" % (path, cfile)) + py_compile.compile(path, cfile) + if sys.version >= (2, 6, 0): + os.system("../bin/uncompyle6 -a -t %s" % cfile) diff --git a/test/bytecode_2.4/03_if_elif.pyc b/test/bytecode_2.4/03_if_elif.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e5e5511c6d6bca97e0681a32932046cb2e1fa006 GIT binary patch literal 266 zcmY*SJqyAx5WUk%iehmS$8MRd;15s-R~LtlL23$t=EEco4le#3|DC_UODTv4_ujpC zFFF00PnYj!-M~;tyr&K|fdsH6phU1Uq7m2(@W%f}gCr?O8#82Az2gcZ1jhj57+w@h z(JR22rz0nx5yqTA2y@X=h(WZfOCqh49}5}|AxIyUHAnBQ=j6Z-Vo5S6?dV;wci+e= hL>)u5*$UMP*{OEz9x+|rrC-B>fMJ0dGR!Be=P&#mFJS-x literal 0 HcmV?d00001 diff --git a/test/bytecode_2.4/04_raise.pyc b/test/bytecode_2.4/04_raise.pyc new file mode 100644 index 0000000000000000000000000000000000000000..70547e8db7a4985459ed795f59d8e0e312c71582 GIT binary patch literal 307 zcmYjL!43gI3~fnBB!rv9!5;U7gF7OQ95_f^Hfzjb!|rURm5^}3Pxwt=pj{#+d9Urf zzP9PBUYkF!YXjeh62}6n3+(_N02@gVR$)ngjOq$4rUL2+T>$bXAfq0*d|P zT2NcM*vH0hW3vx-&Qg#$4(ur*E(Ws>0QUKwPxGO0oX@0N~ zxuZ9>PnF$=;l5QQ(T77=w2ii1lnkiaFR2xyfnuZk9yAs9kREld%xIqvqhSmNFuJ9D65n&?mXo&JC` ztC-e>_hxqHy*Iaq^lrNU{nl`PitB`dDN_xw16XjQ;48o3iI%-UJ|7GmFm1R#0Y%+b z!JmRAnoph?_E|%r)TS!+PgZ+_S>q`)D~ps%8r?I!Bbq?gH=iN+aGJ{*s&ZzCgwNce zb?wp==)0iJ5Xlh^N8=)t7R^h$rbpIj@7hvRaXFiaQ3zC`9@H%6&n5pq{rVF<_Psh^ LcT4jYlO^~F@pMED literal 0 HcmV?d00001 diff --git a/test/bytecode_2.7/04_withas.pyc b/test/bytecode_2.7/04_withas.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4223a88589c4157101df963477bece2dd50aab41 GIT binary patch literal 294 zcma)0JqyAx6nyamw9>h&V<+q2C?dEQv_r*3N|I`^X-kt@3w3k%$NC3+uL`aP?sDYa zU0(lXTh8?sa`+yG_Zp#XBmwXMIG|t -# Copyright (c) 2000-2002 by hartmut Goebel -# Copyright (c) 1999 John Aycock """ Python 2.5 bytecode scanner/deparser @@ -10,7 +7,6 @@ Python 3 and other versions of Python. Also, we save token information for later use in deparsing. """ -from xdis.opcodes.opcode_25 import * import uncompyle6.scanners.scanner26 as scan import uncompyle6.scanners.scanner2 as scan2 diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index 06b0d406..18d631f6 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -961,8 +961,9 @@ class SourceWalker(GenericASTTraversal, object): n_import_as_cont = n_import_as def n_importfrom(self, node): - if node[0].pattr > 0: - node[2].pattr = '.'*node[0].pattr+node[2].pattr + relative_path_index = 0 + if self.version >= 2.5 and node[relative_path_index].pattr > 0: + node[2].pattr = '.'*node[relative_path_index].pattr + node[2].pattr self.default(node) n_importstar = n_importfrom