summaryrefslogtreecommitdiffstats
path: root/cobbler/Cheetah/Utils/htmlEncode.py
blob: f76c77e4e622f5d3124804f7c553ab79daed5f41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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