import re


def percent_decode(data):
    """ Percent decode a string of data.

    """
    if data is None:
        return None
    percent_code = re.compile("(%[0-9A-Fa-f]{2})")
    try:
        bits = percent_code.split(data)
    except TypeError:
        bits = percent_code.split(str(data))
    out = bytearray()
    for bit in bits:
        if bit.startswith("%"):
            out.extend(bytearray([int(bit[1:], 16)]))
        else:
            out.extend(bytearray(bit, "utf-8"))
    return out.decode("utf-8")