You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
Bugs in 2.x relative import '.' and 1.x bytecode
This commit is contained in:
@@ -229,6 +229,8 @@ class Scanner(object):
|
|||||||
# Locally we use list for more convenient iteration using indices
|
# Locally we use list for more convenient iteration using indices
|
||||||
linestarts = list(self.opc.findlinestarts(code_obj))
|
linestarts = list(self.opc.findlinestarts(code_obj))
|
||||||
self.linestarts = dict(linestarts)
|
self.linestarts = dict(linestarts)
|
||||||
|
if not self.linestarts:
|
||||||
|
return []
|
||||||
|
|
||||||
# 'List-map' which shows line number of current op and offset of
|
# 'List-map' which shows line number of current op and offset of
|
||||||
# first op on following line, given offset of op as index
|
# first op on following line, given offset of op as index
|
||||||
|
@@ -522,7 +522,7 @@ class Scanner2(Scanner):
|
|||||||
for s in stmt_list:
|
for s in stmt_list:
|
||||||
if code[s] == self.opc.JUMP_ABSOLUTE and s not in pass_stmts:
|
if code[s] == self.opc.JUMP_ABSOLUTE and s not in pass_stmts:
|
||||||
target = self.get_target(s)
|
target = self.get_target(s)
|
||||||
if target > s or self.lines[last_stmt].l_no == self.lines[s].l_no:
|
if target > s or (self.lines and self.lines[last_stmt].l_no == self.lines[s].l_no):
|
||||||
stmts.remove(s)
|
stmts.remove(s)
|
||||||
continue
|
continue
|
||||||
j = self.prev[s]
|
j = self.prev[s]
|
||||||
@@ -623,6 +623,7 @@ class Scanner2(Scanner):
|
|||||||
parent = self.structs[0]
|
parent = self.structs[0]
|
||||||
start = parent["start"]
|
start = parent["start"]
|
||||||
end = parent["end"]
|
end = parent["end"]
|
||||||
|
next_line_byte = end
|
||||||
|
|
||||||
# Pick inner-most parent for our offset
|
# Pick inner-most parent for our offset
|
||||||
for struct in self.structs:
|
for struct in self.structs:
|
||||||
@@ -651,7 +652,8 @@ class Scanner2(Scanner):
|
|||||||
if setup_target != loop_end_offset:
|
if setup_target != loop_end_offset:
|
||||||
self.fixed_jumps[offset] = loop_end_offset
|
self.fixed_jumps[offset] = loop_end_offset
|
||||||
|
|
||||||
(line_no, next_line_byte) = self.lines[offset]
|
if self.lines:
|
||||||
|
(line_no, next_line_byte) = self.lines[offset]
|
||||||
|
|
||||||
# jump_back_offset is the instruction after the SETUP_LOOP
|
# jump_back_offset is the instruction after the SETUP_LOOP
|
||||||
# where we iterate back to.
|
# where we iterate back to.
|
||||||
|
@@ -113,7 +113,7 @@ class Scanner26(scan.Scanner2):
|
|||||||
i = self.next_stmt[last_stmt]
|
i = self.next_stmt[last_stmt]
|
||||||
replace = {}
|
replace = {}
|
||||||
while i < codelen - 1:
|
while i < codelen - 1:
|
||||||
if self.lines[last_stmt].next > i:
|
if self.lines and self.lines[last_stmt].next > i:
|
||||||
# Distinguish "print ..." from "print ...,"
|
# Distinguish "print ..." from "print ...,"
|
||||||
if self.code[last_stmt] == self.opc.PRINT_ITEM:
|
if self.code[last_stmt] == self.opc.PRINT_ITEM:
|
||||||
if self.code[i] == self.opc.PRINT_ITEM:
|
if self.code[i] == self.opc.PRINT_ITEM:
|
||||||
|
@@ -30,10 +30,10 @@ def customize_for_version26_27(self, version):
|
|||||||
########################################
|
########################################
|
||||||
if version > (2, 6):
|
if version > (2, 6):
|
||||||
TABLE_DIRECT.update({
|
TABLE_DIRECT.update({
|
||||||
'except_cond2': ( '%|except %c as %c:\n', 1, 5 ),
|
"except_cond2": ( "%|except %c as %c:\n", 1, 5 ),
|
||||||
# When a generator is a single parameter of a function,
|
# When a generator is a single parameter of a function,
|
||||||
# it doesn't need the surrounding parenethesis.
|
# it doesn't need the surrounding parenethesis.
|
||||||
'call_generator': ('%c%P', 0, (1, -1, ', ', 100)),
|
"call_generator": ('%c%P', 0, (1, -1, ', ', 100)),
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
TABLE_DIRECT.update({
|
TABLE_DIRECT.update({
|
||||||
@@ -60,3 +60,14 @@ def customize_for_version26_27(self, version):
|
|||||||
|
|
||||||
self.default(node)
|
self.default(node)
|
||||||
self.n_call = n_call
|
self.n_call = n_call
|
||||||
|
|
||||||
|
def n_import_from(node):
|
||||||
|
import_name = node[2]
|
||||||
|
if import_name == "IMPORT_NAME" and import_name.pattr == "":
|
||||||
|
fmt = "%|from . import %c\n"
|
||||||
|
self.template_engine(
|
||||||
|
(fmt, (3, "importlist")), node
|
||||||
|
)
|
||||||
|
self.prune()
|
||||||
|
self.default(node)
|
||||||
|
self.n_import_from = n_import_from
|
||||||
|
Reference in New Issue
Block a user