mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
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:
@@ -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
@@ -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
@@ -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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user