def context_factory(apply_globally=False, api=None):
    """A decorator that registers a single hug context factory"""
    def decorator(context_factory_):
        if apply_globally:
            hug.defaults.context_factory = context_factory_
        else:
            apply_to_api = hug.API(api) if api else hug.api.from_object(context_factory_)
            apply_to_api.context_factory = context_factory_
        return context_factory_
    return decorator
A decorator that registers a single hug context factory