'Handle entity references as data, possibly converting known
HTML entity references to the corresponding Unicode
characters.'

def handle_entityref(self, ref):

    replaceWithXMLEntity = (self.convertXMLEntities and (ref in self.XML_ENTITIES_TO_CHARS))
    if (self.convertHTMLEntities or replaceWithXMLEntity):
        try:
            data = unichr(name2codepoint[ref])
        except KeyError:
            if replaceWithXMLEntity:
                data = self.XML_ENTITIES_TO_CHARS.get(ref)
            else:
                data = ('&amp;%s' % ref)
    else:
        data = ('&%s;' % ref)
    self.handle_data(data)
