INNER CODE UNIT · Python

xml_format_string

volfpeter/htmy · htmy/core.py:217

def xml_format_string(value: str) -> str:
    """Escapes `<`, `>`, and `&` characters in the given string, unless it's a `SafeStr`."""
    return value if isinstance(value, SafeStr) else xml_escape(value)


class Formatter(ContextAware):
    """
    The default, context-aware property name and value formatter.

    The formatter supports both primitive and (many) complex values, such as lists,
    dictionaries, tuples, and sets. Complex values are JSON-serialized by default.

    Important: the default implementation looks up the formatter for a given value by checking
    its type, but it doesn't do this check with the base classes of the encountered type. For
    example the formatter will know how to format `datetime` object, but it won't know how to
    format a `MyCustomDatetime(datetime)` instance.

    One reason for this is efficiency: always checking the base classes of every single value is a

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…