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

Method __init__

IPython/lib/lexers.py:267–330  ·  view source on GitHub ↗

Initialize the IPython console lexer. Parameters ---------- python3 : bool If `True`, then the console inputs are parsed using a Python 3 lexer. Otherwise, they are parsed using a Python 2 lexer. in1_regex : RegexObject The compile

(self, **options)

Source from the content-addressed store, hash-verified

265 ipytb_start = re.compile(r'^(\^C)?(-+\n)|^( File)(.*)(, line )(\d+\n)')
266
267 def __init__(self, **options):
268 """Initialize the IPython console lexer.
269
270 Parameters
271 ----------
272 python3 : bool
273 If `True`, then the console inputs are parsed using a Python 3
274 lexer. Otherwise, they are parsed using a Python 2 lexer.
275 in1_regex : RegexObject
276 The compiled regular expression used to detect the start
277 of inputs. Although the IPython configuration setting may have a
278 trailing whitespace, do not include it in the regex. If `None`,
279 then the default input prompt is assumed.
280 in2_regex : RegexObject
281 The compiled regular expression used to detect the continuation
282 of inputs. Although the IPython configuration setting may have a
283 trailing whitespace, do not include it in the regex. If `None`,
284 then the default input prompt is assumed.
285 out_regex : RegexObject
286 The compiled regular expression used to detect outputs. If `None`,
287 then the default output prompt is assumed.
288
289 """
290 self.python3 = get_bool_opt(options, 'python3', False)
291 if self.python3:
292 self.aliases = ['ipython3console']
293 else:
294 self.aliases = ['ipython2console', 'ipythonconsole']
295
296 in1_regex = options.get('in1_regex', self.in1_regex)
297 in2_regex = options.get('in2_regex', self.in2_regex)
298 out_regex = options.get('out_regex', self.out_regex)
299
300 # So that we can work with input and output prompts which have been
301 # rstrip'd (possibly by editors) we also need rstrip'd variants. If
302 # we do not do this, then such prompts will be tagged as 'output'.
303 # The reason can't just use the rstrip'd variants instead is because
304 # we want any whitespace associated with the prompt to be inserted
305 # with the token. This allows formatted code to be modified so as hide
306 # the appearance of prompts, with the whitespace included. One example
307 # use of this is in copybutton.js from the standard lib Python docs.
308 in1_regex_rstrip = in1_regex.rstrip() + '\n'
309 in2_regex_rstrip = in2_regex.rstrip() + '\n'
310 out_regex_rstrip = out_regex.rstrip() + '\n'
311
312 # Compile and save them all.
313 attrs = ['in1_regex', 'in2_regex', 'out_regex',
314 'in1_regex_rstrip', 'in2_regex_rstrip', 'out_regex_rstrip']
315 for attr in attrs:
316 self.__setattr__(attr, re.compile(locals()[attr]))
317
318 Lexer.__init__(self, **options)
319
320 if self.python3:
321 pylexer = IPython3Lexer
322 tblexer = IPythonTracebackLexer
323 else:
324 pylexer = IPythonLexer

Callers

nothing calls this directly

Calls 3

resetMethod · 0.95
__setattr__Method · 0.45
__init__Method · 0.45

Tested by

no test coverage detected