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

def handle_entityref(self, ref):

    data = None
    if self.soup.convertHTMLEntities:
        try:
            data = unichr(name2codepoint[ref])
        except KeyError:
            pass
    if ((not data) and self.soup.convertXMLEntities):
        data = self.soup.XML_ENTITIES_TO_SPECIAL_CHARS.get(ref)
    if ((not data) and self.soup.convertHTMLEntities and (not self.soup.XML_ENTITIES_TO_SPECIAL_CHARS.get(ref))):
        data = ('&amp;%s' % ref)
    if (not data):
        data = ('&%s;' % ref)
    self.handle_data(data)
