def add_hook(name, pass_function=False):
 def outer(f):
  f.__hook_name__ = name
  @functools.wraps(f)
  def inner(*args, **kwargs):
   manager = _HOOKS.setdefault(name, HookManager(name))
   function = None
   if pass_function:
    function = f
   manager.run_pre(name, args, kwargs, f=function)
   rv = f(*args, **kwargs)
   manager.run_post(name, rv, args, kwargs, f=function)
   return rv
  return inner
 return outer

def add_hook ( name , pass_function = False ) : def outer ( f ) : f . __hook_name__ = name @ functools . wraps ( f ) def inner ( * args , ** kwargs ) : manager = _HOOKS . setdefault ( name , HookManager ( name ) ) function = None if pass_function : function = f manager . run_pre ( name , args , kwargs , f = function ) rv = f ( * args , ** kwargs ) manager . run_post ( name , rv , args , kwargs , f = function ) return rv return inner return outer
execute optional pre and post methods around the decorated function .