def preserve_value(namespace, name):
 def decorator(func):
  def resetter_attr(saved_value_internal):
   return setattr(namespace, name, saved_value_internal)
  def resetter_no_attr(saved_value_internal):
   del saved_value_internal
   return delattr(namespace, name)
  def wrapper(*args, **kwargs):
   saved_value = None
   try:
    saved_value = getattr(namespace, name)
    resetter = resetter_attr
   except AttributeError:
    resetter = resetter_no_attr
   try:
    return func(*args, **kwargs)
   finally:
    resetter(saved_value)
  wrapper.__name__ = func.__name__
  wrapper.__doc__ = func.__doc__
  return wrapper
 return decorator

def preserve_value ( namespace , name ) : def decorator ( func ) : def resetter_attr ( saved_value_internal ) : return setattr ( namespace , name , saved_value_internal ) def resetter_no_attr ( saved_value_internal ) : del saved_value_internal return delattr ( namespace , name ) def wrapper ( * args , ** kwargs ) : saved_value = None try : saved_value = getattr ( namespace , name ) resetter = resetter_attr except AttributeError : resetter = resetter_no_attr try : return func ( * args , ** kwargs ) finally : resetter ( saved_value ) wrapper . __name__ = func . __name__ wrapper . __doc__ = func . __doc__ return wrapper return decorator
function decorator to wrap a function that sets a namespace item .