Skip to content

Commit 4101f31

Browse files
committed
html: Add pristine from Python-3.3.3 tarball.
1 parent 78fd837 commit 4101f31

File tree

3 files changed

+3059
-0
lines changed

3 files changed

+3059
-0
lines changed

html/html/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
General functions for HTML manipulation.
3+
"""
4+
5+
6+
_escape_map = {ord('&'): '&amp;', ord('<'): '&lt;', ord('>'): '&gt;'}
7+
_escape_map_full = {ord('&'): '&amp;', ord('<'): '&lt;', ord('>'): '&gt;',
8+
ord('"'): '&quot;', ord('\''): '&#x27;'}
9+
10+
# NB: this is a candidate for a bytes/string polymorphic interface
11+
12+
def escape(s, quote=True):
13+
"""
14+
Replace special characters "&", "<" and ">" to HTML-safe sequences.
15+
If the optional flag quote is true (the default), the quotation mark
16+
characters, both double quote (") and single quote (') characters are also
17+
translated.
18+
"""
19+
if quote:
20+
return s.translate(_escape_map_full)
21+
return s.translate(_escape_map)

0 commit comments

Comments
 (0)