#!/usr/local/bin/python2 class Hook(object): def pre_func(*args, **kwargs): pass def post_func(*args, **kwargs): pass def attach(self, method, instance): def f(*args, **kwargs): self.pre_func(*args, **kwargs) method(*args, **kwargs) self.post_func(*args, **kwargs) setattr(instance, method.__name__, f)