'HTML-escape a string or object.
This converts any non-string objects passed into it to strings
(actually, using unicode()).  All values returned are
non-unicode strings (using "&#num;" entities for all non-ASCII
characters).
None is treated specially, and returns the empty string.
@param s: The string that needs to be escaped.
@type s: str
@return: The escaped string.'

def _html_escape(self, s):

    if (s is None):
        return ''
    if (not isinstance(s, basestring)):
        if hasattr(s, '__unicode__'):
            s = unicode(s)
        else:
            s = str(s)
    s = cgi.escape(s, True)
    if isinstance(s, unicode):
        s = s.encode('ascii', 'xmlcharrefreplace')
    return s
