def FlagOverrider(**flag_kwargs):
 def Decorator(f):
  'Allow a function to safely change flags, restoring them on return.'
  def Decorated(*args, **kwargs):
   global FLAGS
   old_flags = copy.copy(FLAGS)
   for (k, v) in flag_kwargs.items():
    setattr(FLAGS, k, v)
   try:
    return f(*args, **kwargs)
   finally:
    FLAGS = old_flags
  return Decorated
 return Decorator

def FlagOverrider ( ** flag_kwargs ) : def Decorator ( f ) : def Decorated ( * args , ** kwargs ) : global FLAGS old_flags = copy . copy ( FLAGS ) for ( k , v ) in flag_kwargs . items ( ) : setattr ( FLAGS , k , v ) try : return f ( * args , ** kwargs ) finally : FLAGS = old_flags return Decorated return Decorator
a helpful decorator which can switch the flag values temporarily .