root/Cheetah/Utils/htmlEncode.py

Revision f17b49bd2a9cb5c693518283252cdbca4d04136b, 508 bytes (checked in by Jason Michalski <armooo@armooo.net>, 2 years ago)

Lets try the import again

  • Property mode set to 100644
Line 
1 """This is a copy of the htmlEncode function in Webware.
2
3
4 @@TR: It implemented more efficiently.
5
6 """
7 htmlCodes = [
8     ['&', '&amp;'],
9     ['<', '&lt;'],
10     ['>', '&gt;'],
11     ['"', '&quot;'],
12 ]
13 htmlCodesReversed = htmlCodes[:]
14 htmlCodesReversed.reverse()
15
16 def htmlEncode(s, codes=htmlCodes):
17     """ Returns the HTML encoded version of the given string. This is useful to
18     display a plain ASCII text string on a web page."""
19     for code in codes:
20         s = s.replace(code[0], code[1])
21     return s
Note: See TracBrowser for help on using the browser.