cleanup — comments

This commit is contained in:
Kenneth Reitz
2011-05-22 13:31:09 -04:00
parent 982fd9d803
commit f887906ec3
+27 -24
View File
@@ -8,14 +8,10 @@ This module provides the Requests settings feature set.
"""
# Time (in seconds) to allow the request to connect to
# the remote host before timing it out.
# timeout = None
class Settings(object):
_singleton = {}
# attributes with defaults
__attrs__ = ('timeout',)
def __init__(self, **kwargs):
@@ -23,6 +19,31 @@ class Settings(object):
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()
# 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:
@@ -31,22 +52,4 @@ class Settings(object):
return None
return object.__getattribute__(self, key)
def __enter__(self):
pass
def __exit__(self, *args):
self.__dict__.update(self.__cache.copy())
del self.__cache
def __call__(self, *args, **kwargs):
r = self.__class__()
r.__cache = self.__dict__.copy()
self.__dict__.update(*args, **kwargs)
return r
settings = Settings()