1 # Copyright 2014 The Swarming Authors. All rights reserved.
2 # Use of this source code is governed under the Apache License, Version 2.0 that
3 # can be found in the LICENSE file.
10 """Context manager for environment variables.
12 Passed a dict to the constructor it sets variables named with the key to the
13 value. Exiting the context causes all the variables named with the key to be
14 restored to their value before entering the context.
16 def __init__(self, var_map):
17 self.var_map = var_map
21 self._backup = os.environ
22 os.environ = os.environ.copy()
23 os.environ.update(self.var_map)
25 def __exit__(self, exc_type, exc_value, traceback):
26 os.environ = self._backup
30 """Returns current process umask without modifying it."""
33 _UMASK = os.umask(0777)