code: def handle_entityref(self, ref):
          
          data = None
          if self.convertHTMLEntities:
              try:
                  data = unichr(name2codepoint[ref])
              except KeyError:
                  pass
  
          if not data and self.convertXMLEntities:
                  data = self.XML_ENTITIES_TO_SPECIAL_CHARS.get(ref)
  
          if not data and self.convertHTMLEntities and \
              not self.XML_ENTITIES_TO_SPECIAL_CHARS.get(ref):
                  # TODO: We've got a problem here. We're told this is
                  # an entity reference, but it's not an XML entity
                  # reference or an HTML entity reference. Nonetheless,
                  # the logical thing to do is to pass it through as an
                  # unrecognized entity reference.
                  #
                  # Except: when the input is "&carol;" this function
                  # will be called with input "carol". When the input is
                  # "AT&T", this function will be called with input
                  # "T". We have no way of knowing whether a semicolon
                  # was present originally, so we don't know whether
                  # this is an unknown entity or just a misplaced
                  # ampersand.
                  #
                  # The more common case is a misplaced ampersand, so I
                  # escape the ampersand and omit the trailing semicolon.
                  data = "&amp;%s" % ref
          if not data:
              # This case is different from the one above, because we
              # haven't already gone through a supposedly comprehensive
              # mapping of entities to Unicode characters. We might not
              # have gone through any mapping at all. So the chances are
              # very high that this is a real entity, and not a
              # misplaced ampersand.
              data = "&%s;" % ref
          self.handle_data(data)
docs: Handle entity references as data, possibly converting known
          HTML and/or XML entity references to the corresponding Unicode
          characters.