[Checkins] SVN: Sandbox/shane/republish/zope/pipeline/ Added the switch and passthrough applications.

Shane Hathaway shane at hathawaymix.org
Wed Feb 11 13:48:43 EST 2009


Log message for revision 96451:
  Added the switch and passthrough applications.
  

Changed:
  U   Sandbox/shane/republish/zope/pipeline/configure.zcml
  A   Sandbox/shane/republish/zope/pipeline/passthrough.py
  A   Sandbox/shane/republish/zope/pipeline/switch.py
  U   Sandbox/shane/republish/zope/pipeline/zcml.py

-=-
Modified: Sandbox/shane/republish/zope/pipeline/configure.zcml
===================================================================
--- Sandbox/shane/republish/zope/pipeline/configure.zcml	2009-02-11 18:01:30 UTC (rev 96450)
+++ Sandbox/shane/republish/zope/pipeline/configure.zcml	2009-02-11 18:48:43 UTC (rev 96451)
@@ -1,15 +1,18 @@
-<configuration>
+<configure xmlns="http://namespaces.zope.org/zope"
+           xmlns:wsgi="http://namespaces.zope.org/wsgi">
 
-<!-- a wsgi:stage-list directive registers a bound StageList.adapt() method
-     as an unnamed adapter from the request type to IStageList. -->
+<!-- a wsgi:application-list directive specifies the names of
+     applications to use in a pipeline.  Its implementation
+     registers a bound ApplicationList.adapt() method as an
+     unnamed adapter from the request type to IApplicationList. -->
 
-<wsgi:app-list for=".interfaces.IUndecidedRequest" names="
+<wsgi:application-list for=".interfaces.IUndecidedRequest" names="
     retry
     request_factory
-    pipeline_pivot
+    switch
     " />
 
-<wsgi:app-list for="zope.publisher.interfaces.IRequest" names="
+<wsgi:application-list for="zope.publisher.interfaces.IRequest" names="
     logger
     root_opener
     transaction_controller
@@ -21,51 +24,50 @@
     caller
     " />
 
-<!-- a wsgi:pipeline directive registers a bound Pipeline.adapt() method as
-     an adapter from the request type to IWSGIApplication with name
-     "pipeline". -->
+<!-- a wsgi:pipeline directive creates a pipeline for a particular
+     request type.  Its implementation registers a bound
+     Pipeline.adapt() method as an adapter from the request type
+     to IWSGIApplication with name "pipeline". -->
 
 <wsgi:pipeline for=".interfaces.IUndecidedRequest" />
 <wsgi:pipeline for="zope.publisher.interfaces.IRequest" />
 <wsgi:pipeline for="zope.publisher.interfaces.http.IHTTPRequest" />
 <wsgi:pipeline for="zope.publisher.interfaces.browser.IBrowserRequest" />
 
-<!-- a wsgi:middleware directive is like an adapter directive,
+<!-- a wsgi:middleware directive registers an application for use
+     as middleware in a pipeline.  It is like an adapter directive,
      except that the adapter is registered as requiring
-     two parameters, 'app' and 'request', while only the app is
-     provided to the application factory; the factory is wrapped
+     two parameters, 'app' and 'request', while only the 'app' parameter is
+     provided to the middleware factory; the factory is wrapped
      to make that happen.  If neither the directive nor the factory
      says what kind of request is required, assume IRequest. -->
 
 <wsgi:middleware
     factory=".retry.Retry"
-    name="retry" />
+    name="retry"
+    for=".interfaces.INoRequest" />
 
-<!-- a wsgi:application directive is like an adapter directive,
-     except that the adapter is registered as requiring
+<wsgi:middleware
+    factory="..."
+    name="request_factory"
+    for=".interfaces.INoRequest" />
+
+<!-- a wsgi:application directive registers an application for use
+     as the final application in a pipeline.  It is like an adapter
+     directive, except that the adapter is registered as requiring
      one parameter, 'request', while no parameters are passed to the
      application factory; the factory is wrapped
      to make that happen.  If neither the directive nor the factory
      says what kind of request is required, assume IRequest. -->
 
 <wsgi:application
-    factory=".caller.Caller"
-    name="caller" />
+    factory=".switch.Switch"
+    name="switch"
+    for=".interfaces.INoRequest" />
 
-<wsgi:middleware
-    factory=".retry.Retry"
-    name="retry" />
 
 <wsgi:middleware
     factory="..."
