MCPcopy Create free account
hub / github.com/ipython/ipython / IPythonConsoleLexer

Class IPythonConsoleLexer

IPython/lib/lexers.py:211–494  ·  view source on GitHub ↗

An IPython console lexer for IPython code-blocks and doctests, such as: .. code-block:: rst .. code-block:: ipythonconsole In [1]: a = 'foo' In [2]: a Out[2]: 'foo' In [3]: print a foo In [4]: 1 / 0

Source from the content-addressed store, hash-verified

209 IPythonPartialTracebackLexer, **options)
210
211class IPythonConsoleLexer(Lexer):
212 """
213 An IPython console lexer for IPython code-blocks and doctests, such as:
214
215 .. code-block:: rst
216
217 .. code-block:: ipythonconsole
218
219 In [1]: a = 'foo'
220
221 In [2]: a
222 Out[2]: 'foo'
223
224 In [3]: print a
225 foo
226
227 In [4]: 1 / 0
228
229
230 Support is also provided for IPython exceptions:
231
232 .. code-block:: rst
233
234 .. code-block:: ipythonconsole
235
236 In [1]: raise Exception
237
238 ---------------------------------------------------------------------------
239 Exception Traceback (most recent call last)
240 <ipython-input-1-fca2ab0ca76b> in <module>
241 ----> 1 raise Exception
242
243 Exception:
244
245 """
246 name = 'IPython console session'
247 aliases = ['ipythonconsole']
248 mimetypes = ['text/x-ipython-console']
249
250 # The regexps used to determine what is input and what is output.
251 # The default prompts for IPython are:
252 #
253 # in = 'In [#]: '
254 # continuation = ' .D.: '
255 # template = 'Out[#]: '
256 #
257 # Where '#' is the 'prompt number' or 'execution count' and 'D'
258 # D is a number of dots matching the width of the execution count
259 #
260 in1_regex = r'In \[[0-9]+\]: '
261 in2_regex = r' \.\.+\.: '
262 out_regex = r'Out\[[0-9]+\]: '
263
264 #: The regex to determine when a traceback starts.
265 ipytb_start = re.compile(r'^(\^C)?(-+\n)|^( File)(.*)(, line )(\d+\n)')
266
267 def __init__(self, **options):
268 """Initialize the IPython console lexer.

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected