def encode(char): char = ord(char) name = codepoint2name.get(char) if name is not None: return "&%s;" % name else: return "%%%02X" % char
def escapize(char): a = codepoint2name.get(ord(char), None) if a: return '&' + a + ';' return char
def html_replace(exc): assert isinstance(exc, (UnicodeEncodeError, UnicodeTranslateError)) s = [ u'&%s;' % codepoint2name.get(ord(c), '#x%04X' % (ord(c),)) for c in exc.object[exc.start:exc.end] ] return ''.join(s), exc.end
def html_entity(self): name = codepoint2name.get(self.dec) if name: return '&%s;' % name else: return ''