MCPcopy Index your code
hub / github.com/ipython/ipython / Parser

Class Parser

IPython/utils/PyColorize.py:393–582  ·  view source on GitHub ↗

Format colored Python source.

Source from the content-addressed store, hash-verified

391
392
393class Parser:
394 """Format colored Python source."""
395
396 _theme_name: str
397 out: Any
398 pos: int
399 lines: list[int]
400 raw: str
401
402 def __init__(self, out: Any = sys.stdout, *, theme_name: str | None = None) -> None:
403 """Create a parser with a specified color table and output channel.
404
405 Call format() to process code.
406 """
407
408 assert theme_name is not None
409
410 self.out = out
411 self.pos = 0
412 self.lines = []
413 self.raw = ""
414 if theme_name is not None:
415 if theme_name in ["Linux", "LightBG", "Neutral", "NoColor"]:
416 warnings.warn(
417 f"Theme names and color schemes are lowercase in IPython 9.0 use {theme_name.lower()} instead",
418 DeprecationWarning,
419 stacklevel=2,
420 )
421 theme_name = theme_name.lower()
422 if not theme_name:
423 self.theme_name = "nocolor"
424 else:
425 self.theme_name = theme_name
426
427 @property
428 def theme_name(self) -> str:
429 return self._theme_name
430
431 @theme_name.setter
432 def theme_name(self, value: str) -> None:
433 assert value == value.lower()
434 self._theme_name = value
435
436 @property
437 def style(self) -> str:
438 assert False
439 return self._theme_name
440
441 @style.setter
442 def style(self, val: str) -> None:
443 assert False
444 assert val == val.lower()
445 self._theme_name = val
446
447 def format(self, raw: str, out: Any = None) -> str | None:
448 return self.format2(raw, out)[0]
449
450 def format2(self, raw: str, out: Any = None) -> tuple[str | None, bool]:

Callers 3

format_recordMethod · 0.90
test_parse_sampleFunction · 0.90
test_parse_errorFunction · 0.90

Calls

no outgoing calls

Tested by 2

test_parse_sampleFunction · 0.72
test_parse_errorFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…