mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
defaults
This commit is contained in:
+6
-6
@@ -36,12 +36,12 @@ def request(method, url, **kwargs):
|
||||
"""
|
||||
data = kwargs.pop('data', dict()) or kwargs.pop('params', dict())
|
||||
|
||||
r = Request(method=method, url=url, data=data, headers=kwargs.pop('headers', {}),
|
||||
cookiejar=kwargs.pop('cookies', None),
|
||||
files=kwargs.pop('files', None),
|
||||
auth=kwargs.pop('auth', auth_manager.get_auth(url)),
|
||||
timeout=kwargs.pop('timeout', config.settings.timeout),
|
||||
allow_redirects=kwargs.pop('allow_redirects', None)
|
||||
r = Request(method=method, url=url, data=data, headers=kwargs.pop('headers', dict()),
|
||||
cookiejar=kwargs.get('cookies', None),
|
||||
files=kwargs.get('files', None),
|
||||
auth=kwargs.get('auth', auth_manager.get_auth(url)),
|
||||
timeout=kwargs.get('timeout', config.settings.timeout),
|
||||
allow_redirects=kwargs.get('allow_redirects', None)
|
||||
)
|
||||
|
||||
r.send()
|
||||
|
||||
@@ -26,6 +26,7 @@ class Settings(object):
|
||||
|
||||
# cache previous settings for __exit__
|
||||
r.__cache = self.__dict__.copy()
|
||||
map(self.__cache.setdefault, self.__attrs__)
|
||||
|
||||
# set new settings
|
||||
self.__dict__.update(*args, **kwargs)
|
||||
@@ -40,6 +41,7 @@ class Settings(object):
|
||||
def __exit__(self, *args):
|
||||
|
||||
# restore cached copy
|
||||
print '>>> {0}'.format(self.__cache)
|
||||
self.__dict__.update(self.__cache.copy())
|
||||
del self.__cache
|
||||
|
||||
|
||||
Reference in New Issue
Block a user