Skip to content
Myr

Refactor settings

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Johannes Gorset · committed by Johannes Gorset · parent 8ffb246 · Browse files · 1 file+17 added−13 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+17 added−13 removed

  • other:+17 added−13 removed

1 file+17 added−13 removed

modified:requests/__init__.py+17 added-13 removed
8 unmodified lines
910timeout = None1112class settings:13 """Context manager for settings."""13 15 cache = {}16 17 def __init__(self, timeout):18 self.module = inspect.getmodule(self)14 def __init__(self, **settings):15 self._cache_settings(**settings)16 self._alter_settings(**settings)17 20 # Cache settings21 self.cache['timeout'] = self.module.timeout22 23 self.module.timeout = timeout24 18 def __enter__(self):19 pass20 21 def __exit__(self, type, value, traceback):29 # Restore settings 30 for key in self.cache:31 setattr(self.module, key, self.cache[key])22 self._restore_settings()23 24 def _cache_settings(self, **settings):25 self.cache = {}26 for setting in settings:27 self.cache[setting] = globals()[setting]28 29 def _alter_settings(self, **settings):30 for setting, value in settings.items():31 globals()[setting] = value32 33 def _restore_settings(self):34 for setting, value in self.cache.items():35 globals()[setting] = value