def replace_handler(selector, path, *args, **kwargs):
    """
    Replace an existing path handler in the selector
    map with a new handler. Usually we want to add a
    new one, but sometimes we just want to replace.
    This makes replacing easy. Courtesy of Luke Arno,
    the Selector author.

    Example:
    `replace_handler(config['selector'], '/', GET=show, PUT=update)`
    """
    if len(args):
        new_handler = args[0]
    else:
        new_handler = kwargs
    for index, (regex, _) in enumerate(selector.mappings):
        if regex.match(path) is not None:
            selector.mappings[index] = regex, new_handler
