From: Kenneth Reitz Date: Sat, 22 Oct 2011 23:41:39 +0000 (-0400) Subject: config.py => _config.py X-Git-Tag: v0.7.0~6^2~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ab3200b4cc1fd2bec915a47aafa48a9d1a4774ed;p=services%2Fpython-requests.git config.py => _config.py --- diff --git a/requests/_config.py b/requests/_config.py new file mode 100644 index 0000000..794109c --- /dev/null +++ b/requests/_config.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- + +""" +requests.config +~~~~~~~~~~~~~~~ + +This module provides the Requests settings feature set. + +""" + +class Settings(object): + _singleton = {} + + # attributes with defaults + __attrs__ = [] + + def __init__(self, **kwargs): + super(Settings, self).__init__() + + self.__dict__ = self._singleton + + + def __call__(self, *args, **kwargs): + # new instance of class to call + r = self.__class__() + + # cache previous settings for __exit__ + r.__cache = self.__dict__.copy() + map(self.__cache.setdefault, self.__attrs__) + + # set new settings + self.__dict__.update(*args, **kwargs) + + return r + + + def __enter__(self): + pass + + + def __exit__(self, *args): + + # restore cached copy + self.__dict__.update(self.__cache.copy()) + del self.__cache + + + def __getattribute__(self, key): + if key in object.__getattribute__(self, '__attrs__'): + try: + return object.__getattribute__(self, key) + except AttributeError: + return None + return object.__getattribute__(self, key) + + +settings = Settings() + +settings.base_headers = {'User-Agent': 'python-requests.org'} +settings.accept_gzip = True +settings.proxies = None +settings.verbose = None +settings.timeout = None +settings.max_redirects = 30 +settings.decode_unicode = True + +#: Use socket.setdefaulttimeout() as fallback? +settings.timeout_fallback = True diff --git a/requests/config.py b/requests/config.py deleted file mode 100644 index 794109c..0000000 --- a/requests/config.py +++ /dev/null @@ -1,68 +0,0 @@ -# -*- coding: utf-8 -*- - -""" -requests.config -~~~~~~~~~~~~~~~ - -This module provides the Requests settings feature set. - -""" - -class Settings(object): - _singleton = {} - - # attributes with defaults - __attrs__ = [] - - def __init__(self, **kwargs): - super(Settings, self).__init__() - - self.__dict__ = self._singleton - - - def __call__(self, *args, **kwargs): - # new instance of class to call - r = self.__class__() - - # cache previous settings for __exit__ - r.__cache = self.__dict__.copy() - map(self.__cache.setdefault, self.__attrs__) - - # set new settings - self.__dict__.update(*args, **kwargs) - - return r - - - def __enter__(self): - pass - - - def __exit__(self, *args): - - # restore cached copy - self.__dict__.update(self.__cache.copy()) - del self.__cache - - - def __getattribute__(self, key): - if key in object.__getattribute__(self, '__attrs__'): - try: - return object.__getattribute__(self, key) - except AttributeError: - return None - return object.__getattribute__(self, key) - - -settings = Settings() - -settings.base_headers = {'User-Agent': 'python-requests.org'} -settings.accept_gzip = True -settings.proxies = None -settings.verbose = None -settings.timeout = None -settings.max_redirects = 30 -settings.decode_unicode = True - -#: Use socket.setdefaulttimeout() as fallback? -settings.timeout_fallback = True