You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 08:49:51 +08:00
Merge branch 'master' into python-3.3-to-3.5
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import pytest
|
||||
# uncompyle6
|
||||
from uncompyle6 import PYTHON_VERSION
|
||||
from xdis.version_info import PYTHON_VERSION_TRIPLE, IS_PYPY
|
||||
from validate import validate_uncompyle
|
||||
|
||||
|
||||
@pytest.mark.skipif(PYTHON_VERSION < 3.6, reason='need at least python 3.6')
|
||||
@pytest.mark.skipif(PYTHON_VERSION_TRIPLE < (3, 6) or IS_PYPY, reason="need at least Python 3.6 and not PyPY")
|
||||
@pytest.mark.parametrize('text', (
|
||||
"{0.: 'a', -1: 'b'}", # BUILD_MAP
|
||||
"{'a':'b'}", # BUILD_MAP
|
||||
|
@@ -1,6 +1,5 @@
|
||||
import pytest
|
||||
from uncompyle6.semantics.fragments import code_deparse as deparse, deparsed_find
|
||||
from uncompyle6 import PYTHON_VERSION, PYTHON3
|
||||
from uncompyle6.semantics.fragments import code_deparse as deparse
|
||||
from xdis.version_info import PYTHON_VERSION, PYTHON3
|
||||
|
||||
def map_stmts(x, y):
|
||||
x = []
|
||||
@@ -37,13 +36,11 @@ def check_expect(expect, parsed, fn_name):
|
||||
debug = False
|
||||
i = 2
|
||||
max_expect = len(expect)
|
||||
code = get_parsed_for_fn(fn_name)
|
||||
for name, offset in sorted(parsed.offsets.keys()):
|
||||
assert i+1 <= max_expect, (
|
||||
"%s: ran out if items in testing node" % fn_name)
|
||||
nodeInfo = parsed.offsets[name, offset]
|
||||
node = nodeInfo.node
|
||||
nodeInfo2 = deparsed_find((name, offset), parsed, code)
|
||||
extractInfo = parsed.extract_node_info(node)
|
||||
|
||||
assert expect[i] == extractInfo.selectedLine, \
|
||||
|
@@ -1,11 +1,11 @@
|
||||
import sys
|
||||
from uncompyle6 import PYTHON3
|
||||
from uncompyle6.scanner import get_scanner
|
||||
from uncompyle6.semantics.consts import (
|
||||
escape, NONE,
|
||||
# RETURN_NONE, PASS, RETURN_LOCALS
|
||||
)
|
||||
|
||||
from xdis.version_info import PYTHON3
|
||||
if PYTHON3:
|
||||
from io import StringIO
|
||||
def iteritems(d):
|
||||
|
@@ -1,9 +1,10 @@
|
||||
import pytest
|
||||
from uncompyle6 import PYTHON_VERSION, code_deparse
|
||||
pytestmark = pytest.mark.skip(PYTHON_VERSION < 2.7,
|
||||
from uncompyle6 import code_deparse
|
||||
from xdis.version_info import PYTHON_VERSION_TRIPLE
|
||||
pytestmark = pytest.mark.skip(PYTHON_VERSION_TRIPLE < (2, 7),
|
||||
reason="need at least Python 2.7")
|
||||
|
||||
if PYTHON_VERSION > 2.6:
|
||||
if PYTHON_VERSION_TRIPLE > (2, 6):
|
||||
def test_single_mode():
|
||||
single_expressions = (
|
||||
'i = 1',
|
||||
|
@@ -84,8 +84,8 @@ check-3.10: check-bytecode
|
||||
@echo "Note that we do not support decompiling Python 3.10 bytecode - no 3.10 tests run"
|
||||
|
||||
# FIXME
|
||||
#: this is called when running under pypy3.5-5.8.0, pypy2-5.6.0, or pypy3.6-7.3.0
|
||||
5.8 5.6:
|
||||
#: this is called when running under pypy3.5-5.8.0, pypy2-5.6.0, pypy3.6-7.3.0 or pypy3.8-7.3.7
|
||||
5.8 5.6 7.3:
|
||||
|
||||
#: Check deparsing only, but from a different Python version
|
||||
check-disasm:
|
||||
|
@@ -31,9 +31,9 @@ from __future__ import print_function
|
||||
|
||||
import getopt, os, py_compile, sys, shutil, tempfile, time
|
||||
|
||||
from uncompyle6 import PYTHON_VERSION
|
||||
from uncompyle6.main import main
|
||||
from fnmatch import fnmatch
|
||||
from uncompyle6.main import main
|
||||
from xdis.version_info import PYTHON_VERSION
|
||||
|
||||
|
||||
def get_srcdir():
|
||||
|
@@ -1,5 +1,5 @@
|
||||
"""
|
||||
Copyright (c) 2015, 2018 by Rocky Bernstein
|
||||
Copyright (c) 2015, 2018, 2021 by Rocky Bernstein
|
||||
Copyright (c) 2000 by hartmut Goebel <h.goebel@crazy-compilers.com>
|
||||
Copyright (c) 1999 John Aycock
|
||||
|
||||
@@ -30,18 +30,7 @@ import sys
|
||||
|
||||
__docformat__ = "restructuredtext"
|
||||
|
||||
from uncompyle6.version import __version__
|
||||
|
||||
PYTHON3 = sys.version_info >= (3, 0)
|
||||
|
||||
# We do this crazy way to support Python 2.6 which
|
||||
# doesn't support version_major, and has a bug in
|
||||
# floating point so we can't divide 26 by 10 and get
|
||||
# 2.6
|
||||
PYTHON_VERSION = sys.version_info[0] + (sys.version_info[1] / 10.0)
|
||||
PYTHON_VERSION_STR = "%s.%s" % (sys.version_info[0], sys.version_info[1])
|
||||
|
||||
IS_PYPY = "__pypy__" in sys.builtin_module_names
|
||||
from uncompyle6.version import __version__ # noqa
|
||||
|
||||
if hasattr(sys, "setrecursionlimit"):
|
||||
# pyston doesn't have setrecursionlimit
|
||||
@@ -51,7 +40,7 @@ import uncompyle6.semantics.pysource
|
||||
import uncompyle6.semantics.fragments
|
||||
|
||||
# Export some functions
|
||||
from uncompyle6.main import decompile_file
|
||||
from uncompyle6.main import decompile_file # noqa
|
||||
|
||||
# Convenience functions so you can say:
|
||||
# from uncompyle6 import (code_deparse, deparse_code2str)
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import sys
|
||||
from uncompyle6 import PYTHON3
|
||||
from xdis.version_info import PYTHON3
|
||||
from uncompyle6.scanners.tok import NoneToken
|
||||
from spark_parser.ast import AST as spark_AST
|
||||
|
||||
|
24
uncompyle6/scanners/pypy37.py
Normal file
24
uncompyle6/scanners/pypy37.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# Copyright (c) 2021 by Rocky Bernstein
|
||||
"""
|
||||
Python PyPy 3.7 decompiler scanner.
|
||||
|
||||
Does some additional massaging of xdis-disassembled instructions to
|
||||
make things easier for decompilation.
|
||||
"""
|
||||
|
||||
import decompyle3.scanners.scanner3y as scan
|
||||
|
||||
# bytecode verification, verify(), uses JUMP_OPS from here
|
||||
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):
|
||||
# There are no differences in initialization between
|
||||
# pypy 3.7 and 3.7
|
||||
scan.Scanner37.__init__(self, show_asm, is_pypy=True)
|
||||
self.version = (3, 7)
|
||||
self.opc = opc
|
||||
return
|
24
uncompyle6/scanners/pypy38.py
Normal file
24
uncompyle6/scanners/pypy38.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# Copyright (c) 2021 by Rocky Bernstein
|
||||
"""
|
||||
Python PyPy 3.8 decompiler scanner.
|
||||
|
||||
Does some additional massaging of xdis-disassembled instructions to
|
||||
make things easier for decompilation.
|
||||
"""
|
||||
|
||||
import decompyle3.scanners.scanner38 as scan
|
||||
|
||||
# bytecode verification, verify(), uses JUMP_OPS from here
|
||||
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):
|
||||
# There are no differences in initialization between
|
||||
# pypy 3.8 and 3.8
|
||||
scan.Scanner38.__init__(self, show_asm, is_pypy=True)
|
||||
self.version = (3, 8)
|
||||
self.opc = opc
|
||||
return
|
@@ -40,7 +40,7 @@ from copy import copy
|
||||
from xdis import code2num, iscode, op_has_argument, instruction_size
|
||||
from xdis.bytecode import _get_const_info
|
||||
|
||||
from uncompyle6 import PYTHON3
|
||||
from xdis.version_info import PYTHON3
|
||||
|
||||
if PYTHON3:
|
||||
from sys import intern
|
||||
|
@@ -23,7 +23,7 @@ use in deparsing.
|
||||
"""
|
||||
|
||||
import sys
|
||||
from uncompyle6 import PYTHON3
|
||||
from xdis.version_info import PYTHON3
|
||||
if PYTHON3:
|
||||
intern = sys.intern
|
||||
|
||||
|
@@ -47,7 +47,7 @@ import xdis.opcodes.opcode_33 as op3
|
||||
from uncompyle6.scanner import Scanner
|
||||
|
||||
import sys
|
||||
from uncompyle6 import PYTHON3
|
||||
from xdis.version_info import PYTHON3
|
||||
|
||||
if PYTHON3:
|
||||
intern = sys.intern
|
||||
|
@@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2016-2020 by Rocky Bernstein
|
||||
# Copyright (c) 2016-2021 by Rocky Bernstein
|
||||
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
|
||||
# Copyright (c) 1999 John Aycock
|
||||
#
|
||||
@@ -16,7 +16,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import re, sys
|
||||
from uncompyle6 import PYTHON3
|
||||
from xdis.version_info import PYTHON3
|
||||
|
||||
if PYTHON3:
|
||||
intern = sys.intern
|
||||
|
@@ -16,8 +16,8 @@
|
||||
|
||||
import re, sys
|
||||
from uncompyle6.parsers.treenode import SyntaxTree
|
||||
from uncompyle6 import PYTHON3
|
||||
from uncompyle6.scanners.tok import Token, NoneToken
|
||||
from xdis.version_info import PYTHON3
|
||||
|
||||
if PYTHON3:
|
||||
minint = -sys.maxsize - 1
|
||||
|
@@ -3,7 +3,7 @@ import sys
|
||||
from xdis import iscode
|
||||
from uncompyle6.parsers.treenode import SyntaxTree
|
||||
|
||||
from uncompyle6 import PYTHON3
|
||||
from xdis.version_info import PYTHON3
|
||||
if PYTHON3:
|
||||
minint = -sys.maxsize-1
|
||||
maxint = sys.maxsize
|
||||
|
@@ -17,9 +17,7 @@
|
||||
All the crazy things we have to do to handle Python functions in Python before 3.0.
|
||||
The saga of changes continues in 3.0 and above and in other files.
|
||||
"""
|
||||
from xdis import iscode, code_has_star_arg, code_has_star_star_arg
|
||||
from uncompyle6.scanner import Code
|
||||
from uncompyle6 import PYTHON3
|
||||
from uncompyle6.semantics.parser_error import ParserError
|
||||
from uncompyle6.parser import ParserError as ParserError2
|
||||
from uncompyle6.semantics.helper import (
|
||||
@@ -28,6 +26,8 @@ from uncompyle6.semantics.helper import (
|
||||
find_globals_and_nonlocals,
|
||||
find_none,
|
||||
)
|
||||
from xdis import iscode, code_has_star_arg, code_has_star_star_arg
|
||||
from xdis.version_info import PYTHON3
|
||||
|
||||
if PYTHON3:
|
||||
from itertools import zip_longest
|
||||
|
@@ -24,16 +24,14 @@ from xdis import (
|
||||
CO_ASYNC_GENERATOR,
|
||||
)
|
||||
from uncompyle6.scanner import Code
|
||||
from uncompyle6.parsers.treenode import SyntaxTree
|
||||
from uncompyle6.semantics.parser_error import ParserError
|
||||
from uncompyle6.parser import ParserError as ParserError2
|
||||
from uncompyle6 import PYTHON3
|
||||
from uncompyle6.semantics.helper import (
|
||||
print_docstring,
|
||||
find_all_globals,
|
||||
find_globals_and_nonlocals,
|
||||
find_none,
|
||||
)
|
||||
from xdis.version_info import PYTHON3
|
||||
|
||||
if PYTHON3:
|
||||
from itertools import zip_longest
|
||||
|
@@ -3,7 +3,7 @@
|
||||
# More could be done here though.
|
||||
|
||||
from math import copysign
|
||||
from uncompyle6 import PYTHON_VERSION
|
||||
from xdis.version_info import PYTHON_VERSION
|
||||
|
||||
|
||||
def is_negative_zero(n):
|
||||
|
@@ -26,8 +26,8 @@ from subprocess import call
|
||||
|
||||
import uncompyle6
|
||||
from uncompyle6.scanner import Token as ScannerToken, get_scanner
|
||||
from uncompyle6 import PYTHON3
|
||||
from xdis import iscode, load_file, load_module, pretty_code_flags, PYTHON_MAGIC_INT
|
||||
from xdis.version_info import PYTHON3
|
||||
|
||||
# FIXME: DRY
|
||||
if PYTHON3:
|
||||
|
Reference in New Issue
Block a user