aboutsummaryrefslogtreecommitdiff
path: root/requests/config.py
diff options
context:
space:
mode:
authorSVN-Git Migration <python-modules-team@lists.alioth.debian.org>2015-10-08 13:41:15 -0700
committerSVN-Git Migration <python-modules-team@lists.alioth.debian.org>2015-10-08 13:41:15 -0700
commit4fad8c1375c73a3d4483fe78e4534c7dabc453f5 (patch)
treecd9f3e8c6811892a2cea932b9d1d97b41945b712 /requests/config.py
downloadpython-requests-4fad8c1375c73a3d4483fe78e4534c7dabc453f5.tar
python-requests-4fad8c1375c73a3d4483fe78e4534c7dabc453f5.tar.gz
Imported Upstream version 0.4.1
Diffstat (limited to 'requests/config.py')
-rw-r--r--requests/config.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/requests/config.py b/requests/config.py
new file mode 100644
index 0000000..63d3fa9
--- /dev/null
+++ b/requests/config.py
@@ -0,0 +1,56 @@
+# -*- coding: utf-8 -*-
+
+"""
+requests.config
+~~~~~~~~~~~~~~~
+
+This module provides the Requests settings feature set.
+
+"""
+
+class Settings(object):
+ _singleton = {}
+
+ # attributes with defaults
+ __attrs__ = ('timeout',)
+
+ 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() \ No newline at end of file