"Fossies" - the Fresh Open Source Software Archive

Member "cheetah3-3.2.6.post2/Cheetah/Utils/htmlEncode.py" (20 Apr 2021, 509 Bytes) of package /linux/www/cheetah3-3.2.6.post2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "htmlEncode.py" see the Fossies "Dox" file reference documentation.

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