def test_load(): """Basic test of load_file, check_object_path and load_module""" co = load_file(__file__) obj_path = check_object_path(__file__) version, timestamp, magic_int, co2 = load_module(obj_path) assert sys.version[0:3] == str(version) assert co == co2
def uncompyle_file(filename, outstream=None, showasm=False, showast=False, showgrammar=False): """ decompile Python byte-code file (.pyc) """ filename = check_object_path(filename) code_objects = {} version, timestamp, magic_int, co = load_module(filename, code_objects) if type(co) == list: for con in co: uncompyle(version, con, outstream, showasm, showast, timestamp, showgrammar, code_objects=code_objects) else: uncompyle(version, co, outstream, showasm, showast, timestamp, showgrammar, code_objects=code_objects) co = None
def compare_code_with_srcfile(pyc_filename, src_filename): """Compare a .pyc with a source code file.""" version, timestamp, magic_int, code_obj1 = load_module(pyc_filename) if magic_int != PYTHON_MAGIC_INT: msg = ("Can't compare code - Python is running with magic %s, but code is magic %s " % (PYTHON_MAGIC_INT, magic_int)) return msg code_obj2 = load_file(src_filename) cmp_code_objects(version, code_obj1, code_obj2) return None
def disassemble_file(filename, outstream=None): """ disassemble Python byte-code file (.pyc) If given a Python source file (".py") file, we'll try to find the corresponding compiled object. """ filename = check_object_path(filename) version, timestamp, magic_int, co = load_module(filename) if type(co) == list: for con in co: disco(version, con, outstream) else: disco(version, co, outstream) co = None