Replace one matched HTML entity with the character it represents,
    if possible.

def _unescape_fixup(match):
    """
    Replace one matched HTML entity with the character it represents,
    if possible.
    """
    text = match.group(0)
    if text[:2] == "&#":
        # character reference
        try:
            if text[:3] == "&#x":
                codept = int(text[3:-1], 16)
            else:
                codept = int(text[2:-1])
            if 0x80 <= codept < 0xa0:
                # Decode this range of characters as Windows-1252, as Web
                # browsers do in practice.
                return bytes([codept]).decode('sloppy-windows-1252')
            else:
                return chr(codept)
        except ValueError:
            return text
    else:
        # This is a named entity; if it's a known HTML5 entity, replace
        # it with the appropriate character.
        try:
            return entities.html5[text[1:]]
        except KeyError:
            return text