'Ensure that Python interactive shell sessions are put in
code blocks -- even if not properly indented.'

def _prepare_pyshell_blocks(self, text):

    if ('>>>' not in text):
        return text
    less_than_tab = (self.tab_width - 1)
    _pyshell_block_re = re.compile(('\n                                                ^([    ]{0,%d})>>>[    ].*\\n            #    first    line\n                                                ^(\\1.*\\S+.*\\n)*                                    #    any    number    of    subsequent    lines\n                                                ^\\n                                                                                    #    ends    with    a    blank    line\n                                                ' % less_than_tab), (re.M | re.X))
    return _pyshell_block_re.sub(self._pyshell_block_sub, text)
