import functools


def context_wrapper(ctx_manager, *ctx_args, **ctx_kwargs):
    """
    Higher order function that returns a decorator that runs the wrapped
    func within the context of the given `ctx_manager` initialized
    by `ctx_args` and `ctx_kwargs`
    """
    def _wrapper(func):
        @functools.wraps(func)
        def _inner(*args, **kwargs):
            with ctx_manager(*ctx_args, **ctx_kwargs):
                return func(*args, **kwargs)
        return _inner
    return _wrapper