Exemplo n.º 1
0
def _logical_start(lines, lineno, check_prev=False):
    logical_finder = LogicalLineFinder(ArrayLinesAdapter(lines))
    if check_prev:
        prev = lineno - 1
        while prev > 0:
            start, end = logical_finder.logical_line_in(prev)
            if end is None or start <= lineno < end:
                return start
            if start <= prev:
                break
            prev -= 1
    return logical_finder.logical_line_in(lineno)[0]
Exemplo n.º 2
0
 def _fix_incomplete_try_blocks(self, lineno, indents):
     block_start = lineno
     last_indents = indents
     while block_start > 0:
         block_start = rope.base.codeanalyze.get_block_start(
             ArrayLinesAdapter(self.lines), block_start) - 1
         if self.lines[block_start].strip().startswith('try:'):
             indents = _get_line_indents(self.lines[block_start])
             if indents > last_indents:
                 continue
             last_indents = indents
             block_end = self._find_matching_deindent(block_start)
             line = self.lines[block_end].strip()
             if not (line.startswith('finally:')
                     or line.startswith('except ')
                     or line.startswith('except:')):
                 self._insert(block_end, ' ' * indents + 'finally:')
                 self._insert(block_end + 1, ' ' * indents + '    pass')