moksha/lib/helpers.py | 17 ++++++++++++++++- moksha/middleware/middleware.py | 27 ++------------------------- moksha/streams/demo/demostream.py | 7 +++++-- moksha/wsgiapp.py | 16 ++++++++++++++-- setup.cfg | 3 --- 5 files changed, 37 insertions(+), 33 deletions(-)
New commits: commit e0528280793047005ff0e61edde1af4f2cec3d8b Author: Luke Macken lmacken@redhat.com Date: Mon May 11 09:42:04 2009 -0400
Make all requests go through our MokshaAppDispatcher(PylonsApp).
This ensures that Pylons will setup all of the proper globals, such as the pylons.request object, etc. This will allow connectors to utilize the global Beaker cache, instead of creating their own. It will also allow connectors to utilize other connectors.
diff --git a/moksha/middleware/middleware.py b/moksha/middleware/middleware.py index 730c5e4..d11b23a 100644 --- a/moksha/middleware/middleware.py +++ b/moksha/middleware/middleware.py @@ -51,7 +51,7 @@ class MokshaMiddleware(object): def __init__(self, application): log.info('Creating Moksha Middleware') self.application = application - self.mokshaapp = MokshaAppDispatcher() + self.mokshaapp = MokshaAppDispatcher(application)
moksha.apps = {} # {'app name': tg.TGController/tg.WSGIAppController} moksha._widgets = {} # {'widget name': tw.api.Widget} @@ -72,17 +72,7 @@ class MokshaMiddleware(object):
def __call__(self, environ, start_response): self.register_stomp(environ) - request = Request(environ) - - path = self.strip_script(environ, request.path) - if path.startswith('/apps/') or \ - path.startswith('/widget') or \ - path.startswith('/docs/') or \ - path.startswith('/moksha_admin/'): - response = request.get_response(self.mokshaapp) - else: - response = request.get_response(self.application) - return response(environ, start_response) + return self.mokshaapp(environ, start_response)
def register_stomp(self, environ): environ['paste.registry'].register(moksha.stomp, { diff --git a/moksha/wsgiapp.py b/moksha/wsgiapp.py index e52be49..4047d4f 100644 --- a/moksha/wsgiapp.py +++ b/moksha/wsgiapp.py @@ -16,8 +16,11 @@ # # Authors: Luke Macken lmacken@redhat.com
+from pylons import request from pylons.wsgiapp import PylonsApp
+from moksha.lib.helpers import strip_script + class MokshaAppDispatcher(PylonsApp): """ Moksha WSGI Application Dispatcher.
@@ -27,10 +30,11 @@ class MokshaAppDispatcher(PylonsApp): """ root = None
- def __init__(self): + def __init__(self, application): super(MokshaAppDispatcher, self).__init__() from moksha.controllers.root import RootController self.root = RootController + self.application = application
def resolve(self, environ, start_response): """ Uses dispatching information found in @@ -40,4 +44,12 @@ class MokshaAppDispatcher(PylonsApp):
""" environ['pylons.routes_dict'] = environ['wsgiorg.routing_args'][1] - return self.root() + path = strip_script(environ) + if path.startswith('/apps/') or \ + path.startswith('/widget') or \ + path.startswith('/docs/') or \ + path.startswith('/moksha_admin/'): + return self.root() + else: + return self.application +
commit a2aaa3ad9ee137865da2db0e5f4a880207dab02f Author: Luke Macken lmacken@redhat.com Date: Mon May 11 09:41:26 2009 -0400
Move the strip_script method to moksha.lib.helpers.
Also, remove the request argument, as we can obtain that data from the environ['PATH_INFO']
diff --git a/moksha/lib/helpers.py b/moksha/lib/helpers.py index 18ddb2f..757c8b7 100644 --- a/moksha/lib/helpers.py +++ b/moksha/lib/helpers.py @@ -875,4 +875,19 @@ class EnumGroup(object): def __getitem__(self, key): (category, enum_id) = key.rsplit('.', 1) enum = self._enums[category] - return enum.get_data(key) \ No newline at end of file + return enum.get_data(key) + + +def strip_script(environ): + """ + Strips the script portion of a url path so the middleware works even + when mounted under a path other than root. + """ + path = environ['PATH_INFO'] + if path.startswith('/') and 'SCRIPT_NAME' in environ: + prefix = environ.get('SCRIPT_NAME') + if prefix.endswith('/'): + prefix = prefix[:-1] + if path.startswith(prefix): + path = path[len(prefix):] + return path diff --git a/moksha/middleware/middleware.py b/moksha/middleware/middleware.py index 5638d86..730c5e4 100644 --- a/moksha/middleware/middleware.py +++ b/moksha/middleware/middleware.py @@ -70,19 +70,6 @@ class MokshaMiddleware(object): moksha.feed_storage = Shove(config['feed_cache'], compress=True) moksha.feed_cache = Cache(moksha.feed_storage)
- def strip_script(self, environ, path): - # Strips the script portion of a url path so the middleware works even - # when mounted under a path other than root - if path.startswith('/') and 'SCRIPT_NAME' in environ: - prefix = environ.get('SCRIPT_NAME') - if prefix.endswith('/'): - prefix = prefix[:-1] - - if path.startswith(prefix): - path = path[len(prefix):] - - return path - def __call__(self, environ, start_response): self.register_stomp(environ) request = Request(environ)
commit 9166cdc9a76b870cb546d75e2d206d60f88f6435 Author: Luke Macken lmacken@redhat.com Date: Mon May 11 05:51:28 2009 -0400
Move our demo's feed initialization into __init__
diff --git a/moksha/streams/demo/demostream.py b/moksha/streams/demo/demostream.py index e0a2d63..0ed742e 100644 --- a/moksha/streams/demo/demostream.py +++ b/moksha/streams/demo/demostream.py @@ -35,10 +35,13 @@ class MokshaDemoDataStream(PollingDataStream): n = 0
# Feed demo specific variables - feed = Feed(url='http://doggdot.us/rss') - feed_entries = feed.entries() i = 0
+ def __init__(self, *args, **kw): + self.feed = Feed(url='http://doggdot.us/rss') + self.feed_entries = self.feed.entries() + super(MokshaDemoDataStream, self).__init__(*args, **kw) + def poll(self): self.n += 1
diff --git a/setup.cfg b/setup.cfg index 08503a6..6d798d1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -5,9 +5,6 @@ tag_svn_revision = true [easy_install] find_links = http://www.pylonshq.com/download/
-[nosetests] -with-pylons=test.ini - # Babel configuration [compile_catalog] domain = moksha
moksha-commits@lists.fedorahosted.org