MCPcopy Create free account
hub / github.com/EasyIME/PIME / xhtml_escape

Function xhtml_escape

python/python3/tornado/escape.py:43–56  ·  view source on GitHub ↗

Escapes a string so it is valid within HTML or XML. Escapes the characters ``<``, ``>``, ``"``, ``'``, and ``&``. When used in attribute values the escaped strings must be enclosed in quotes. .. versionchanged:: 3.2 Added the single quote to the list of escaped characters.

(value: Union[str, bytes])

Source from the content-addressed store, hash-verified

41
42
43def xhtml_escape(value: Union[str, bytes]) -> str:
44 """Escapes a string so it is valid within HTML or XML.
45
46 Escapes the characters ``<``, ``>``, ``"``, ``&#x27;``, and ``&``.
47 When used in attribute values the escaped strings must be enclosed
48 in quotes.
49
50 .. versionchanged:: 3.2
51
52 Added the single quote to the list of escaped characters.
53 """
54 return _XHTML_ESCAPE_RE.sub(
55 lambda match: _XHTML_ESCAPE_DICT[match.group(0)], to_basestring(value)
56 )
57
58
59def xhtml_unescape(value: Union[str, bytes]) -> str:

Callers 3

test_xhtml_escapeMethod · 0.90
linkifyFunction · 0.85

Calls

no outgoing calls

Tested by 2

test_xhtml_escapeMethod · 0.72