config.py => _config.py
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kenneth Reitz · committed by Kenneth Reitz · parent 185450c · Browse files · 2 files·+68 added−68 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+68 added−68 removed
- other:+68 added−68 removed
Provenance
- Commit
ab3200b- Tree
fb13e9d- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
185450c
2 files changed+68 added−68 removed
added:requests/_config.py+68 added
1+# -*- coding: utf-8 -*-2+3+"""4+requests.config5+~~~~~~~~~~~~~~~6+7+This module provides the Requests settings feature set.8+9+"""10+11+class Settings(object):12+ _singleton = {}13+14+ # attributes with defaults15+ __attrs__ = []16+17+ def __init__(self, **kwargs):18+ super(Settings, self).__init__()19+20+ self.__dict__ = self._singleton21+22+23+ def __call__(self, *args, **kwargs):24+ # new instance of class to call25+ r = self.__class__()26+27+ # cache previous settings for __exit__28+ r.__cache = self.__dict__.copy()29+ map(self.__cache.setdefault, self.__attrs__)30+31+ # set new settings32+ self.__dict__.update(*args, **kwargs)33+34+ return r35+36+37+ def __enter__(self):38+ pass39+40+41+ def __exit__(self, *args):42+43+ # restore cached copy44+ self.__dict__.update(self.__cache.copy())45+ del self.__cache46+47+48+ def __getattribute__(self, key):49+ if key in object.__getattribute__(self, '__attrs__'):50+ try:51+ return object.__getattribute__(self, key)52+ except AttributeError:53+ return None54+ return object.__getattribute__(self, key)55+56+57+settings = Settings()58+59+settings.base_headers = {'User-Agent': 'python-requests.org'}60+settings.accept_gzip = True61+settings.proxies = None62+settings.verbose = None63+settings.timeout = None64+settings.max_redirects = 3065+settings.decode_unicode = True66+67+#: Use socket.setdefaulttimeout() as fallback?68+settings.timeout_fallback = Truedeleted:requests/config.py-68 removed
1-# -*- coding: utf-8 -*-2-3-"""4-requests.config5-~~~~~~~~~~~~~~~6-7-This module provides the Requests settings feature set.8-9-"""10-11-class Settings(object):12- _singleton = {}13-14- # attributes with defaults15- __attrs__ = []16-17- def __init__(self, **kwargs):18- super(Settings, self).__init__()19-20- self.__dict__ = self._singleton21-22-23- def __call__(self, *args, **kwargs):24- # new instance of class to call25- r = self.__class__()26-27- # cache previous settings for __exit__28- r.__cache = self.__dict__.copy()29- map(self.__cache.setdefault, self.__attrs__)30-31- # set new settings32- self.__dict__.update(*args, **kwargs)33-34- return r35-36-37- def __enter__(self):38- pass39-40-41- def __exit__(self, *args):42-43- # restore cached copy44- self.__dict__.update(self.__cache.copy())45- del self.__cache46-47-48- def __getattribute__(self, key):49- if key in object.__getattribute__(self, '__attrs__'):50- try:51- return object.__getattribute__(self, key)52- except AttributeError:53- return None54- return object.__getattribute__(self, key)55-56-57-settings = Settings()58-59-settings.base_headers = {'User-Agent': 'python-requests.org'}60-settings.accept_gzip = True61-settings.proxies = None62-settings.verbose = None63-settings.timeout = None64-settings.max_redirects = 3065-settings.decode_unicode = True66-67-#: Use socket.setdefaulttimeout() as fallback?68-settings.timeout_fallback = True