summaryrefslogtreecommitdiff
path: root/cheetah/Utils/htmlEncode.py
diff options
context:
space:
mode:
Diffstat (limited to 'cheetah/Utils/htmlEncode.py')
-rw-r--r--cheetah/Utils/htmlEncode.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/cheetah/Utils/htmlEncode.py b/cheetah/Utils/htmlEncode.py
new file mode 100644
index 0000000..f76c77e
--- /dev/null
+++ b/cheetah/Utils/htmlEncode.py
@@ -0,0 +1,21 @@
+"""This is a copy of the htmlEncode function in Webware.
+
+
+@@TR: It implemented more efficiently.
+
+"""
+htmlCodes = [
+ ['&', '&'],
+ ['<', '&lt;'],
+ ['>', '&gt;'],
+ ['"', '&quot;'],
+]
+htmlCodesReversed = htmlCodes[:]
+htmlCodesReversed.reverse()
+
+def htmlEncode(s, codes=htmlCodes):
+ """ Returns the HTML encoded version of the given string. This is useful to
+ display a plain ASCII text string on a web page."""
+ for code in codes:
+ s = s.replace(code[0], code[1])
+ return s