Merge pull request #35 from jgorset/requests

---

Ive completed the migration of the requests settings to the new `settings` module, but my attempt to facilitate for manipulating settings outside of the context manager (eg. `requests.settings.timeout = 5`) has been thwarted by the namespace collision of the context manager and the module.

Im probably just being stupid. Youll figure it out.

Conflicts:
	requests/api.py
This commit is contained in:
Kenneth Reitz
2011-05-21 13:04:32 -04:00
4 changed files with 7 additions and 37 deletions
-29
View File
@@ -1,35 +1,6 @@
# -*- coding: utf-8 -*-
import inspect
import packages
from core import *
from core import __version__
timeout = None
class settings:
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
+3 -3
View File
@@ -12,6 +12,7 @@ This module impliments the Requests API.
"""
import requests
import settings
from .models import Request, Response, AuthManager, AuthObject, auth_manager
@@ -38,9 +39,8 @@ def request(method, url, **kwargs):
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', requests.timeout),
allow_redirects=kwargs.pop('allow_redirects', requests.timeout)
)
timeout=kwargs.pop('timeout', settings.timeout))
r.send()
return r.response
+1 -1
View File
@@ -22,4 +22,4 @@ __copyright__ = 'Copyright 2011 Kenneth Reitz'
from models import HTTPError, auth_manager
from api import *
from exceptions import *
from settings import *
from settings import Settings as settings
+3 -4
View File
@@ -8,6 +8,9 @@ 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):
@@ -33,7 +36,3 @@ class Settings(object):
def _restore_settings(self):
for setting, value in self.cache.items():
globals()[setting] = value
settings = Settings
timeout = None