<s> """<STR_LIT>""" <EOL> import re <EOL> from pygments . lexer import Lexer , do_insertions <EOL> from pygments . lexers . agile import ( PythonConsoleLexer , PythonLexer , <EOL> PythonTracebackLexer ) <EOL> from pygments . token import Comment , Generic <EOL> from sphinx import highlighting <EOL> line_re = re . compile ( '<STR_LIT>' ) <EOL> class IPythonConsoleLexer ( Lexer ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> aliases = [ '<STR_LIT>' ] <EOL> mimetypes = [ '<STR_LIT>' ] <EOL> input_prompt = re . compile ( "<STR_LIT>" ) <EOL> output_prompt = re . compile ( "<STR_LIT>" ) <EOL> continue_prompt = re . compile ( "<STR_LIT>" ) <EOL> tb_start = re . compile ( "<STR_LIT>" ) <EOL> def get_tokens_unprocessed ( self , text ) : <EOL> pylexer = PythonLexer ( ** self . options ) <EOL> tblexer = PythonTracebackLexer ( ** self . options ) <EOL> curcode = '<STR_LIT>' <EOL> insertions = [ ] <EOL> for match in line_re . finditer ( text ) : <EOL> line = match . group ( ) <EOL> input_prompt = self . input_prompt . match ( line ) <EOL> continue_prompt = self . continue_prompt . match ( line . rstrip ( ) ) <EOL> output_prompt = self . output_prompt . match ( line ) <EOL> if line . startswith ( "<STR_LIT:#>" ) : <EOL> insertions . append ( ( len ( curcode ) , <EOL> [ ( <NUM_LIT:0> , Comment , line ) ] ) ) <EOL> elif input_prompt is not None : <EOL> insertions . append ( ( len ( curcode ) , <EOL> [ ( <NUM_LIT:0> , Generic . Prompt , input_prompt . group ( ) ) ] ) ) <EOL> curcode += line [ input_prompt . end ( ) : ] <EOL> elif continue_prompt is not None : <EOL> insertions . append ( ( len ( curcode ) , <EOL> [ ( <NUM_LIT:0> , Generic . Prompt , continue_prompt . group ( ) ) ] ) ) <EOL> curcode += line [ continue_prompt . end ( ) : ] <EOL> elif output_prompt is not None : <EOL> insertions . append ( ( len ( curcode ) , <EOL> [ ( <NUM_LIT:0> , Generic . Error , output_prompt . group ( ) ) ] ) ) <EOL> curcode += line [ output_prompt . end ( ) : ] <EOL> else : <EOL> if curcode : <EOL> for item in do_insertions ( insertions , <EOL> pylexer . get_tokens_unprocessed ( curcode ) ) : <EOL> yield item <EOL> curcode = '<STR_LIT>' <EOL> insertions = [ ] <EOL> yield match . start ( ) , Generic . Output , line <EOL> if curcode : <EOL> for item in do_insertions ( insertions , <EOL> pylexer . get_tokens_unprocessed ( curcode ) ) : <EOL> yield item <EOL> def setup ( app ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> highlighting . lexers [ '<STR_LIT>' ] = IPythonConsoleLexer ( ) </s>
