def set_key(target, key, value=None):
    ctx = get_context()

    # clearing key
    if value is None:
        try:
            del target.metadata[key]
            target.user_set_metadata.remove(key)
        except (KeyError, __HOLE__):
            pass

    # setting key
    else:
        target.metadata[key] = value

        restricted_keys = ctx.conf.metadata.get('restricted_keys', [])
        if key not in target.user_set_metadata and key not in restricted_keys:
            target.user_set_metadata.append(key)

        target.metadata[key] = value
dataset/ETHPy150Open mammon-ircd/mammon/mammon/core/ircv3/metadata.py/set_key