How to use the loguru._ansimarkup.AnsiMarkup function in loguru

To help you get started, we’ve selected a few loguru examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Delgan / loguru / tests / test_ansimarkup.py View on Github external
def test_strip():
    assert s("<b>1</b>23") == "123"
    assert s("1") == "1"
    assert s("1") == "1"
    assert s("1") == "1"
    assert s("1") == "1"

    markups = {"red": "", "b,g,r": "", "fg 1,2,3": ""}
    am = AnsiMarkup(custom_markups=markups, strip=True)
    assert am.feed("123", strict=True) == "123"
github Delgan / loguru / tests / test_opt.py View on Github external
def parse(text, colorize=True):
    if colorize:
        return AnsiMarkup(strip=False).feed(text, strict=True)
    else:
        return AnsiMarkup(strip=True).feed(text, strict=True)
github Delgan / loguru / tests / test_add_options.py View on Github external
def parse(text):
    return AnsiMarkup(strip=False).feed(text, strict=True)
github Delgan / loguru / tests / test_ansimarkup.py View on Github external
def s(text, *, strict=False):
    return AnsiMarkup(strip=True).feed(text, strict=strict)
github Delgan / loguru / tests / test_levels.py View on Github external
def parse(text):
    return AnsiMarkup(strip=False).feed(text, strict=True)
github Delgan / loguru / loguru / _logger.py View on Github external
elif isinstance(level, int):
            levelno = level
        else:
            raise TypeError(
                "Invalid level, it should be an integer or a string, not: '%s'"
                % type(level).__name__
            )

        if levelno &lt; 0:
            raise ValueError(
                "Invalid level value, it should be a positive integer, not: %d" % levelno
            )

        if isinstance(format, str):
            try:
                AnsiMarkup.verify(format, ["level", "lvl"])
            except ValueError as e:
                raise ValueError(
                    "Invalid format, color markups could not be parsed correctly"
                ) from e
            formatter = format + terminator + "{exception}"
            is_formatter_dynamic = False
        elif callable(format):
            if format == builtins.format:
                raise ValueError(
                    "The built-in 'format()' function cannot be used as a 'format' parameter, "
                    "this is most likely a mistake (please double-check the arguments passed "
                    "to 'logger.add()')."
                )
            formatter = format
            is_formatter_dynamic = True
        else:
github Delgan / loguru / loguru / _handler.py View on Github external
def _decolorize_format(format_):
        markups = {"level": "", "lvl": ""}
        return AnsiMarkup(custom_markups=markups, strip=True).feed(format_, strict=True)
github Delgan / loguru / loguru / _handler.py View on Github external
def _memoize_ansi_messages(format_, ansi_code, message):
        markups = {"level": ansi_code, "lvl": ansi_code}
        ansimarkup = AnsiMarkup(custom_markups=markups, strip=False)

        def parse(string_, *, recursive=True):
            for text, name, spec, _ in string.Formatter().parse(string_):
                ansimarkup.feed(text, strict=False)
                if spec and recursive:
                    yield from parse(spec, recursive=False)
                if name and name[:8] in ("message", "message.", "message["):
                    yield ansimarkup.feed(message, strict=True)

        messages = list(parse(format_))

        class AnsiDict:
            def __init__(self, record):
                self._record = record
                self._messages = iter(messages)