[Checkins] SVN: hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/wsgi.py The hurry.resource.wsgi injector middlware informs the wrappend application of the possible presence of a resource publisher

Jan-Jaap Driessen jdriessen at thehealthagency.com
Sun Nov 14 09:38:45 EST 2010


Log message for revision 118400:
  The hurry.resource.wsgi injector middlware informs the wrappend application of the possible presence of a resource publisher

Changed:
  U   hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/wsgi.py

-=-
Modified: hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/wsgi.py
===================================================================
--- hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/wsgi.py	2010-11-14 14:37:00 UTC (rev 118399)
+++ hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/wsgi.py	2010-11-14 14:38:43 UTC (rev 118400)
@@ -1,8 +1,8 @@
 import webob
 
-import hurry.resource
+NEEDED = 'hurry.resource.needed'
+PUBLISHER_PREFIX = 'hurry.resource.publisher_prefix'
 
-KEY = 'hurry.resource.needed'
 
 # TODO: would be nice to make middleware smarter so it could work with
 # a streamed HTML body instead of serializing it out to body. That
@@ -11,12 +11,18 @@
 
 class InjectMiddleWare(object):
 
-    def __init__(self, application):
+    def __init__(self, application, publisher_prefix=None):
         self.application = application
+        self.publisher_prefix = publisher_prefix
 
     def __call__(self, environ, start_response):
         request = webob.Request(environ)
 
+        if self.publisher_prefix is not None:
+            # Inform the wrapped application of the presence of a resource
+            # publisher and resource URLs may thus be routed to this publisher.
+            environ[PUBLISHER_PREFIX] = self.publisher_prefix
+
         # Get the response from the wrapped application:
         response = request.get_response(self.application)
 
@@ -25,13 +31,13 @@
         if not response.content_type.lower() in ['text/html', 'text/xml']:
             return response(environ, start_response)
 
-        # The rest of the WSGI stack may have left information in the
-        # neededinclusions.
-        needed = response.environ.get(KEY)
+        # The wrapped application may have left information in the environment
+        # about needed inclusions.
+        needed = response.environ.get(NEEDED)
         if needed is not None:
             response.body = needed.render_topbottom_into_html(response.body)
         return response(environ, start_response)
 
 
 def make_inject(app, global_config, **local_config):
-    return InjectMiddleWare(app)
+    return InjectMiddleWare(app, **local_config)



More information about the checkins mailing list