def uni2html(u):
    '''
    Convert unicode to html.

    Basically leaves ascii chars as is, and attempts to encode unicode chars
    as HTML entities. If the conversion fails the character is skipped.
    '''
    htmlentities = list()
    for c in u:
        ord_c = ord(c)
        if ord_c < 128:
            # ignoring all ^chars like ^M ^R ^E
            if ord_c >31:
                htmlentities.append(c)
        else:
            try:
                htmlentities.append('&%s;' % codepoint2name[ord_c])
            except KeyError:
                pass # Charachter unknown
    return ''.join(htmlentities)
dataset/ETHPy150Open sixohsix/twitter/utils/update.py/uni2html/original