From 81633b3c1c3ae49120c755bd3ddfbc80ed452633 Mon Sep 17 00:00:00 2001 From: Bo Xuan Date: Tue, 23 Aug 2022 14:18:31 +0800 Subject: [PATCH 1/7] Fix offset of extended argument instruction --- uncompyle6/parsers/reducecheck/ifelsestmt.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/uncompyle6/parsers/reducecheck/ifelsestmt.py b/uncompyle6/parsers/reducecheck/ifelsestmt.py index 40f747c5..aa73e4eb 100644 --- a/uncompyle6/parsers/reducecheck/ifelsestmt.py +++ b/uncompyle6/parsers/reducecheck/ifelsestmt.py @@ -158,13 +158,15 @@ def ifelsestmt(self, lhs, n, rule, tree, tokens, first, last): # just the last one. if len(tree) == 5: end_come_froms = tree[-1] + offset = tokens[first].offset + offset = int(tokens[first].offset.split('_')[0]) if isinstance(offset, str) else offset if end_come_froms.kind != "else_suite" and self.version >= (3, 0): if end_come_froms == "opt_come_from_except" and len(end_come_froms) > 0: end_come_froms = end_come_froms[0] if not isinstance(end_come_froms, Token): if len(end_come_froms): - return tokens[first].offset > end_come_froms[-1].attr - elif tokens[first].offset > end_come_froms.attr: + return offset > end_come_froms[-1].attr + elif offset > end_come_froms.attr: return True # FIXME: There is weirdness in the grammar we need to work around. @@ -173,7 +175,7 @@ def ifelsestmt(self, lhs, n, rule, tree, tokens, first, last): last_token = tree[-1] else: last_token = tokens[last] - if last_token == "COME_FROM" and tokens[first].offset > last_token.attr: + if last_token == "COME_FROM" and offset > last_token.attr: if self.version < (3, 0) and self.insts[self.offset2inst_index[last_token.attr]].opname != "SETUP_LOOP": return True From 3cc51aa37f9540eccf8991ca50fe5207f2482a31 Mon Sep 17 00:00:00 2001 From: rocky Date: Tue, 23 Aug 2022 21:51:33 -0400 Subject: [PATCH 2/7] Reduce 2.6 excluded tests --- test/stdlib/2.6-exclude.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/stdlib/2.6-exclude.sh b/test/stdlib/2.6-exclude.sh index d9fe398f..2ec213f8 100644 --- a/test/stdlib/2.6-exclude.sh +++ b/test/stdlib/2.6-exclude.sh @@ -35,14 +35,14 @@ SKIP_TESTS=( [test_file.py]=1 # it fails on its own [test_future5.py]=1 # it fails on its own - # [test_generators.py]=1 # Investigate + # [test_generators.py]=1 # works but use PYTHON=pytest [test_gl.py]=1 # it fails on its own - [test_grp.py]=1 # Long test - might work Control flow? + # [test_grp.py]=1 # works but use PYTHON=pytest [test_imageop.py]=1 # it fails on its own [test_imaplib.py]=1 # it fails on its own [test_imgfile.py]=1 # it fails on its own - [test_ioctl.py]=1 # it fails on its own + # [test_ioctl.py]=1 # works but use PYTHON=pytest [test_kqueue.py]=1 # it fails on its own @@ -52,7 +52,7 @@ SKIP_TESTS=( [test_macostools.py]=1 # it fails on its own [test_mailbox.py]=1 # FIXME: release 3.6.2 may have worked - [test_normalization.py]=1 # it fails on its own + # [test_normalization.py]=1 # it fails on its own [test_ossaudiodev.py]=1 # it fails on its own From 2f3b5e53d4cd8ac893ab10f8e96957590dac1313 Mon Sep 17 00:00:00 2001 From: Bo Xuan Date: Wed, 24 Aug 2022 16:19:39 +0800 Subject: [PATCH 3/7] Add test case --- .../bytecode_3.7_run/10_extendedargifelse.pyc | Bin 0 -> 2777 bytes .../bug37/10_extendedargifelse.py | 264 ++++++++++++++++++ uncompyle6/parsers/reducecheck/ifelsestmt.py | 8 +- 3 files changed, 267 insertions(+), 5 deletions(-) create mode 100644 test/bytecode_3.7_run/10_extendedargifelse.pyc create mode 100644 test/simple_source/bug37/10_extendedargifelse.py diff --git a/test/bytecode_3.7_run/10_extendedargifelse.pyc b/test/bytecode_3.7_run/10_extendedargifelse.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5ec444e959208a8f6de11d5127d3472754750a51 GIT binary patch literal 2777 zcmeIyhnF2?8NlItXEy~%l#YcK#6SonAZkQ9D5zlQ#RUm>=KH2)TXwT)(wiU%u~IDb z-a(~FQF>9-2?NyRkcauqS)5H~X+J`>{V?p@#!FkgswO zvpARzDH(xCPC-dU&1`zdm%x3`$S;W^kghM%u!#RQ@If|n>hGRL7 zuX8*n@C{DnB)-YXoWf$h#kctm-{pIJpHn%F(>a45@I!vYk2#aGIGb}gm-9HE3%HPr zxR^`0l*_oBE4Y%YxSDIYmY?ube#UiN&kfwjP5hjjxrJM~jbHFfZs!i}!9`5Bn z?&kr1#jkmg-|$<0#}a%koJje6Az>B=Z%e=y?yvFOi!JE9r+o83%J^BQ2ZNGC(LfhxA#qHR&xO-@F zNP1fR-J#2Gy7y{L8MAEkDYEyn(PzlA#AW7&-9GmuolcWTTt=FtGtW7n1uSGylcb%VBu$+fsYa@iYNQ&eMyio&q#CJ4s*!4>8mUG)r%6(c zbQqm<1f5hT)k$^IMLkJom&`7iPNtLTWICBnrjzMpI+;$^+a#Gz*6-BGbTYeSI+;$U zlj&qSnNFsY>0~;=K0znw1f8H0bb?OM2|7V1=mh%&onW7!6Lf-3&a6Lq3au9NHJ zS(D^CxlXQ=>*PAQPOg*d0B& z*ry0iokFM3DRc^*LZ{FvbPD?vI)!}-ox(naPBGjhg-)SU*r(7bbc%&dQs|UArF}}B z(mth5sZ;8dWs{UTrB10+>XbUAPN`GslsctOX`fQ3)G2jJ_pQ_^bxNH|r_!n1w@Rnd zsWd9PR2r2=rBP{A?pbAiWqxITHRQY5mD!cql^rUxEBC50yEeNvyS77Zc5QZThuZww z{M!85{M!85{Mrt+9cqnQqt>YHP}`x_sdZ|dTBp{jb!z{cvpe{k%+8vwd7Yt)TSJpP z9p1UTHg&k_8|;mKh0n ey>Xk-N6hd9&zSD^|KIQDJ21BW?t6TDZ1O)K1g{4G literal 0 HcmV?d00001 diff --git a/test/simple_source/bug37/10_extendedargifelse.py b/test/simple_source/bug37/10_extendedargifelse.py new file mode 100644 index 00000000..15d5adc1 --- /dev/null +++ b/test/simple_source/bug37/10_extendedargifelse.py @@ -0,0 +1,264 @@ +aa = 0 +ab = 0 +ac = 0 +ad = 0 +ae = 0 +af = 0 +ag = 0 +ah = 0 +ai = 0 +aj = 0 +ak = 0 +al = 0 +am = 0 +an = 0 +ao = 0 +ap = 0 +aq = 0 +ar = 0 +at = 0 +au = 0 +av = 0 +aw = 0 +ax = 0 +ay = 0 +az = 0 +ba = 0 +bb = 0 +bc = 0 +bd = 0 +be = 0 +bf = 0 +bg = 0 +bh = 0 +bi = 0 +bj = 0 +bk = 0 +bl = 0 +bm = 0 +bn = 0 +bo = 0 +bp = 0 +bq = 0 +br = 0 +bs = 0 +bt = 0 +bu = 0 +bv = 0 +bw = 0 +bx = 0 +by = 0 +bz = 0 +ca = 0 +cb = 0 +cc = 0 +cd = 0 +ce = 0 +cf = 0 +cg = 0 +ch = 0 +ci = 0 +cj = 0 +ck = 0 +cl = 0 +cm = 0 +cn = 0 +co = 0 +cp = 0 +cq = 0 +cr = 0 +cs = 0 +ct = 0 +cu = 0 +cv = 0 +cw = 0 +cx = 0 +cy = 0 +cz = 0 +da = 0 +db = 0 +dc = 0 +dd = 0 +de = 0 +df = 0 +dg = 0 +dh = 0 +di = 0 +dj = 0 +dk = 0 +dl = 0 +dm = 0 +dn = 0 +do = 0 +dp = 0 +dq = 0 +dr = 0 +ds = 0 +dt = 0 +du = 0 +dv = 0 +dw = 0 +dx = 0 +dy = 0 +dz = 0 +ea = 0 +eb = 0 +ec = 0 +ed = 0 +ee = 0 +ef = 0 +eg = 0 +eh = 0 +ei = 0 +ej = 0 +ek = 0 +el = 0 +em = 0 +en = 0 +eo = 0 +ep = 0 +eq = 0 +er = 0 +es = 0 +et = 0 +eu = 0 +ev = 0 +ew = 0 +ex = 0 +ey = 0 +ez = 0 +fa = 0 +fb = 0 +fc = 0 +fd = 0 +fe = 0 +ff = 0 +fg = 0 +fh = 0 +fi = 0 +fj = 0 +fk = 0 +fl = 0 +fm = 0 +fn = 0 +fo = 0 +fp = 0 +fq = 0 +fr = 0 +fs = 0 +ft = 0 +fu = 0 +fv = 0 +fw = 0 +fx = 0 +fy = 0 +fz = 0 +ga = 0 +gb = 0 +gc = 0 +gd = 0 +ge = 0 +gf = 0 +gg = 0 +gh = 0 +gi = 0 +gj = 0 +gk = 0 +gl = 0 +gm = 0 +gn = 0 +go = 0 +gp = 0 +gq = 0 +gr = 0 +gs = 0 +gt = 0 +gu = 0 +gv = 0 +gw = 0 +gx = 0 +gy = 0 +gz = 0 +ha = 0 +hb = 0 +hc = 0 +hd = 0 +he = 0 +hf = 0 +hg = 0 +hh = 0 +hi = 0 +hj = 0 +hk = 0 +hl = 0 +hm = 0 +hn = 0 +ho = 0 +hp = 0 +hq = 0 +hr = 0 +hs = 0 +ht = 0 +hu = 0 +hv = 0 +hw = 0 +hx = 0 +hy = 0 +hz = 0 +ia = 0 +ib = 0 +ic = 0 +id = 0 +ie = 0 +ig = 0 +ih = 0 +ii = 0 +ij = 0 +ik = 0 +il = 0 +im = 0 +io = 0 +ip = 0 +iq = 0 +ir = 0 +it = 0 +iu = 0 +iv = 0 +iw = 0 +ix = 0 +iy = 0 +iz = 0 +ja = 0 +jb = 0 +jc = 0 +jd = 0 +je = 0 +jf = 0 +jg = 0 +jh = 0 +ji = 0 +jj = 0 +jk = 0 +jl = 0 +jm = 0 +jn = 0 +jo = 0 +jp = 0 +jq = 0 +jr = 0 +js = 0 +jt = 0 +ju = 0 +jv = 0 +jw = 0 +jx = 0 +jy = 0 +jz = 0 +ka = 0 +kb = 0 +kc = 0 +var = True +if var: + aa = 1 +else: + aa = 2 \ No newline at end of file diff --git a/uncompyle6/parsers/reducecheck/ifelsestmt.py b/uncompyle6/parsers/reducecheck/ifelsestmt.py index aa73e4eb..e0921b09 100644 --- a/uncompyle6/parsers/reducecheck/ifelsestmt.py +++ b/uncompyle6/parsers/reducecheck/ifelsestmt.py @@ -158,15 +158,13 @@ def ifelsestmt(self, lhs, n, rule, tree, tokens, first, last): # just the last one. if len(tree) == 5: end_come_froms = tree[-1] - offset = tokens[first].offset - offset = int(tokens[first].offset.split('_')[0]) if isinstance(offset, str) else offset if end_come_froms.kind != "else_suite" and self.version >= (3, 0): if end_come_froms == "opt_come_from_except" and len(end_come_froms) > 0: end_come_froms = end_come_froms[0] if not isinstance(end_come_froms, Token): if len(end_come_froms): - return offset > end_come_froms[-1].attr - elif offset > end_come_froms.attr: + return tokens[first].off2int() > end_come_froms[-1].attr + elif tokens[first].off2int() > end_come_froms.attr: return True # FIXME: There is weirdness in the grammar we need to work around. @@ -175,7 +173,7 @@ def ifelsestmt(self, lhs, n, rule, tree, tokens, first, last): last_token = tree[-1] else: last_token = tokens[last] - if last_token == "COME_FROM" and offset > last_token.attr: + if last_token == "COME_FROM" and tokens[first].off2int() > last_token.attr: if self.version < (3, 0) and self.insts[self.offset2inst_index[last_token.attr]].opname != "SETUP_LOOP": return True From 765b0149ea5d1dd87ab843f88383f0c182cb1783 Mon Sep 17 00:00:00 2001 From: rocky Date: Wed, 24 Aug 2022 05:26:26 -0400 Subject: [PATCH 4/7] iftstmt reduce rule for 2.6: In ifsmt there can be a JUMP_ABSOLUTE right before the endif and a jump the endif doesn't fall through to the place after the endif. --- uncompyle6/parsers/reducecheck/ifstmt2.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/uncompyle6/parsers/reducecheck/ifstmt2.py b/uncompyle6/parsers/reducecheck/ifstmt2.py index a8e616b9..3cf098a0 100644 --- a/uncompyle6/parsers/reducecheck/ifstmt2.py +++ b/uncompyle6/parsers/reducecheck/ifstmt2.py @@ -6,7 +6,6 @@ If statement reduction check for Python 2.6 (and older?) def ifstmt2(self, lhs, n, rule, ast, tokens, first, last): - # print("XXX", first, last) # for t in range(first, last): # print(tokens[t]) # print("=" * 30) @@ -61,16 +60,25 @@ def ifstmt2(self, lhs, n, rule, ast, tokens, first, last): if testexpr[0] in ("testtrue", "testfalse"): test = testexpr[0] - if len(test) > 1 and test[1].kind.startswith("jmp_"): - jmp_target = int(test[1][0].pattr) + jmp = test[1] + if len(test) > 1 and jmp.kind.startswith("jmp_"): + jmp_target = int(jmp[0].pattr) if last == len(tokens): last -= 1 + + if_end_offset = tokens[last].off2int(prefer_last=False) if ( tokens[first].off2int(prefer_last=True) <= jmp_target - < tokens[last].off2int(prefer_last=False) + < if_end_offset ): - return True + # In 2.6 (and before?) we need to check if the previous instruction + # is a jump to the last token. If so, testexpr is negated? and so + # jmp_target < if_end_offset. + previous_inst_index = self.offset2inst_index[jmp_target] - 1 + previous_inst = self.insts[previous_inst_index] + if previous_inst.opname != "JUMP_ABSOLUTE" and previous_inst.argval != if_end_offset: + return True # jmp_target less than tokens[first] is okay - is to a loop # jmp_target equal tokens[last] is also okay: normal non-optimized non-loop jump if jmp_target > tokens[last].off2int(): From 4260deea11d702f13cf51b3100611f123937c1ab Mon Sep 17 00:00:00 2001 From: rocky Date: Mon, 29 Aug 2022 05:29:57 -0400 Subject: [PATCH 5/7] Tidy ifelsemstmt check --- .../bytecode_3.7_run/10_extendedargifelse.pyc | Bin 2777 -> 2779 bytes .../bug37/10_extendedargifelse.py | 10 +++++++++- uncompyle6/parsers/reducecheck/ifelsestmt.py | 12 +++++++----- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/test/bytecode_3.7_run/10_extendedargifelse.pyc b/test/bytecode_3.7_run/10_extendedargifelse.pyc index 5ec444e959208a8f6de11d5127d3472754750a51..3dda1b31e325f4339ed13941fa4dcad10dfcd35c 100644 GIT binary patch delta 44 xcmca9dRvs&iIr=3`=D*nE-W598#MTmnoii~t9P3q$|_ delta 41 ucmcaDdQ+6wiIrE&%||Z3;vH diff --git a/test/simple_source/bug37/10_extendedargifelse.py b/test/simple_source/bug37/10_extendedargifelse.py index 15d5adc1..d8c95091 100644 --- a/test/simple_source/bug37/10_extendedargifelse.py +++ b/test/simple_source/bug37/10_extendedargifelse.py @@ -1,3 +1,10 @@ +# This is RUNNABLE! + +"""This program is self-checking!""" + +# Bug was handling if which has EXTENDED_ARG +# See https://github.com/rocky/python-uncompyle6/pull/406 + aa = 0 ab = 0 ac = 0 @@ -261,4 +268,5 @@ var = True if var: aa = 1 else: - aa = 2 \ No newline at end of file + aa = 2 +assert aa == 1 diff --git a/uncompyle6/parsers/reducecheck/ifelsestmt.py b/uncompyle6/parsers/reducecheck/ifelsestmt.py index e0921b09..133df853 100644 --- a/uncompyle6/parsers/reducecheck/ifelsestmt.py +++ b/uncompyle6/parsers/reducecheck/ifelsestmt.py @@ -136,6 +136,8 @@ def ifelsestmt(self, lhs, n, rule, tree, tokens, first, last): # print(tokens[t]) # print("=" * 30) + first_offset = tokens[first].off2int() + if rule not in IFELSE_STMT_RULES: # print("XXX", rule) return False @@ -151,7 +153,7 @@ def ifelsestmt(self, lhs, n, rule, tree, tokens, first, last): ): return True - # Make sure all of the "come froms" offset at the + # Make sure all the offsets from the "come froms" at the # end of the "if" come from somewhere inside the "if". # Since the come_froms are ordered so that lowest # offset COME_FROM is last, it is sufficient to test @@ -163,8 +165,8 @@ def ifelsestmt(self, lhs, n, rule, tree, tokens, first, last): end_come_froms = end_come_froms[0] if not isinstance(end_come_froms, Token): if len(end_come_froms): - return tokens[first].off2int() > end_come_froms[-1].attr - elif tokens[first].off2int() > end_come_froms.attr: + return first_offset > end_come_froms[-1].attr + elif first_offset > end_come_froms.attr: return True # FIXME: There is weirdness in the grammar we need to work around. @@ -173,7 +175,7 @@ def ifelsestmt(self, lhs, n, rule, tree, tokens, first, last): last_token = tree[-1] else: last_token = tokens[last] - if last_token == "COME_FROM" and tokens[first].off2int() > last_token.attr: + if last_token == "COME_FROM" and first_offset > last_token.attr: if self.version < (3, 0) and self.insts[self.offset2inst_index[last_token.attr]].opname != "SETUP_LOOP": return True @@ -237,7 +239,7 @@ def ifelsestmt(self, lhs, n, rule, tree, tokens, first, last): if jump_else_end[-1].off2int() != jmp_target: return True - if tokens[first].off2int() > jmp_target: + if first_offset > jmp_target: return True return (jmp_target > last_offset) and tokens[last] != "JUMP_FORWARD" From 4b2a2e218ab9f4e7e1b16ef9d280827c271e1da0 Mon Sep 17 00:00:00 2001 From: rocky Date: Fri, 16 Sep 2022 15:38:13 -0400 Subject: [PATCH 6/7] Misc lint stuff from pycharm... that has been applied to decompyle3 already --- requirements.txt | 5 +++++ setup.py | 7 +++---- uncompyle6/bin/pydisassemble.py | 2 +- uncompyle6/{disas.py => code_fns.py} | 0 uncompyle6/main.py | 2 +- uncompyle6/scanner.py | 4 ++-- uncompyle6/scanners/pypy37.py | 1 + uncompyle6/scanners/pypy38.py | 1 + uncompyle6/scanners/scanner37.py | 4 ++-- uncompyle6/scanners/scanner37base.py | 16 ++++++++++------ uncompyle6/scanners/scanner38.py | 4 ++-- uncompyle6/scanners/tok.py | 5 +++-- 12 files changed, 31 insertions(+), 20 deletions(-) rename uncompyle6/{disas.py => code_fns.py} (100%) diff --git a/requirements.txt b/requirements.txt index 5b1e7b65..40a86898 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,8 @@ hypothesis==2.0.0 pytest -e . + +Click~=7.0 +xdis>=6.0.4 +configobj~=5.0.6 +setuptools~=65.3.0 diff --git a/setup.py b/setup.py index c88e7362..05b1b788 100755 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +import setuptools import sys """Setup script for the 'uncompyle6' distribution.""" @@ -39,9 +40,7 @@ from __pkginfo__ import ( zip_safe, ) -from setuptools import setup, find_packages - -setup( +setuptools.setup( author=author, author_email=author_email, classifiers=classifiers, @@ -52,7 +51,7 @@ setup( long_description=long_description, long_description_content_type="text/x-rst", name=modname, - packages=find_packages(), + packages=setuptools.find_packages(), py_modules=py_modules, test_suite="nose.collector", url=web, diff --git a/uncompyle6/bin/pydisassemble.py b/uncompyle6/bin/pydisassemble.py index 9f43f7af..219158fc 100755 --- a/uncompyle6/bin/pydisassemble.py +++ b/uncompyle6/bin/pydisassemble.py @@ -6,7 +6,7 @@ from __future__ import print_function import sys, os, getopt -from uncompyle6.disas import disassemble_file +from uncompyle6.code_fns import disassemble_file from uncompyle6.version import __version__ program, ext = os.path.splitext(os.path.basename(__file__)) diff --git a/uncompyle6/disas.py b/uncompyle6/code_fns.py similarity index 100% rename from uncompyle6/disas.py rename to uncompyle6/code_fns.py diff --git a/uncompyle6/main.py b/uncompyle6/main.py index 1cdd2657..edf29096 100644 --- a/uncompyle6/main.py +++ b/uncompyle6/main.py @@ -18,7 +18,7 @@ import datetime, py_compile, os, sys from xdis import iscode from xdis.version_info import IS_PYPY, PYTHON_VERSION_TRIPLE, version_tuple_to_str -from uncompyle6.disas import check_object_path +from uncompyle6.code_fns import check_object_path from uncompyle6.semantics import pysource from uncompyle6.semantics.pysource import PARSER_DEFAULT_DEBUG from uncompyle6.parser import ParserError diff --git a/uncompyle6/scanner.py b/uncompyle6/scanner.py index d4fcfc4b..6452dae4 100644 --- a/uncompyle6/scanner.py +++ b/uncompyle6/scanner.py @@ -133,9 +133,9 @@ class Scanner(object): assert count <= i if collection_type == "CONST_DICT": - # constant dictonaries work via BUILD_CONST_KEY_MAP and + # constant dictionaries work via BUILD_CONST_KEY_MAP and # handle the values() like sets and lists. - # However the keys() are an LOAD_CONST of the keys. + # However, the keys() are an LOAD_CONST of the keys. # adjust offset to account for this count += 1 diff --git a/uncompyle6/scanners/pypy37.py b/uncompyle6/scanners/pypy37.py index 6856c839..eac8b2e3 100644 --- a/uncompyle6/scanners/pypy37.py +++ b/uncompyle6/scanners/pypy37.py @@ -13,6 +13,7 @@ from xdis.opcodes import opcode_37pypy as opc # is this right? JUMP_OPs = opc.JUMP_OPS + # We base this off of 3.7 class ScannerPyPy37(scan.Scanner37): def __init__(self, show_asm): diff --git a/uncompyle6/scanners/pypy38.py b/uncompyle6/scanners/pypy38.py index f32c1bbd..8f22e397 100644 --- a/uncompyle6/scanners/pypy38.py +++ b/uncompyle6/scanners/pypy38.py @@ -13,6 +13,7 @@ from xdis.opcodes import opcode_38pypy as opc JUMP_OPs = opc.JUMP_OPS + # We base this off of 3.8 class ScannerPyPy38(scan.Scanner38): def __init__(self, show_asm): diff --git a/uncompyle6/scanners/scanner37.py b/uncompyle6/scanners/scanner37.py index e88a8a78..99517ee9 100644 --- a/uncompyle6/scanners/scanner37.py +++ b/uncompyle6/scanners/scanner37.py @@ -120,7 +120,7 @@ class Scanner37(Scanner37Base): return new_tokens def ingest( - self, co, classname=None, code_objects={}, show_asm=None + self, bytecode, classname=None, code_objects={}, show_asm=None ) -> Tuple[list, dict]: """ Create "tokens" the bytecode of an Python code object. Largely these @@ -141,7 +141,7 @@ class Scanner37(Scanner37Base): cause specific rules for the specific number of arguments they take. """ tokens, customize = Scanner37Base.ingest( - self, co, classname, code_objects, show_asm + self, bytecode, classname, code_objects, show_asm ) new_tokens = [] for i, t in enumerate(tokens): diff --git a/uncompyle6/scanners/scanner37base.py b/uncompyle6/scanners/scanner37base.py index 5dc63519..1c6c499b 100644 --- a/uncompyle6/scanners/scanner37base.py +++ b/uncompyle6/scanners/scanner37base.py @@ -47,14 +47,18 @@ import sys globals().update(op3.opmap) +CONST_COLLECTIONS = ("CONST_LIST", "CONST_SET", "CONST_DICT") + + class Scanner37Base(Scanner): - def __init__(self, version: Tuple[int], show_asm=None, debug="", is_pypy=False): + def __init__(self, version: Tuple[int, int], show_asm=None, debug="", is_pypy=False): super(Scanner37Base, self).__init__(version, show_asm, is_pypy) + self.offset2tok_index = None self.debug = debug self.is_pypy = is_pypy # Create opcode classification sets - # Note: super initilization above initializes self.opc + # Note: super initialization above initializes self.opc # Ops that start SETUP_ ... We will COME_FROM with these names # Some blocks and END_ statements. And they can start @@ -139,7 +143,7 @@ class Scanner37Base(Scanner): self.opc.POP_JUMP_IF_FALSE, ] ) - # Not really a set, but still clasification-like + # Not really a set, but still classification-like self.statement_opcode_sequences = [ (self.opc.POP_JUMP_IF_FALSE, self.opc.JUMP_FORWARD), (self.opc.POP_JUMP_IF_FALSE, self.opc.JUMP_ABSOLUTE), @@ -274,7 +278,7 @@ class Scanner37Base(Scanner): if inst.opname == "JUMP_FORWARD": jump_inst = self.insts[self.offset2inst_index[inst.argval]] if jump_inst.has_extended_arg and jump_inst.opname.startswith("JUMP"): - # Create comination of the jump-to instruction and + # Create a combination of the jump-to instruction and # this one. Keep the position information of this instruction, # but the operator and operand properties come from the other # instruction @@ -442,9 +446,9 @@ class Scanner37Base(Scanner): elif op == self.opc.JUMP_ABSOLUTE: # Refine JUMP_ABSOLUTE further in into: # - # * "JUMP_LOOP" - which are are used in loops. This is sometimes + # * "JUMP_LOOP" - which are used in loops. This is sometimes # found at the end of a looping construct - # * "BREAK_LOOP" - which are are used to break loops. + # * "BREAK_LOOP" - which are used to break loops. # * "CONTINUE" - jumps which may appear in a "continue" statement. # It is okay to confuse this with JUMP_LOOP. The # grammar should tolerate this. diff --git a/uncompyle6/scanners/scanner38.py b/uncompyle6/scanners/scanner38.py index 765daf2b..98fb090d 100644 --- a/uncompyle6/scanners/scanner38.py +++ b/uncompyle6/scanners/scanner38.py @@ -44,7 +44,7 @@ class Scanner38(Scanner37): pass def ingest( - self, co, classname=None, code_objects={}, show_asm=None + self, bytecode, classname=None, code_objects={}, show_asm=None ) -> Tuple[list, dict]: """ Create "tokens" the bytecode of an Python code object. Largely these @@ -65,7 +65,7 @@ class Scanner38(Scanner37): cause specific rules for the specific number of arguments they take. """ tokens, customize = super(Scanner38, self).ingest( - co, classname, code_objects, show_asm + bytecode, classname, code_objects, show_asm ) # Hacky way to detect loop ranges. diff --git a/uncompyle6/scanners/tok.py b/uncompyle6/scanners/tok.py index f98b6306..def45346 100644 --- a/uncompyle6/scanners/tok.py +++ b/uncompyle6/scanners/tok.py @@ -15,7 +15,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import re, sys +import re +import sys intern = sys.intern @@ -87,7 +88,7 @@ class Token: print(f"I don't know about Python version {e} yet.") try: version_tuple = tuple(int(i) for i in str(e)[1:-1].split(".")) - except: + except Exception: pass else: if version_tuple > (3, 9): From 04df8a98fba7fd5a2abefa13b803a8047bc357d2 Mon Sep 17 00:00:00 2001 From: rocky Date: Fri, 16 Sep 2022 15:46:46 -0400 Subject: [PATCH 7/7] uncompyle6.disasm -> uncompyle6.code_fns --- pytest/test_disasm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytest/test_disasm.py b/pytest/test_disasm.py index 97ed847c..27f4ad36 100644 --- a/pytest/test_disasm.py +++ b/pytest/test_disasm.py @@ -1,7 +1,7 @@ import os.path import pytest -from uncompyle6.disas import disassemble_file +from uncompyle6.code_fns import disassemble_file def get_srcdir(): filename = os.path.normcase(os.path.dirname(__file__))