Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(79002)

Side by Side Diff: Lib/html/__init__.py

Issue 2830: Copy cgi.escape() to html
Patch Set: Created 8 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/cgi.py ('k') | Lib/http/server.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # This directory is a Python package. 1 """Helper functions for HTML manipulation."""
2
3 def escape(s, quote=None):
4 """Replace special characters "&", "<" and ">" to HTML-safe sequences.
5 If the optional flag quote is true, the quotation mark character (")
6 is also translated."""
7 s = s.replace("&", "&amp;") # Must be done first!
8 s = s.replace("<", "&lt;")
9 s = s.replace(">", "&gt;")
10 if quote:
11 s = s.replace('"', "&quot;")
12 s = s.replace('\'', "&#x27;")
13 return s
OLDNEW
« no previous file with comments | « Lib/cgi.py ('k') | Lib/http/server.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+