new settings module
authorKenneth Reitz <me@kennethreitz.com>
Fri, 20 May 2011 16:53:20 +0000 (12:53 -0400)
committerKenneth Reitz <me@kennethreitz.com>
Fri, 20 May 2011 16:54:42 +0000 (12:54 -0400)
requests/core.py
requests/settings.py [new file with mode: 0644]

index 84e6ac4..fb239f2 100644 (file)
@@ -19,7 +19,7 @@ __license__ = 'ISC'
 __copyright__ = 'Copyright 2011 Kenneth Reitz'
 
 
-
 from models import HTTPError, auth_manager
 from api import *
 from exceptions import *
+from settings import *
\ No newline at end of file
diff --git a/requests/settings.py b/requests/settings.py
new file mode 100644 (file)
index 0000000..00e27d6
--- /dev/null
@@ -0,0 +1,39 @@
+# -*- coding: utf-8 -*-
+
+"""
+requests.settings
+~~~~~~~~~~~~~~~~~
+
+This module provides the Requests settings feature set.
+
+"""
+
+
+class Settings(object):
+
+    def __init__(self, **settings):
+        self._cache_settings(**settings)
+        self._alter_settings(**settings)
+
+    def __enter__(self):
+        pass
+
+    def __exit__(self, type, value, traceback):
+        self._restore_settings()
+
+    def _cache_settings(self, **settings):
+        self.cache = {}
+        for setting in settings:
+            self.cache[setting] = globals()[setting]
+
+    def _alter_settings(self, **settings):
+        for setting, value in settings.items():
+            globals()[setting] = value
+
+    def _restore_settings(self):
+        for setting, value in self.cache.items():
+            globals()[setting] = value
+
+
+settings = Settings
+timeout = None
\ No newline at end of file