Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate settings to new module #35

Merged
merged 3 commits into from
May 21, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions requests/__init__.py
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions requests/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

"""

import requests
import settings
from .models import Request, Response, AuthManager, AuthObject, auth_manager


Expand All @@ -37,7 +37,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))
timeout=kwargs.pop('timeout', settings.timeout))

r.send()

return r.response
Expand Down
2 changes: 1 addition & 1 deletion requests/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
from models import HTTPError, auth_manager
from api import *
from exceptions import *
from settings import *
from settings import Settings as settings
7 changes: 3 additions & 4 deletions requests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

"""

# Time (in seconds) to allow the request to connect to
# the remote host before timing it out.
timeout = None

class Settings(object):

Expand All @@ -33,7 +36,3 @@ def _alter_settings(self, **settings):
def _restore_settings(self):
for setting, value in self.cache.items():
globals()[setting] = value


settings = Settings
timeout = None