You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
Merge pull request #364 from rocky/PYTHON3-move
use xdis.PYTHON3 not uncompyle.PYTHON3
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import pytest
|
from uncompyle6.semantics.fragments import code_deparse as deparse
|
||||||
from uncompyle6.semantics.fragments import code_deparse as deparse, deparsed_find
|
from xdis.version_info import PYTHON_VERSION, PYTHON3
|
||||||
from uncompyle6 import PYTHON_VERSION, PYTHON3
|
|
||||||
|
|
||||||
def map_stmts(x, y):
|
def map_stmts(x, y):
|
||||||
x = []
|
x = []
|
||||||
@@ -37,13 +36,11 @@ def check_expect(expect, parsed, fn_name):
|
|||||||
debug = False
|
debug = False
|
||||||
i = 2
|
i = 2
|
||||||
max_expect = len(expect)
|
max_expect = len(expect)
|
||||||
code = get_parsed_for_fn(fn_name)
|
|
||||||
for name, offset in sorted(parsed.offsets.keys()):
|
for name, offset in sorted(parsed.offsets.keys()):
|
||||||
assert i+1 <= max_expect, (
|
assert i+1 <= max_expect, (
|
||||||
"%s: ran out if items in testing node" % fn_name)
|
"%s: ran out if items in testing node" % fn_name)
|
||||||
nodeInfo = parsed.offsets[name, offset]
|
nodeInfo = parsed.offsets[name, offset]
|
||||||
node = nodeInfo.node
|
node = nodeInfo.node
|
||||||
nodeInfo2 = deparsed_find((name, offset), parsed, code)
|
|
||||||
extractInfo = parsed.extract_node_info(node)
|
extractInfo = parsed.extract_node_info(node)
|
||||||
|
|
||||||
assert expect[i] == extractInfo.selectedLine, \
|
assert expect[i] == extractInfo.selectedLine, \
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
import sys
|
import sys
|
||||||
from uncompyle6 import PYTHON3
|
|
||||||
from uncompyle6.scanner import get_scanner
|
from uncompyle6.scanner import get_scanner
|
||||||
from uncompyle6.semantics.consts import (
|
from uncompyle6.semantics.consts import (
|
||||||
escape, NONE,
|
escape, NONE,
|
||||||
# RETURN_NONE, PASS, RETURN_LOCALS
|
# RETURN_NONE, PASS, RETURN_LOCALS
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from xdis.version_info import PYTHON3
|
||||||
if PYTHON3:
|
if PYTHON3:
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
def iteritems(d):
|
def iteritems(d):
|
||||||
|
@@ -1,9 +1,10 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from uncompyle6 import PYTHON_VERSION, code_deparse
|
from uncompyle6 import code_deparse
|
||||||
pytestmark = pytest.mark.skip(PYTHON_VERSION < 2.7,
|
from xdis.version_info import PYTHON_VERSION_TRIPLE
|
||||||
|
pytestmark = pytest.mark.skip(PYTHON_VERSION_TRIPLE < (2, 7),
|
||||||
reason="need at least Python 2.7")
|
reason="need at least Python 2.7")
|
||||||
|
|
||||||
if PYTHON_VERSION > 2.6:
|
if PYTHON_VERSION_TRIPLE > (2, 6):
|
||||||
def test_single_mode():
|
def test_single_mode():
|
||||||
single_expressions = (
|
single_expressions = (
|
||||||
'i = 1',
|
'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"
|
@echo "Note that we do not support decompiling Python 3.10 bytecode - no 3.10 tests run"
|
||||||
|
|
||||||
# FIXME
|
# FIXME
|
||||||
#: this is called when running under pypy3.5-5.8.0, pypy2-5.6.0, or pypy3.6-7.3.0
|
#: 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:
|
5.8 5.6 7.3:
|
||||||
|
|
||||||
#: Check deparsing only, but from a different Python version
|
#: Check deparsing only, but from a different Python version
|
||||||
check-disasm:
|
check-disasm:
|
||||||
|
@@ -14,11 +14,11 @@ def a():
|
|||||||
def c():
|
def c():
|
||||||
k = 34
|
k = 34
|
||||||
global i
|
global i
|
||||||
i += k
|
i = i+k
|
||||||
l = 42
|
l = 42
|
||||||
c()
|
c()
|
||||||
global j
|
global j
|
||||||
j += l
|
j = j+l
|
||||||
b()
|
b()
|
||||||
print i, j # should print 35, 49
|
print i, j # should print 35, 49
|
||||||
|
|
||||||
|
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
def f():
|
def f():
|
||||||
print x # would result in a 'NameError' or 'UnboundLocalError'
|
print x # would result in a 'NameError' or 'UnboundLocalError'
|
||||||
x += 1
|
x = x+1
|
||||||
print x
|
print x
|
||||||
|
|
||||||
raise "This program can't be run"
|
raise "This program can't be run"
|
||||||
|
@@ -28,7 +28,7 @@ else:
|
|||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
while i < 10:
|
while i < 10:
|
||||||
i += 1
|
i = i+1
|
||||||
if i == 3:
|
if i == 3:
|
||||||
continue
|
continue
|
||||||
if i == 5:
|
if i == 5:
|
||||||
@@ -40,7 +40,7 @@ print
|
|||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
while i < 10:
|
while i < 10:
|
||||||
i += 1
|
i = i+1
|
||||||
if i == 3:
|
if i == 3:
|
||||||
continue
|
continue
|
||||||
print i,
|
print i,
|
||||||
|
@@ -55,9 +55,9 @@ class DBRecIO:
|
|||||||
if self.closed:
|
if self.closed:
|
||||||
raise ValueError, "I/O operation on closed file"
|
raise ValueError, "I/O operation on closed file"
|
||||||
if mode == 1:
|
if mode == 1:
|
||||||
pos += self.pos
|
pos = pos + self.pos
|
||||||
elif mode == 2:
|
elif mode == 2:
|
||||||
pos += self.len
|
pos = pos + self.len
|
||||||
self.pos = max(0, pos)
|
self.pos = max(0, pos)
|
||||||
|
|
||||||
def tell(self):
|
def tell(self):
|
||||||
@@ -84,7 +84,7 @@ class DBRecIO:
|
|||||||
if self.closed:
|
if self.closed:
|
||||||
raise ValueError, "I/O operation on closed file"
|
raise ValueError, "I/O operation on closed file"
|
||||||
if self.buflist:
|
if self.buflist:
|
||||||
self.buf += string.joinfields(self.buflist, '')
|
self.buf = self.buf + string.joinfields(self.buflist, '')
|
||||||
self.buflist = []
|
self.buflist = []
|
||||||
i = string.find(self.buf, '\n', self.pos)
|
i = string.find(self.buf, '\n', self.pos)
|
||||||
if i < 0:
|
if i < 0:
|
||||||
|
@@ -3,7 +3,7 @@ def flatten(tup):
|
|||||||
elts = []
|
elts = []
|
||||||
for elt in tup:
|
for elt in tup:
|
||||||
if isinstance(elt, tuple):
|
if isinstance(elt, tuple):
|
||||||
elts += flatten(elt)
|
elts = elts + flatten(elt)
|
||||||
else:
|
else:
|
||||||
elts.append(elt)
|
elts.append(elt)
|
||||||
return elts
|
return elts
|
||||||
@@ -53,7 +53,7 @@ def mangle(name, klass):
|
|||||||
try:
|
try:
|
||||||
i = 0
|
i = 0
|
||||||
while klass[i] == '_':
|
while klass[i] == '_':
|
||||||
i += 1
|
i = i + 1
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return name
|
return name
|
||||||
klass = klass[i:]
|
klass = klass[i:]
|
||||||
|
@@ -30,7 +30,7 @@ class SyntaxErrorChecker:
|
|||||||
self.errors = 0
|
self.errors = 0
|
||||||
|
|
||||||
def error(self, node, msg):
|
def error(self, node, msg):
|
||||||
self.errors += 1
|
self.errors = self.errors + 1
|
||||||
if self.multi is not None:
|
if self.multi is not None:
|
||||||
print "%s:%s: %s" % (node.filename, node.lineno, msg)
|
print "%s:%s: %s" % (node.filename, node.lineno, msg)
|
||||||
else:
|
else:
|
||||||
|
@@ -9,11 +9,11 @@ def normpath(comps):
|
|||||||
del comps[i]
|
del comps[i]
|
||||||
elif comps[i] == '..' and i > 0 and comps[i-1] not in ('', '..'):
|
elif comps[i] == '..' and i > 0 and comps[i-1] not in ('', '..'):
|
||||||
del comps[i-1:i+1]
|
del comps[i-1:i+1]
|
||||||
i -= 1
|
i = i - 1
|
||||||
elif comps[i] == '' and i > 0 and comps[i-1] != '':
|
elif comps[i] == '' and i > 0 and comps[i-1] != '':
|
||||||
del comps[i]
|
del comps[i]
|
||||||
else:
|
else:
|
||||||
i += 1
|
i = i + 1
|
||||||
return comps
|
return comps
|
||||||
|
|
||||||
assert normpath(['.']) == []
|
assert normpath(['.']) == []
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
# messing up control flow detection
|
# messing up control flow detection
|
||||||
def _format_usage(self, usage, actions, groups, prefix):
|
def _format_usage(self, usage, actions, groups, prefix):
|
||||||
if usage:
|
if usage:
|
||||||
usage %= dict(prog=self._prog)
|
usage = usage % dict(prog=self._prog)
|
||||||
|
|
||||||
elif usage is None:
|
elif usage is None:
|
||||||
prog = 5
|
prog = 5
|
||||||
|
@@ -31,9 +31,9 @@ from __future__ import print_function
|
|||||||
|
|
||||||
import getopt, os, py_compile, sys, shutil, tempfile, time
|
import getopt, os, py_compile, sys, shutil, tempfile, time
|
||||||
|
|
||||||
from uncompyle6 import PYTHON_VERSION
|
|
||||||
from uncompyle6.main import main
|
|
||||||
from fnmatch import fnmatch
|
from fnmatch import fnmatch
|
||||||
|
from uncompyle6.main import main
|
||||||
|
from xdis.version_info import PYTHON_VERSION
|
||||||
|
|
||||||
|
|
||||||
def get_srcdir():
|
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) 2000 by hartmut Goebel <h.goebel@crazy-compilers.com>
|
||||||
Copyright (c) 1999 John Aycock
|
Copyright (c) 1999 John Aycock
|
||||||
|
|
||||||
@@ -30,18 +30,7 @@ import sys
|
|||||||
|
|
||||||
__docformat__ = "restructuredtext"
|
__docformat__ = "restructuredtext"
|
||||||
|
|
||||||
from uncompyle6.version import __version__
|
from uncompyle6.version import __version__ # noqa
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
if hasattr(sys, "setrecursionlimit"):
|
if hasattr(sys, "setrecursionlimit"):
|
||||||
# pyston doesn't have setrecursionlimit
|
# pyston doesn't have setrecursionlimit
|
||||||
@@ -51,7 +40,7 @@ import uncompyle6.semantics.pysource
|
|||||||
import uncompyle6.semantics.fragments
|
import uncompyle6.semantics.fragments
|
||||||
|
|
||||||
# Export some functions
|
# Export some functions
|
||||||
from uncompyle6.main import decompile_file
|
from uncompyle6.main import decompile_file # noqa
|
||||||
|
|
||||||
# Convenience functions so you can say:
|
# Convenience functions so you can say:
|
||||||
# from uncompyle6 import (code_deparse, deparse_code2str)
|
# from uncompyle6 import (code_deparse, deparse_code2str)
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import sys
|
import sys
|
||||||
from uncompyle6 import PYTHON3
|
from xdis.version_info import PYTHON3
|
||||||
from uncompyle6.scanners.tok import NoneToken
|
from uncompyle6.scanners.tok import NoneToken
|
||||||
from spark_parser.ast import AST as spark_AST
|
from spark_parser.ast import AST as spark_AST
|
||||||
|
|
||||||
|
@@ -40,7 +40,7 @@ from copy import copy
|
|||||||
from xdis import code2num, iscode, op_has_argument, instruction_size
|
from xdis import code2num, iscode, op_has_argument, instruction_size
|
||||||
from xdis.bytecode import _get_const_info
|
from xdis.bytecode import _get_const_info
|
||||||
|
|
||||||
from uncompyle6 import PYTHON3
|
from xdis.version_info import PYTHON3
|
||||||
|
|
||||||
if PYTHON3:
|
if PYTHON3:
|
||||||
from sys import intern
|
from sys import intern
|
||||||
|
@@ -23,7 +23,7 @@ use in deparsing.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from uncompyle6 import PYTHON3
|
from xdis.version_info import PYTHON3
|
||||||
if PYTHON3:
|
if PYTHON3:
|
||||||
intern = sys.intern
|
intern = sys.intern
|
||||||
|
|
||||||
|
@@ -47,7 +47,7 @@ import xdis.opcodes.opcode_33 as op3
|
|||||||
from uncompyle6.scanner import Scanner
|
from uncompyle6.scanner import Scanner
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from uncompyle6 import PYTHON3
|
from xdis.version_info import PYTHON3
|
||||||
|
|
||||||
if PYTHON3:
|
if PYTHON3:
|
||||||
intern = sys.intern
|
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) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
|
||||||
# Copyright (c) 1999 John Aycock
|
# Copyright (c) 1999 John Aycock
|
||||||
#
|
#
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import re, sys
|
import re, sys
|
||||||
from uncompyle6 import PYTHON3
|
from xdis.version_info import PYTHON3
|
||||||
|
|
||||||
if PYTHON3:
|
if PYTHON3:
|
||||||
intern = sys.intern
|
intern = sys.intern
|
||||||
|
@@ -16,8 +16,8 @@
|
|||||||
|
|
||||||
import re, sys
|
import re, sys
|
||||||
from uncompyle6.parsers.treenode import SyntaxTree
|
from uncompyle6.parsers.treenode import SyntaxTree
|
||||||
from uncompyle6 import PYTHON3
|
|
||||||
from uncompyle6.scanners.tok import Token, NoneToken
|
from uncompyle6.scanners.tok import Token, NoneToken
|
||||||
|
from xdis.version_info import PYTHON3
|
||||||
|
|
||||||
if PYTHON3:
|
if PYTHON3:
|
||||||
minint = -sys.maxsize - 1
|
minint = -sys.maxsize - 1
|
||||||
|
@@ -3,7 +3,7 @@ import sys
|
|||||||
from xdis import iscode
|
from xdis import iscode
|
||||||
from uncompyle6.parsers.treenode import SyntaxTree
|
from uncompyle6.parsers.treenode import SyntaxTree
|
||||||
|
|
||||||
from uncompyle6 import PYTHON3
|
from xdis.version_info import PYTHON3
|
||||||
if PYTHON3:
|
if PYTHON3:
|
||||||
minint = -sys.maxsize-1
|
minint = -sys.maxsize-1
|
||||||
maxint = sys.maxsize
|
maxint = sys.maxsize
|
||||||
|
@@ -17,9 +17,7 @@
|
|||||||
All the crazy things we have to do to handle Python functions in Python before 3.0.
|
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.
|
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.scanner import Code
|
||||||
from uncompyle6 import PYTHON3
|
|
||||||
from uncompyle6.semantics.parser_error import ParserError
|
from uncompyle6.semantics.parser_error import ParserError
|
||||||
from uncompyle6.parser import ParserError as ParserError2
|
from uncompyle6.parser import ParserError as ParserError2
|
||||||
from uncompyle6.semantics.helper import (
|
from uncompyle6.semantics.helper import (
|
||||||
@@ -28,6 +26,8 @@ from uncompyle6.semantics.helper import (
|
|||||||
find_globals_and_nonlocals,
|
find_globals_and_nonlocals,
|
||||||
find_none,
|
find_none,
|
||||||
)
|
)
|
||||||
|
from xdis import iscode, code_has_star_arg, code_has_star_star_arg
|
||||||
|
from xdis.version_info import PYTHON3
|
||||||
|
|
||||||
if PYTHON3:
|
if PYTHON3:
|
||||||
from itertools import zip_longest
|
from itertools import zip_longest
|
||||||
|
@@ -24,16 +24,14 @@ from xdis import (
|
|||||||
CO_ASYNC_GENERATOR,
|
CO_ASYNC_GENERATOR,
|
||||||
)
|
)
|
||||||
from uncompyle6.scanner import Code
|
from uncompyle6.scanner import Code
|
||||||
from uncompyle6.parsers.treenode import SyntaxTree
|
|
||||||
from uncompyle6.semantics.parser_error import ParserError
|
from uncompyle6.semantics.parser_error import ParserError
|
||||||
from uncompyle6.parser import ParserError as ParserError2
|
from uncompyle6.parser import ParserError as ParserError2
|
||||||
from uncompyle6 import PYTHON3
|
|
||||||
from uncompyle6.semantics.helper import (
|
from uncompyle6.semantics.helper import (
|
||||||
print_docstring,
|
|
||||||
find_all_globals,
|
find_all_globals,
|
||||||
find_globals_and_nonlocals,
|
find_globals_and_nonlocals,
|
||||||
find_none,
|
find_none,
|
||||||
)
|
)
|
||||||
|
from xdis.version_info import PYTHON3
|
||||||
|
|
||||||
if PYTHON3:
|
if PYTHON3:
|
||||||
from itertools import zip_longest
|
from itertools import zip_longest
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
# More could be done here though.
|
# More could be done here though.
|
||||||
|
|
||||||
from math import copysign
|
from math import copysign
|
||||||
from uncompyle6 import PYTHON_VERSION
|
from xdis.version_info import PYTHON_VERSION
|
||||||
|
|
||||||
|
|
||||||
def is_negative_zero(n):
|
def is_negative_zero(n):
|
||||||
|
@@ -26,8 +26,8 @@ from subprocess import call
|
|||||||
|
|
||||||
import uncompyle6
|
import uncompyle6
|
||||||
from uncompyle6.scanner import Token as ScannerToken, get_scanner
|
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 import iscode, load_file, load_module, pretty_code_flags, PYTHON_MAGIC_INT
|
||||||
|
from xdis.version_info import PYTHON3
|
||||||
|
|
||||||
# FIXME: DRY
|
# FIXME: DRY
|
||||||
if PYTHON3:
|
if PYTHON3:
|
||||||
|
Reference in New Issue
Block a user