Skip to content
Myr

settings -> config

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

reimpliment settings as singleton

authored by Kenneth Reitz · committed by Kenneth Reitz · parent 0741448 · Browse files · 2 files+52 added−38 removed
This commit

State

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

Diff stats

2 files+52 added−38 removed

  • other:+52 added−38 removed

2 files+52 added−38 removed

added:requests/config.py+52 added
1# -*- coding: utf-8 -*-23"""4requests.config5~~~~~~~~~~~~~~~67This module provides the Requests settings feature set.89"""1011# Time (in seconds) to allow the request to connect to12# the remote host before timing it out.1314# timeout = None151617class Settings(object):18 _singleton = {}19 __attrs__ = ('timeout',)2021 def __init__(self, **kwargs):22 super(Settings, self).__init__()2324 self.__dict__ = self._singleton2526 def __getattribute__(self, key):27 if key in object.__getattribute__(self, '__attrs__'):28 try:29 return object.__getattribute__(self, key)30 except AttributeError:31 return None32 return object.__getattribute__(self, key)333435 def __enter__(self):36 pass3738 def __exit__(self, *args):3940 self.__dict__.update(self.__cache.copy())41 del self.__cache424344 def __call__(self, *args, **kwargs):45 r = self.__class__()46 r.__cache = self.__dict__.copy()47 self.__dict__.update(*args, **kwargs)4849 return r505152settings = Settings()
deleted:requests/settings.py-38 removed
1# -*- coding: utf-8 -*-23"""4requests.settings5~~~~~~~~~~~~~~~~~67This module provides the Requests settings feature set.89"""1011# Time (in seconds) to allow the request to connect to12# the remote host before timing it out.13timeout = None1415class Settings(object):1617 def __init__(self, **settings):18 self._cache_settings(**settings)19 self._alter_settings(**settings)2021 def __enter__(self):22 pass2324 def __exit__(self, type, value, traceback):25 self._restore_settings()2627 def _cache_settings(self, **settings):28 self.cache = {}29 for setting in settings:30 self.cache[setting] = globals()[setting]3132 def _alter_settings(self, **settings):33 for setting, value in settings.items():34 globals()[setting] = value3536 def _restore_settings(self):37 for setting, value in self.cache.items():38 globals()[setting] = value