MCPcopy
hub / github.com/scrapy/scrapy / _colorize

Function _colorize

scrapy/utils/display.py:32–43  ·  view source on GitHub ↗
(text: str, colorize: bool = True)

Source from the content-addressed store, hash-verified

30
31
32def _colorize(text: str, colorize: bool = True) -> str:
33 # pylint: disable=no-name-in-module
34 if not colorize or not sys.stdout.isatty() or not _tty_supports_color():
35 return text
36 try:
37 from pygments import highlight # noqa: PLC0415
38 except ImportError:
39 return text
40 from pygments.formatters import TerminalFormatter # noqa: PLC0415
41 from pygments.lexers import PythonLexer # noqa: PLC0415
42
43 return highlight(text, PythonLexer(), TerminalFormatter())
44
45
46def pformat(obj: Any, *args: Any, **kwargs: Any) -> str:

Callers 1

pformatFunction · 0.85

Calls 1

_tty_supports_colorFunction · 0.85

Tested by

no test coverage detected