-    name="request_factory" />
-
-<wsgi:application
-    factory="..."
-    name="pipeline_pivot" />
-
-<wsgi:middleware
-    factory="..."
     name="logger" />
 
 <wsgi:middleware
@@ -96,11 +98,15 @@
     factory=".txnctl.TransactionAnnotator"
     name="transaction_annotator" />
 
+<wsgi:application
+    factory=".caller.Caller"
+    name="caller" />
 
-</configuration>
 
+</configure>
 
 
+
 <!--
     # other possible stages:
     # RequestProfiler

Added: Sandbox/shane/republish/zope/pipeline/passthrough.py
===================================================================
--- Sandbox/shane/republish/zope/pipeline/passthrough.py	                        (rev 0)
+++ Sandbox/shane/republish/zope/pipeline/passthrough.py	2009-02-11 18:48:43 UTC (rev 96451)
@@ -0,0 +1,10 @@
+
+
+def passthrough(app):
+    """A passthrough application.
+
+    Use this to skip a pipeline step.  Register this function
+    as the middleware factory for a step you don't want to use.
+    The step will be eliminated even from application stack traces.
+    """
+    return app

Added: Sandbox/shane/republish/zope/pipeline/switch.py
===================================================================
--- Sandbox/shane/republish/zope/pipeline/switch.py	                        (rev 0)
+++ Sandbox/shane/republish/zope/pipeline/switch.py	2009-02-11 18:48:43 UTC (rev 96451)
@@ -0,0 +1,19 @@
+
+
+from zope.interface import implements
+from zope.publisher.interfaces import IWSGIApplication
+
+class Switch(object):
+    """WSGI application that switches to a pipeline based on the request type.
+
+    Requires 'zope.request' in the environment.
+    """
+    implements(IWSGIApplication)
+
+    def __call__(self, environ, start_response):
+        request = environ['zope.request']
+        app = IWSGIApplication(request, name='pipeline')
+        return app(environ, start_response)
+
+    def __repr__(self):
+        return '%s()' % self.__class__.__name__

Modified: Sandbox/shane/republish/zope/pipeline/zcml.py
===================================================================
--- Sandbox/shane/republish/zope/pipeline/zcml.py	2009-02-11 18:01:30 UTC (rev 96450)
+++ Sandbox/shane/republish/zope/pipeline/zcml.py	2009-02-11 18:48:43 UTC (rev 96451)
@@ -30,6 +30,7 @@
 from zope.publisher.interfaces import IWSGIApplication
 from zope.publisher.interfaces import IRequest
 
+
 class IApplicationListDirective(Interface):
     """Declare a list of application names in a WSGI pipeline"""
 
@@ -45,6 +46,7 @@
             'the rest declare a middleware application.'),
         required=True)
 
+
 class IPipelineDirective(Interface):
     """Declare a WSGI pipeline"""
 
@@ -53,6 +55,7 @@
         description=_('The type of request that should use this pipeline'),
         required=True)
 
+
 class IApplicationDirective(Interface):
     """Declare a simple WSGI application for use at the end of a pipeline"""
 
@@ -74,14 +77,17 @@
         required=False,
         )
 
+
 class IMiddlewareDirective(IApplicationDirective):
     """Declare a middleware WSGI application for use in a pipeline"""
     # same schema as IApplicationDirective
     pass
 
+
 class IApplicationList(Interface):
     names = Attribute("Application names to use in a pipeline")
 
+
 class ApplicationList(object):
     implements(IApplicationList)
 
@@ -92,6 +98,7 @@
         """Called by adapter lookup"""
         return self
 
+
 class MarkerRequest(object):
     """A marker object that claims to provide a request type.
 
@@ -102,12 +109,13 @@
     def __init__(self, request_type):
         directlyProvides(self, request_type)
 
+
 class Pipeline(object):
     implements(IWSGIApplication)
 
     def __init__(self, request_type):
+        self.request_type = request_type
         self.app = None
-        self.request_type = request_type
 
     def adapt(self, request):
         """Called by adapter lookup"""
@@ -131,6 +139,13 @@
                 (app, marker_req), IWSGIApplication, name=name)
         return app
 
+    def __repr__(self):
+        if self.app is None:
+            self.app = self.make_app()
+        return '%s(%s, app=%s)' % (
+            self.__class__.__name__, repr(self.request_type), repr(self.app))
+
+
 def application_list(_context, for_, names):
     """Register an application list"""
     obj = ApplicationList(names)



More information about the Checkins mailing list