def _call_event_handler(*p, **n): ''' ''' # do the pre event... for evt in _call_event_handler.evt_pre_call: evt.fire(func, *p, **n) # do the call... try: res = func(*p, **n) except Exception, err: # do the err event... for evt in _call_event_handler.evt_err_call: evt.fire(func, err) # XXX might be good to be more thorough here... (e.g. # use the same traceback as the original...) raise err
# do the call... try: res = func(*p, **n) except Exception, err: # do the err event... for evt in _call_event_handler.evt_err_call: evt.fire(func, err) # XXX might be good to be more thorough here... (e.g. # use the same traceback as the original...) raise err except: # handle other exceptions... err = sys.exc_info() # do the err event... for evt in _call_event_handler.evt_err_call: evt.fire(func, err[0]) # XXX might be good to be more thorough here... (e.g. # use the same traceback as the original...) raise err[0] # do the post event... for evt in _call_event_handler.evt_post_call: evt.fire(func, res) return res _call_event_handler.evt_pre_call = () _call_event_handler.evt_post_call = () _call_event_handler.evt_err_call = () _call_event_handler.evt_target_func = func res = _call_event_handler else: res = func