Archived
24 lines
456 B
Python
24 lines
456 B
Python
from __future__ import annotations
|
|
|
|
import html
|
|
|
|
|
|
class SafeHtml(str):
|
|
"""HTML fragment that was built by trusted server-side template helpers."""
|
|
|
|
|
|
def escape(value: object) -> str:
|
|
return html.escape(str(value), quote=True)
|
|
|
|
|
|
def attr(value: object) -> str:
|
|
return escape(value)
|
|
|
|
|
|
def trusted(fragment: str) -> SafeHtml:
|
|
return SafeHtml(fragment)
|
|
|
|
|
|
def join_html(fragments: list[str]) -> SafeHtml:
|
|
return SafeHtml("".join(fragments))
|