summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-07-19 20:11:53 (GMT)
committerGuido van Rossum <guido@python.org>1997-07-19 20:11:53 (GMT)
commit64c66209343edbdb212678759bc6e32a897b3a13 (patch)
treebacbae5a61eacd67e9dff5363ccea97d1f99b70c /Lib
parent1e8c8a20f2b5ff51415ed8dfbf4df574595a95fb (diff)
downloadcpython-64c66209343edbdb212678759bc6e32a897b3a13.zip
cpython-64c66209343edbdb212678759bc6e32a897b3a13.tar.gz
cpython-64c66209343edbdb212678759bc6e32a897b3a13.tar.bz2
Add optional 'quote' flag argument to escape(); if true, translate '"'
to '&quot;'.
Diffstat (limited to 'Lib')
-rwxr-xr-xLib/cgi.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/Lib/cgi.py b/Lib/cgi.py
index 20f4700..4f1b459 100755
--- a/Lib/cgi.py
+++ b/Lib/cgi.py
@@ -1316,12 +1316,14 @@ environment as well. Here are some common variable names:
# Utilities
# =========
-def escape(s):
+def escape(s, quote=None):
"""Replace special characters '&', '<' and '>' by SGML entities."""
import regsub
s = regsub.gsub("&", "&amp;", s) # Must be done first!
s = regsub.gsub("<", "&lt;", s)
s = regsub.gsub(">", "&gt;", s)
+ if quote:
+ s = regsub.gsub('"', "&quot;", s)
return s