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
from numbers import Integral | |
class Flag(int): | |
def __new__(cls, value: int, parent_cls: type = None): | |
flag = super().__new__(cls, value) | |
if parent_cls is None: | |
parent_cls = cls |
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
import ctypes | |
def size_of(obj): | |
cls = type(obj) | |
return cls.__sizeof__(obj) | |
def mem_replace(target, source): | |
target_size = size_of(target) |
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
import dis | |
from types import CodeType | |
def _patch_code(code: CodeType, **kwargs): | |
"""Create a new CodeType object with modified attributes.""" | |
code_attrs = {} | |
# Collect the original CodeType attributes |