Merge branch 'master' into python-3.3-to-3.5

This commit is contained in:
rocky
2024-03-02 05:07:05 -05:00
13 changed files with 340 additions and 287 deletions

View File

@@ -22,6 +22,7 @@ scanners, e.g. for Python 2.7 or 3.4.
"""
import sys
from abc import ABC
from array import array
from collections import namedtuple
@@ -89,7 +90,7 @@ def long(num):
CONST_COLLECTIONS = ("CONST_LIST", "CONST_SET", "CONST_DICT", "CONST_MAP")
class Code(object):
class Code:
"""
Class for representing code-objects.
@@ -108,7 +109,7 @@ class Code(object):
self._tokens, self._customize = scanner.ingest(co, classname, show_asm=show_asm)
class Scanner:
class Scanner(ABC):
def __init__(self, version: tuple, show_asm=None, is_pypy=False):
self.version = version
self.show_asm = show_asm
@@ -292,7 +293,13 @@ class Scanner:
return False
return offset < self.get_target(offset)
def prev_offset(self, offset):
def ingest(self, co, classname=None, code_objects={}, show_asm=None):
"""
Code to tokenize disassembly. Subclasses must implement this.
"""
raise NotImplementedError("This method should have been implemented")
def prev_offset(self, offset: int) -> int:
return self.insts[self.offset2inst_index[offset] - 1].offset
def get_inst(self, offset):