You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
Simpify an import, blacken a file.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
# Copyright (c) 2015-2016, 2818 by Rocky Bernstein
|
# Copyright (c) 2015-2016, 2818, 2020 by Rocky Bernstein
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -15,14 +15,21 @@
|
|||||||
|
|
||||||
from collections import deque
|
from collections import deque
|
||||||
|
|
||||||
from xdis import iscode
|
from xdis import Bytecode, iscode, findlinestarts, load_file, load_module
|
||||||
from xdis.load import load_file, load_module
|
|
||||||
from xdis.main import get_opcode
|
from xdis.main import get_opcode
|
||||||
from xdis.bytecode import Bytecode, findlinestarts, offset2line
|
from xdis.bytecode import offset2line
|
||||||
|
|
||||||
|
|
||||||
def line_number_mapping(pyc_filename, src_filename):
|
def line_number_mapping(pyc_filename, src_filename):
|
||||||
(version, timestamp, magic_int, code1, is_pypy,
|
(
|
||||||
source_size, sip_hash) = load_module(pyc_filename)
|
version,
|
||||||
|
timestamp,
|
||||||
|
magic_int,
|
||||||
|
code1,
|
||||||
|
is_pypy,
|
||||||
|
source_size,
|
||||||
|
sip_hash,
|
||||||
|
) = load_module(pyc_filename)
|
||||||
try:
|
try:
|
||||||
code2 = load_file(src_filename)
|
code2 = load_file(src_filename)
|
||||||
except SyntaxError as e:
|
except SyntaxError as e:
|
||||||
@@ -44,7 +51,10 @@ def number_loop(queue, mappings, opc):
|
|||||||
assert code1.co_name == code2.co_name
|
assert code1.co_name == code2.co_name
|
||||||
linestarts_orig = findlinestarts(code1)
|
linestarts_orig = findlinestarts(code1)
|
||||||
linestarts_uncompiled = list(findlinestarts(code2))
|
linestarts_uncompiled = list(findlinestarts(code2))
|
||||||
mappings += [[line, offset2line(offset, linestarts_uncompiled)] for offset, line in linestarts_orig]
|
mappings += [
|
||||||
|
[line, offset2line(offset, linestarts_uncompiled)]
|
||||||
|
for offset, line in linestarts_orig
|
||||||
|
]
|
||||||
bytecode1 = Bytecode(code1, opc)
|
bytecode1 = Bytecode(code1, opc)
|
||||||
bytecode2 = Bytecode(code2, opc)
|
bytecode2 = Bytecode(code2, opc)
|
||||||
instr2s = bytecode2.get_instructions(code2)
|
instr2s = bytecode2.get_instructions(code2)
|
||||||
|
Reference in New Issue
Block a user