Module: utils.PyColorize
4 Classes
- class IPython.utils.PyColorize.Theme(name: str, base: str | None, extra_style: dict[_TokenType, str], *, symbols: Symbols | None = None)
Bases:
object- __init__(name: str, base: str | None, extra_style: dict[_TokenType, str], *, symbols: Symbols | None = None) None
- class IPython.utils.PyColorize.ThemeTable
-
Lazy, extensible mapping of theme name to
Theme.Built-in themes live as JSON next to this module and are only read and turned into pygments tokens the first time they are looked up.
Beyond those, a theme can come from a JSON file dropped in
themes/inside the IPython directory, named after the file, or from a package advertising it in theipython.themesentry point group.Built-in names win, so neither a stray file nor an installed package can silently redefine a shipped theme; a file in the IPython directory in turn wins over an installed package, being the more local of the two.
- class IPython.utils.PyColorize.Parser(out: Any = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, *, theme_name: str | None = None)
Bases:
objectFormat colored Python source.
- __init__(out: Any = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, *, theme_name: str | None = None) None
Create a parser with a specified color table and output channel.
Call format() to process code.
- format2(raw: str, out: Any = None) tuple[str | None, bool]
Parse and send the colored source.
If out is not specified, the defaults (given to constructor) are used.
out should be a file-type object. Optionally, out can be given as the string ‘str’ and the parser will automatically return the output in a string.
1 Function
- IPython.utils.PyColorize.token_from_str(dotted: str) _TokenType
Resolve a dotted token path to a pygments token.
"Prompt.Continuation.L1"givesToken.Prompt.Continuation.L1. A leadingToken.is accepted but not required, and the empty string maps toTokenitself.Raises ValueError if
dotteddoes not name a token.