You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
DRY using version_info_to_str
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
from xdis.version_info import PYTHON_VERSION_TRIPLE, IS_PYPY
|
from xdis.version_info import PYTHON_VERSION_TRIPLE, IS_PYPY, version_tuple_to_str
|
||||||
from uncompyle6.scanner import get_scanner
|
from uncompyle6.scanner import get_scanner
|
||||||
def bug(state, slotstate):
|
def bug(state, slotstate):
|
||||||
if state:
|
if state:
|
||||||
@@ -62,6 +62,6 @@ def test_if_in_for():
|
|||||||
{'end': 59, 'type': 'for-loop', 'start': 31},
|
{'end': 59, 'type': 'for-loop', 'start': 31},
|
||||||
{'end': 63, 'type': 'for-else', 'start': 62}]
|
{'end': 63, 'type': 'for-else', 'start': 62}]
|
||||||
else:
|
else:
|
||||||
print("FIXME: should fix for %s" % ".".join([str(v) for v in PYTHON_VERSION_TRIPLE]))
|
print("FIXME: should fix for %s" % version_tuple_to_str())
|
||||||
assert True
|
assert True
|
||||||
return
|
return
|
||||||
|
@@ -29,12 +29,11 @@ Second, we need structured instruction information for the
|
|||||||
want to run on earlier Python versions.
|
want to run on earlier Python versions.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from collections import deque
|
from collections import deque
|
||||||
|
|
||||||
from xdis import check_object_path, iscode, load_module
|
from xdis import check_object_path, iscode, load_module
|
||||||
|
from xdis.version_info import version_tuple_to_str
|
||||||
from uncompyle6.scanner import get_scanner
|
from uncompyle6.scanner import get_scanner
|
||||||
|
|
||||||
|
|
||||||
@@ -47,7 +46,7 @@ def disco(version, co, out=None, is_pypy=False):
|
|||||||
|
|
||||||
# store final output stream for case of error
|
# store final output stream for case of error
|
||||||
real_out = out or sys.stdout
|
real_out = out or sys.stdout
|
||||||
print("# Python %s" % ".".join([str(v) for v in version]), file=real_out)
|
print("# Python %s" % version_tuple_to_str(version), file=real_out)
|
||||||
if co.co_filename:
|
if co.co_filename:
|
||||||
print("# Embedded file name: %s" % co.co_filename, file=real_out)
|
print("# Embedded file name: %s" % co.co_filename, file=real_out)
|
||||||
|
|
||||||
|
@@ -21,14 +21,12 @@ scanner/ingestion module. From here we call various version-specific
|
|||||||
scanners, e.g. for Python 2.7 or 3.4.
|
scanners, e.g. for Python 2.7 or 3.4.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from array import array
|
from array import array
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from uncompyle6 import PYTHON3, IS_PYPY
|
|
||||||
from uncompyle6.scanners.tok import Token
|
from uncompyle6.scanners.tok import Token
|
||||||
|
from xdis.version_info import PYTHON3, IS_PYPY, version_tuple_to_str
|
||||||
import xdis
|
import xdis
|
||||||
from xdis import Bytecode, canonic_python_version, code2num, instruction_size, extended_arg_val, next_offset
|
from xdis import Bytecode, canonic_python_version, code2num, instruction_size, extended_arg_val, next_offset
|
||||||
|
|
||||||
@@ -62,7 +60,7 @@ PYTHON_VERSIONS = frozenset(
|
|||||||
)
|
)
|
||||||
|
|
||||||
CANONIC2VERSION = dict(
|
CANONIC2VERSION = dict(
|
||||||
(canonic_python_version[".".join(str(v) for v in python_version)], python_version)
|
(canonic_python_version[version_tuple_to_str(python_version)], python_version)
|
||||||
for python_version in PYTHON_VERSIONS
|
for python_version in PYTHON_VERSIONS
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -113,7 +111,7 @@ class Scanner(object):
|
|||||||
exec("from xdis.opcodes import %s" % v_str)
|
exec("from xdis.opcodes import %s" % v_str)
|
||||||
exec("self.opc = %s" % v_str)
|
exec("self.opc = %s" % v_str)
|
||||||
else:
|
else:
|
||||||
raise TypeError("%s is not a Python version I know about" % ".".join([str(v) for v in version]))
|
raise TypeError("%s is not a Python version I know about" % version_tuple_to_str(version))
|
||||||
|
|
||||||
self.opname = self.opc.opname
|
self.opname = self.opc.opname
|
||||||
|
|
||||||
|
@@ -7,11 +7,9 @@ grammar parsing.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from uncompyle6.scanners.scanner2 import Scanner2
|
from uncompyle6.scanners.scanner2 import Scanner2
|
||||||
|
|
||||||
from uncompyle6 import PYTHON3
|
from xdis.version_info import PYTHON3, version_tuple_to_str
|
||||||
|
|
||||||
if PYTHON3:
|
if PYTHON3:
|
||||||
import sys
|
import sys
|
||||||
@@ -123,4 +121,4 @@ if __name__ == "__main__":
|
|||||||
print(t)
|
print(t)
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
print("Need to be Python 2.7 to demo; I am %s." % ".".join(str(v) for v in PYTHON_VERSION_TRIPLE))
|
print("Need to be Python 2.7 to demo; I am %s." % version_tuple_to_str())
|
||||||
|
Reference in New Issue
Block a user