You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-02 16:44:46 +08:00
2.6 custom tryelse code is no longer needed?
If it turns out to be needed, add it back in a better way.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# emacs-mode: -*-python-*-
|
# emacs-mode: -*-python-*-
|
||||||
"""
|
"""
|
||||||
test_pyenvlib -- uncompyle and verify Python libraries
|
test_pyenvlib -- decompile and verify Python libraries
|
||||||
|
|
||||||
Usage-Examples:
|
Usage-Examples:
|
||||||
|
|
||||||
@@ -22,12 +22,17 @@ Step 2: Run the test:
|
|||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import os, time, re, shutil, sys
|
import os
|
||||||
|
import re
|
||||||
|
import shutil
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
from fnmatch import fnmatch
|
from fnmatch import fnmatch
|
||||||
|
|
||||||
from uncompyle6 import main
|
|
||||||
import xdis.magics as magics
|
import xdis.magics as magics
|
||||||
|
|
||||||
|
from uncompyle6 import main
|
||||||
|
|
||||||
# ----- configure this for your needs
|
# ----- configure this for your needs
|
||||||
|
|
||||||
python_versions = [v for v in magics.python_versions if re.match("^[0-9.]+$", v)]
|
python_versions = [v for v in magics.python_versions if re.match("^[0-9.]+$", v)]
|
||||||
@@ -82,6 +87,7 @@ for vers in TEST_VERSIONS:
|
|||||||
if vers == "native":
|
if vers == "native":
|
||||||
short_vers = os.path.basename(sys.path[-1])
|
short_vers = os.path.basename(sys.path[-1])
|
||||||
from xdis.version_info import PYTHON_VERSION_TRIPLE, version_tuple_to_str
|
from xdis.version_info import PYTHON_VERSION_TRIPLE, version_tuple_to_str
|
||||||
|
|
||||||
if PYTHON_VERSION_TRIPLE > (3, 0):
|
if PYTHON_VERSION_TRIPLE > (3, 0):
|
||||||
version = version_tuple_to_str(end=2)
|
version = version_tuple_to_str(end=2)
|
||||||
PYC = f"*.cpython-{version}.pyc"
|
PYC = f"*.cpython-{version}.pyc"
|
||||||
@@ -133,8 +139,17 @@ def do_tests(
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
if len(files) > max_files:
|
if len(files) > max_files:
|
||||||
files = [file for file in files if not "site-packages" in file and (file.endswith(".pyo") or file.endswith(".pyc"))]
|
files = [
|
||||||
files = [file for file in files if not "test" in file and (file.endswith(".pyo") or file.endswith(".pyc"))]
|
file
|
||||||
|
for file in files
|
||||||
|
if not "site-packages" in file
|
||||||
|
and (file.endswith(".pyo") or file.endswith(".pyc"))
|
||||||
|
]
|
||||||
|
files = [
|
||||||
|
file
|
||||||
|
for file in files
|
||||||
|
if not "test" in file and (file.endswith(".pyo") or file.endswith(".pyc"))
|
||||||
|
]
|
||||||
if len(files) > max_files:
|
if len(files) > max_files:
|
||||||
# print("Number of files %d - truncating to last 200" % len(files))
|
# print("Number of files %d - truncating to last 200" % len(files))
|
||||||
print(
|
print(
|
||||||
@@ -151,7 +166,8 @@ def do_tests(
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import getopt, sys
|
import getopt
|
||||||
|
import sys
|
||||||
|
|
||||||
do_coverage = do_verify = False
|
do_coverage = do_verify = False
|
||||||
test_dirs = []
|
test_dirs = []
|
||||||
|
@@ -493,51 +493,6 @@ class Python26Parser(Python2Parser):
|
|||||||
return tokens[last - 3].kind not in frozenset(
|
return tokens[last - 3].kind not in frozenset(
|
||||||
("JUMP_FORWARD", "RETURN_VALUE")
|
("JUMP_FORWARD", "RETURN_VALUE")
|
||||||
) or (tokens[last - 3] == "JUMP_FORWARD" and tokens[last - 3].attr != 2)
|
) or (tokens[last - 3] == "JUMP_FORWARD" and tokens[last - 3].attr != 2)
|
||||||
elif lhs == "tryelsestmt":
|
|
||||||
# We need to distinguish "try_except" from "tryelsestmt"; we do that
|
|
||||||
# by making sure that the jump before the except handler jumps to
|
|
||||||
# code somewhere before the end of the construct.
|
|
||||||
# This AST method is slower, but the token-only based approach
|
|
||||||
# didn't work as it failed with a "try" embedded inside a "try/else"
|
|
||||||
# since we can't detect COME_FROM boundaries.
|
|
||||||
|
|
||||||
if ast[3] == "except_handler":
|
|
||||||
except_handler = ast[3]
|
|
||||||
if except_handler[0] == "JUMP_FORWARD":
|
|
||||||
else_start = int(except_handler[0].pattr)
|
|
||||||
if last == len(tokens):
|
|
||||||
last -= 1
|
|
||||||
if tokens[last] == "COME_FROM" and isinstance:
|
|
||||||
last_offset = int(tokens[last].offset.split("_")[0])
|
|
||||||
return else_start >= last_offset
|
|
||||||
|
|
||||||
# The above test apparently isn't good enough, so we have additional
|
|
||||||
# checks distinguish "try_except" from "tryelsestmt". we do that
|
|
||||||
# by checking the jump before the "END_FINALLY".
|
|
||||||
# If we have:
|
|
||||||
# insn
|
|
||||||
# POP_TOP
|
|
||||||
# END_FINALLY
|
|
||||||
# COME_FROM
|
|
||||||
# then insn is neither a JUMP_FORWARD nor RETURN_VALUE,
|
|
||||||
# or if it is JUMP_FORWARD, then it can't be a JUMP_FORWARD to right after
|
|
||||||
# COME_FROM
|
|
||||||
if last == len(tokens):
|
|
||||||
last -= 1
|
|
||||||
while tokens[last - 1] == "COME_FROM" and tokens[last - 2] == "COME_FROM":
|
|
||||||
last -= 1
|
|
||||||
if tokens[last] == "COME_FROM" and tokens[last - 1] == "COME_FROM":
|
|
||||||
last -= 1
|
|
||||||
if (
|
|
||||||
tokens[last] == "COME_FROM"
|
|
||||||
and tokens[last - 1] == "END_FINALLY"
|
|
||||||
and tokens[last - 2] == "POP_TOP"
|
|
||||||
):
|
|
||||||
# A jump of 2 is a jump around POP_TOP, END_FINALLY which
|
|
||||||
# would indicate try/else rather than try
|
|
||||||
return tokens[last - 3].kind in frozenset(
|
|
||||||
("JUMP_FORWARD", "RETURN_VALUE")
|
|
||||||
) and (tokens[last - 3] != "JUMP_FORWARD" or tokens[last - 3].attr == 2)
|
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user