Allow version to be string...

in get_python_parser and get_scanner
This commit is contained in:
rocky
2017-08-13 09:23:27 -04:00
parent 783e62f3ca
commit 93f18e2449
6 changed files with 67 additions and 2 deletions

View File

@@ -1,3 +1,12 @@
2017-08-10 rocky <rb@dustyfeet.com>
* : commit c38dc61021368f11e95cef70ee77e4a43dba1598 Author: rocky
<rb@dustyfeet.com> Date: Wed Aug 9 22:01:59 2017 -0400
2017-08-09 rocky <rb@dustyfeet.com>
* ChangeLog: Get ready for release 2.11.3
2017-08-09 rocky <rb@dustyfeet.com>
* : commit dc627d13b8455ded4bf708a596bb466f9df9bf7b Author: rocky
@@ -26,6 +35,15 @@
* __pkginfo__.py: Remove six from Python-2.4/2.5 package
2017-08-02 rocky <rb@dustyfeet.com>
* uncompyle6/scanners/scanner3.py: in xdis "exception match" is now
"exception-match"
2017-08-02 rocky <rb@dustyfeet.com>
* __pkginfo__.py: Python 2.4 doesn't do six
2017-08-01 rocky <rb@dustyfeet.com>
* pytest/validate.py, test/dis-compare.py,

View File

@@ -176,7 +176,7 @@ See Also
* https://github.com/rocky/python-xasm : Cross Python version assembler
.. _trepan: https://pypi.python.org/pypi/trepan
.. _trepan: https://pypi.python.org/pypi/trepan2
.. _HISTORY: https://github.com/rocky/python-uncompyle6/blob/master/HISTORY.md
.. _debuggers: https://pypi.python.org/pypi/trepan3k
.. _remake: https://bashdb.sf.net/remake

View File

@@ -40,7 +40,7 @@ entry_points = {
]}
ftp_url = None
install_requires = ['spark-parser >= 1.6.1, < 1.7.0',
'xdis == 3.5.1, < 3.6.0']
'xdis == 3.5.1']
license = 'MIT'
mailing_list = 'python-debugger@googlegroups.com'
modname = 'uncompyle6'

11
pytest/test_basic.py Normal file
View File

@@ -0,0 +1,11 @@
from uncompyle6.scanner import get_scanner
from uncompyle6.parser import get_python_parser
def test_get_scanner():
# See that we can retrieve a scanner using a full version number
assert get_scanner('2.7.13')
def test_get_parser():
# See that we can retrieve a sparser using a full version number
assert get_python_parser('2.7.13')

View File

@@ -12,6 +12,9 @@ from xdis.code import iscode
from spark_parser import GenericASTBuilder, DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
from uncompyle6.show import maybe_show_asm
# FIXME: put in xdis
from uncompyle6.scanner import version_str2float
class ParserError(Exception):
def __init__(self, token, offset):
@@ -609,7 +612,15 @@ def get_python_parser(
explanation of the different modes.
"""
# If version is a string, turn that into the corresponding float.
if isinstance(version, str):
version = version_str2float(version)
# FIXME: there has to be a better way...
# We could do this as a table lookup, but that would force us
# in import all of the parsers all of the time. Perhaps there is
# a lazy way of doing the import?
if version < 3.0:
if version == 1.5:
import uncompyle6.parsers.parse15 as parse15
@@ -762,6 +773,7 @@ def python_parser(version, co, out=sys.stdout, showasm=False,
if __name__ == '__main__':
def parse_test(co):
from uncompyle6 import PYTHON_VERSION, IS_PYPY
ast = python_parser('2.7.13', co, showasm=True, is_pypy=True)
ast = python_parser(PYTHON_VERSION, co, showasm=True, is_pypy=IS_PYPY)
print(ast)
return

View File

@@ -255,7 +255,30 @@ class Scanner(object):
def parse_fn_counts(argc):
return ((argc & 0xFF), (argc >> 8) & 0xFF, (argc >> 16) & 0x7FFF)
# FIXME: put in xdis
from xdis.magics import magics
def version_str2float(version):
if version in magics:
magic = magics[version]
for v, m in list(magics.items()):
if m == magic:
try:
return float(v)
except:
pass
pass
pass
raise RuntimeError("Can't find a valid Python version for version %s"
% version)
return
def get_scanner(version, is_pypy=False, show_asm=None):
# If version is a string, turn that into the corresponding float.
if isinstance(version, str):
version = version_str2float(version)
# Pick up appropriate scanner
if version in PYTHON_VERSIONS:
v_str = "%s" % (int(version * 10))
@@ -282,5 +305,6 @@ def get_scanner(version, is_pypy=False, show_asm=None):
if __name__ == "__main__":
import inspect, uncompyle6
co = inspect.currentframe().f_code
scanner = get_scanner('2.7.13', True)
scanner = get_scanner(uncompyle6.PYTHON_VERSION, IS_PYPY, True)
tokens, customize = scanner.ingest(co, {})