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])
| 41 | |
| 42 | |
| 43 | def xhtml_escape(value: Union[str, bytes]) -> str: |
| 44 | """Escapes a string so it is valid within HTML or XML. |
| 45 | |
| 46 | Escapes the characters ``<``, ``>``, ``"``, ``'``, 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 | |
| 59 | def xhtml_unescape(value: Union[str, bytes]) -> str: |
no outgoing calls