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

Unified Diff: Lib/html/__init__.py

Issue 2830: Copy cgi.escape() to html
Patch Set: Created 8 years, 12 months ago
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/cgi.py ('k') | Lib/http/server.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Lib/html/__init__.py
===================================================================
--- Lib/html/__init__.py (revision 84355)
+++ Lib/html/__init__.py (working copy)
@@ -1 +1,13 @@
-# This directory is a Python package.
+"""Helper functions for HTML manipulation."""
+
+def escape(s, quote=None):
+ """Replace special characters "&", "<" and ">" to HTML-safe sequences.
+ If the optional flag quote is true, the quotation mark character (")
+ is also translated."""
+ s = s.replace("&", "&amp;") # Must be done first!
+ s = s.replace("<", "&lt;")
+ s = s.replace(">", "&gt;")
+ if quote:
+ s = s.replace('"', "&quot;")
+ s = s.replace('\'', "&#x27;")
+ return s
« 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+