def by_dict(hook, truthdict, default=True):
    """A filter for hooks.

    truthdict is a mapping of URI -> filter? where if the requested URI is a
    key in the dict, then the hook is applied based on the filter? value.

    """
    def filtered_hook(request):
        do_hook = truthdict.get(request.line.uri, default)
        if do_hook:
            return hook(request)
        else:
            return request
    return filtered_hook