From 8e87498aaab23b6130ed644ab0bc57b93bbeaf46 Mon Sep 17 00:00:00 2001 From: Fabio Miranda Costa Date: Wed, 21 Dec 2011 16:36:13 -0300 Subject: [PATCH 1/2] removing some unnecessary imports --- django_pyvows/context.py | 6 ++---- django_pyvows/server.py | 4 +--- django_pyvows/settings_manager.py | 5 ++--- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/django_pyvows/context.py b/django_pyvows/context.py index 3d73a07..e1dd2ab 100644 --- a/django_pyvows/context.py +++ b/django_pyvows/context.py @@ -32,24 +32,21 @@ class DjangoContext(Vows.Context): os.environ['DJANGO_SETTINGS_MODULE'] = settings_path settings_tracker.install() - def __init__(self, parent): super(DjangoContext, self).__init__(parent) self.ignore('get_settings', 'template', 'request', 'model', 'url', 'find_in_parent', 'start_environment', 'port', 'host', 'get_url', 'get', 'post') - @property def settings(self): thread = current_thread() - if not hasattr(thread, "settings"): + if not hasattr(thread, 'settings'): thread.settings = local() return thread.settings def setup(self): DjangoContext.start_environment(self.get_settings()) - def get_settings(self): if 'DJANGO_SETTINGS_MODULE' in os.environ: return os.environ['DJANGO_SETTINGS_MODULE'] @@ -88,6 +85,7 @@ class DjangoContext(Vows.Context): except ValueError: return path + class DjangoHTTPContext(DjangoContext): def start_server(self, host=None, port=None): diff --git a/django_pyvows/server.py b/django_pyvows/server.py index 1324c73..cfe03a8 100644 --- a/django_pyvows/server.py +++ b/django_pyvows/server.py @@ -14,11 +14,8 @@ import urllib2 from threading import Thread, local, current_thread from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler -from pyvows import Vows -from django.http import HttpRequest from django.core.handlers.wsgi import WSGIHandler -from django_pyvows.assertions import Url, Model, Template class WSGIRequestHandler(BaseHTTPRequestHandler): """A request handler that implements WSGI dispatching.""" @@ -132,6 +129,7 @@ class DjangoServer(HTTPServer, object): setattr(thread.settings, key, value) while True: self.handle_request() + self.thr = Thread(target=make_response) self.thr.daemon = True self.thr.start() diff --git a/django_pyvows/settings_manager.py b/django_pyvows/settings_manager.py index aa4af67..f8365cf 100644 --- a/django_pyvows/settings_manager.py +++ b/django_pyvows/settings_manager.py @@ -8,7 +8,6 @@ # http://www.opensource.org/licenses/mit-license # Copyright (c) 2011 Rafael Caricio rafael@caricio.com -import sys from threading import current_thread class SettingsTracker(object): @@ -24,7 +23,7 @@ class SettingsTracker(object): fromlist = (fromlist or []) if name == 'django.conf' and 'settings' in fromlist: result.settings = VowsSettings(result.settings) - elif name == "django" and 'conf' in fromlist: + elif name == 'django' and 'conf' in fromlist: result.conf.settings = VowsSettings(result.conf.settings) return result @@ -35,7 +34,7 @@ class VowsSettings(object): def __getattr__(self, attr_name): thread = current_thread() - if hasattr(thread, "settings"): + if hasattr(thread, 'settings'): if hasattr(thread.settings, attr_name): return getattr(thread.settings, attr_name) return getattr(self.original_settings, attr_name) -- 2.34.1 From d2d8c7e3c2937cb10dc38b71969c93b2fa97bf7b Mon Sep 17 00:00:00 2001 From: Fabio Miranda Costa Date: Wed, 21 Dec 2011 16:38:27 -0300 Subject: [PATCH 2/2] fix, if the settings is a threading.local() instance it does not have the items() function, but its iterable through the __dict__ property --- django_pyvows/server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_pyvows/server.py b/django_pyvows/server.py index cfe03a8..ce76aec 100644 --- a/django_pyvows/server.py +++ b/django_pyvows/server.py @@ -125,7 +125,7 @@ class DjangoServer(HTTPServer, object): thread = current_thread() if not hasattr(thread, "settings"): thread.settings = local() - for key, value in settings.items(): + for key, value in getattr(settings, '__dict__', settings).items(): setattr(thread.settings, key, value) while True: self.handle_request() -- 2.34.1