removing some unnecessary imports

This commit is contained in:
Fabio Miranda Costa 2011-12-21 16:36:13 -03:00
parent 3f2ab0777a
commit 8e87498aaa
3 changed files with 5 additions and 10 deletions

View file

@ -32,24 +32,21 @@ class DjangoContext(Vows.Context):
os.environ['DJANGO_SETTINGS_MODULE'] = settings_path os.environ['DJANGO_SETTINGS_MODULE'] = settings_path
settings_tracker.install() settings_tracker.install()
def __init__(self, parent): def __init__(self, parent):
super(DjangoContext, self).__init__(parent) super(DjangoContext, self).__init__(parent)
self.ignore('get_settings', 'template', 'request', 'model', 'url', 'find_in_parent', self.ignore('get_settings', 'template', 'request', 'model', 'url', 'find_in_parent',
'start_environment', 'port', 'host', 'get_url', 'get', 'post') 'start_environment', 'port', 'host', 'get_url', 'get', 'post')
@property @property
def settings(self): def settings(self):
thread = current_thread() thread = current_thread()
if not hasattr(thread, "settings"): if not hasattr(thread, 'settings'):
thread.settings = local() thread.settings = local()
return thread.settings return thread.settings
def setup(self): def setup(self):
DjangoContext.start_environment(self.get_settings()) DjangoContext.start_environment(self.get_settings())
def get_settings(self): def get_settings(self):
if 'DJANGO_SETTINGS_MODULE' in os.environ: if 'DJANGO_SETTINGS_MODULE' in os.environ:
return os.environ['DJANGO_SETTINGS_MODULE'] return os.environ['DJANGO_SETTINGS_MODULE']
@ -88,6 +85,7 @@ class DjangoContext(Vows.Context):
except ValueError: except ValueError:
return path return path
class DjangoHTTPContext(DjangoContext): class DjangoHTTPContext(DjangoContext):
def start_server(self, host=None, port=None): def start_server(self, host=None, port=None):

View file

@ -14,11 +14,8 @@ import urllib2
from threading import Thread, local, current_thread from threading import Thread, local, current_thread
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from pyvows import Vows
from django.http import HttpRequest
from django.core.handlers.wsgi import WSGIHandler from django.core.handlers.wsgi import WSGIHandler
from django_pyvows.assertions import Url, Model, Template
class WSGIRequestHandler(BaseHTTPRequestHandler): class WSGIRequestHandler(BaseHTTPRequestHandler):
"""A request handler that implements WSGI dispatching.""" """A request handler that implements WSGI dispatching."""
@ -132,6 +129,7 @@ class DjangoServer(HTTPServer, object):
setattr(thread.settings, key, value) setattr(thread.settings, key, value)
while True: while True:
self.handle_request() self.handle_request()
self.thr = Thread(target=make_response) self.thr = Thread(target=make_response)
self.thr.daemon = True self.thr.daemon = True
self.thr.start() self.thr.start()

View file

@ -8,7 +8,6 @@
# http://www.opensource.org/licenses/mit-license # http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 Rafael Caricio rafael@caricio.com # Copyright (c) 2011 Rafael Caricio rafael@caricio.com
import sys
from threading import current_thread from threading import current_thread
class SettingsTracker(object): class SettingsTracker(object):
@ -24,7 +23,7 @@ class SettingsTracker(object):
fromlist = (fromlist or []) fromlist = (fromlist or [])
if name == 'django.conf' and 'settings' in fromlist: if name == 'django.conf' and 'settings' in fromlist:
result.settings = VowsSettings(result.settings) 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) result.conf.settings = VowsSettings(result.conf.settings)
return result return result
@ -35,7 +34,7 @@ class VowsSettings(object):
def __getattr__(self, attr_name): def __getattr__(self, attr_name):
thread = current_thread() thread = current_thread()
if hasattr(thread, "settings"): if hasattr(thread, 'settings'):
if hasattr(thread.settings, attr_name): if hasattr(thread.settings, attr_name):
return getattr(thread.settings, attr_name) return getattr(thread.settings, attr_name)
return getattr(self.original_settings, attr_name) return getattr(self.original_settings, attr_name)