human
Complete this python program:
def _htmldecode(text):
assistant
#Here is the Python code you requested.

    """Decode HTML entities in the given text.
    """
    if isinstance(text, str):
        uchr = chr
    else:
        def uchr(value):
            (((value > 127) and chr(value)) or chr(value))
    def entitydecode(match, uchr=uchr):
        entity = match.group(1)
        if entity.startswith(u'#x'):
            return uchr(int(entity[2:], 16))
        elif entity.startswith(u'#'):
            return uchr(int(entity[1:]))
        elif (entity in name2codepoint):
            return uchr(name2codepoint[entity])
        else:
            return match.group(0)
    return charrefpat.sub(entitydecode, text)