You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-02 16:44:46 +08:00
New feature: show line number correspondences
Option --linemap on uncompile show how original source-code line numbers map to uncompiled source lines
This commit is contained in:
14
uncompyle6/linenumbers.py
Normal file
14
uncompyle6/linenumbers.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from xdis.load import load_file, load_module
|
||||
from xdis.bytecode import findlinestarts, offset2line
|
||||
|
||||
def line_number_mapping(pyc_filename, src_filename):
|
||||
(version, timestamp, magic_int, code_obj1, is_pypy,
|
||||
source_size) = load_module(pyc_filename)
|
||||
try:
|
||||
code_obj2 = load_file(src_filename)
|
||||
except SyntaxError as e:
|
||||
return str(e)
|
||||
|
||||
linestarts_orig = findlinestarts(code_obj1)
|
||||
linestarts_uncompiled = list(findlinestarts(code_obj2))
|
||||
return [[line, offset2line(offset, linestarts_uncompiled)] for offset, line in linestarts_orig]
|
Reference in New Issue
Block a user