diff --git a/uncompyle6/scanner.py b/uncompyle6/scanner.py index 344c8ea1..d4fcfc4b 100644 --- a/uncompyle6/scanner.py +++ b/uncompyle6/scanner.py @@ -226,6 +226,8 @@ class Scanner(object): # Locally we use list for more convenient iteration using indices linestarts = list(self.opc.findlinestarts(code_obj)) self.linestarts = dict(linestarts) + if not self.linestarts: + return [] # 'List-map' which shows line number of current op and offset of # first op on following line, given offset of op as index diff --git a/uncompyle6/scanners/scanner2.py b/uncompyle6/scanners/scanner2.py index db213bab..3b4b77da 100644 --- a/uncompyle6/scanners/scanner2.py +++ b/uncompyle6/scanners/scanner2.py @@ -521,7 +521,7 @@ class Scanner2(Scanner): for s in stmt_list: if code[s] == self.opc.JUMP_ABSOLUTE and s not in pass_stmts: 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) continue j = self.prev[s] @@ -622,6 +622,7 @@ class Scanner2(Scanner): parent = self.structs[0] start = parent["start"] end = parent["end"] + next_line_byte = end # Pick inner-most parent for our offset for struct in self.structs: @@ -650,7 +651,8 @@ class Scanner2(Scanner): if setup_target != 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 # where we iterate back to. diff --git a/uncompyle6/scanners/scanner26.py b/uncompyle6/scanners/scanner26.py index f0d46f90..9c77476c 100755 --- a/uncompyle6/scanners/scanner26.py +++ b/uncompyle6/scanners/scanner26.py @@ -113,7 +113,7 @@ class Scanner26(scan.Scanner2): i = self.next_stmt[last_stmt] replace = {} 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 ...," if self.code[last_stmt] == self.opc.PRINT_ITEM: if self.code[i] == self.opc.PRINT_ITEM: diff --git a/uncompyle6/semantics/customize26_27.py b/uncompyle6/semantics/customize26_27.py index ee50bb21..2e503c21 100644 --- a/uncompyle6/semantics/customize26_27.py +++ b/uncompyle6/semantics/customize26_27.py @@ -30,10 +30,10 @@ def customize_for_version26_27(self, version): ######################################## if version > (2, 6): 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, # it doesn't need the surrounding parenethesis. - 'call_generator': ('%c%P', 0, (1, -1, ', ', 100)), + "call_generator": ('%c%P', 0, (1, -1, ', ', 100)), }) else: TABLE_DIRECT.update({ @@ -60,3 +60,14 @@ def customize_for_version26_27(self, version): self.default(node) 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