-
-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #482 from rocky/sync-with-decompile3
Sync with decompile3
- Loading branch information
Showing
2 changed files
with
82 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright (c) 2016, 2018-2023 by Rocky Bernstein | ||
# Copyright (c) 2016, 2018-2024 by Rocky Bernstein | ||
# Copyright (c) 2005 by Dan Pascu <[email protected]> | ||
# Copyright (c) 2000-2002 by hartmut Goebel <[email protected]> | ||
# Copyright (c) 1999 John Aycock | ||
|
@@ -21,13 +21,11 @@ | |
scanners, e.g. for Python 2.7 or 3.4. | ||
""" | ||
|
||
from types import ModuleType | ||
from typing import Optional, Tuple, Union | ||
from array import array | ||
from collections import namedtuple | ||
from types import ModuleType | ||
from typing import Optional, Tuple, Union | ||
|
||
from uncompyle6.scanners.tok import Token | ||
from xdis.version_info import IS_PYPY, version_tuple_to_str | ||
import xdis | ||
from xdis import ( | ||
Bytecode, | ||
|
@@ -37,6 +35,9 @@ | |
instruction_size, | ||
next_offset, | ||
) | ||
from xdis.version_info import IS_PYPY, version_tuple_to_str | ||
|
||
from uncompyle6.scanners.tok import Token | ||
|
||
# The byte code versions we support. | ||
# Note: these all have to be tuples of 2 ints | ||
|
@@ -80,6 +81,7 @@ | |
# FIXME: DRY | ||
L65536 = 65536 | ||
|
||
|
||
def long(num): | ||
return num | ||
|
||
|
@@ -96,7 +98,6 @@ class Code(object): | |
""" | ||
|
||
def __init__(self, co, scanner, classname=None, show_asm=None): | ||
|
||
# Full initialization is given below, but for linters | ||
# well set up some initial values. | ||
self.co_code = None # Really either bytes for >= 3.0 and string in < 3.0 | ||
|
@@ -133,9 +134,7 @@ def __init__(self, version: tuple, show_asm=None, is_pypy=False): | |
# FIXME: This weird Python2 behavior is not Python3 | ||
self.resetTokenClass() | ||
|
||
def bound_collection_from_tokens( | ||
self, tokens, t, i, collection_type | ||
): | ||
def bound_collection_from_tokens(self, tokens, t, i, collection_type): | ||
count = t.attr | ||
assert isinstance(count, int) | ||
|
||
|
@@ -429,7 +428,7 @@ def inst_matches(self, start, end, instr, target=None, include_beyond_target=Fal | |
""" | ||
try: | ||
None in instr | ||
except: | ||
except Exception: | ||
instr = [instr] | ||
|
||
first = self.offset2inst_index[start] | ||
|
@@ -620,16 +619,14 @@ def parse_fn_counts_30_35(argc: int) -> Tuple[int, int, int]: | |
|
||
|
||
def get_scanner(version: Union[str, tuple], is_pypy=False, show_asm=None) -> Scanner: | ||
|
||
# If version is a string, turn that into the corresponding float. | ||
if isinstance(version, str): | ||
if version not in canonic_python_version: | ||
raise RuntimeError("Unknown Python version in xdis %s" % version) | ||
raise RuntimeError(f"Unknown Python version in xdis {version}") | ||
canonic_version = canonic_python_version[version] | ||
if canonic_version not in CANONIC2VERSION: | ||
raise RuntimeError( | ||
"Unsupported Python version %s (canonic %s)" | ||
% (version, canonic_version) | ||
f"Unsupported Python version {version} (canonic {canonic_version})" | ||
) | ||
version = CANONIC2VERSION[canonic_version] | ||
|
||
|
@@ -680,5 +677,6 @@ def get_scanner(version: Union[str, tuple], is_pypy=False, show_asm=None) -> Sca | |
# scanner = get_scanner('2.7.13', True) | ||
# scanner = get_scanner(sys.version[:5], False) | ||
from xdis.version_info import PYTHON_VERSION_TRIPLE | ||
|
||
scanner = get_scanner(PYTHON_VERSION_TRIPLE, IS_PYPY, True) | ||
tokens, customize = scanner.ingest(co, {}, show_asm="after") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters