import functools


def _hook_function(func, pre_func_hook=None, post_func_hook=None):
    """Wrap a function with pre- and post-processing hooks.

    Return a new function that calls `pre_func_hook()`, `func()`,
    `post_func_hook()`.

    All functions receive the same arguments as the wrapper was called with.
    The return value of the wrapper is the return value of `func()`.

    Both hooks are optional and can be omitted.
    """
    if not pre_func_hook and not post_func_hook:
        return func

    @functools.wraps(func)
    def f(*args, **kwargs):
        if pre_func_hook:
            pre_func_hook(*args, **kwargs)
        result = func(*args, **kwargs)
        if post_func_hook:
            post_func_hook(*args, **kwargs)
        return result

    return f