def context_aware(fn):
 def new_fn(*args, **kwargs):
  _new_context()
  _new_context(('(%s)' % fn.__name__))
  try:
   return fn(*args, **kwargs)
  except Exception as e:
   if (not exception_context(e)):
    set_exception_context(e, get_context())
   raise
  finally:
   _pop_context()
   _pop_context()
 new_fn.__name__ = fn.__name__
 new_fn.__doc__ = fn.__doc__
 new_fn.__dict__.update(fn.__dict__)
 return new_fn

def context_aware ( fn ) : def new_fn ( * args , ** kwargs ) : _new_context ( ) _new_context ( ( '(%s)' % fn . __name__ ) ) try : return fn ( * args , ** kwargs ) except Exception as e : if ( not exception_context ( e ) ) : set_exception_context ( e , get_context ( ) ) raise finally : _pop_context ( ) _pop_context ( ) new_fn . __name__ = fn . __name__ new_fn . __doc__ = fn . __doc__ new_fn . __dict__ . update ( fn . __dict__ ) return new_fn
a decorator that must be applied to functions that call context() .