'Refactors one doctest.
A doctest is given as a block of lines, the first of which starts
with ">>>" (possibly indented), while the remaining lines start
with "..." (identically indented).'

def refactor_doctest(self, block, lineno, indent, filename):

    try:
        tree = self.parse_block(block, lineno, indent)
    except Exception as err:
        if self.logger.isEnabledFor(logging.DEBUG):
            for line in block:
                self.log_debug('Source:    %s', line.rstrip('\n'))
        self.log_error("Can't    parse    docstring    in    %s    line    %s:    %s:    %s", filename, lineno, err.__class__.__name__, err)
        return block
    if self.refactor_tree(tree, filename):
        new = str(tree).splitlines(keepends=True)
        (clipped, new) = (new[:(lineno - 1)], new[(lineno - 1):])
        assert (clipped == (['\n'] * (lineno - 1))), clipped
        if (not new[(-1)].endswith('\n')):
            new[(-1)] += '\n'
        block = [((indent + self.PS1) + new.pop(0))]
        if new:
            block += [((indent + self.PS2) + line) for line in new]
    return block
