[z3-checkins] r55523 - z3/deliverance/sandboxes/paul/environ

paul at codespeak.net paul at codespeak.net
Tue Jun 3 17:17:28 CEST 2008


Author: paul
Date: Tue Jun  3 17:17:27 2008
New Revision: 55523

Added:
   z3/deliverance/sandboxes/paul/environ/
   z3/deliverance/sandboxes/paul/environ/README.txt
   z3/deliverance/sandboxes/paul/environ/run.sh
   z3/deliverance/sandboxes/paul/environ/serve.ini
   z3/deliverance/sandboxes/paul/environ/switcher.py
Log:
Test case to show filter ordering and setup

Added: z3/deliverance/sandboxes/paul/environ/README.txt
==============================================================================
--- (empty file)
+++ z3/deliverance/sandboxes/paul/environ/README.txt	Tue Jun  3 17:17:27 2008
@@ -0,0 +1,37 @@
+========================================
+Filter chaining for Paste Pipelines
+========================================
+
+This module tests ordering of execution for filters in a Paste
+pipeline.  To run:
+
+1) Make sure ``paster`` is in your PATH.
+
+2) Execute ``PYTHONPATH=. paster serve serve.ini``
+
+Purpose
+--------------
+
+This testbed was created to try and figure out how to get middleware
+filters that correctly trigger a key in ``environ`` to choose the
+theme.  It has proven a challenge to correctly affect the environ used
+when Deliverance is run.  Do you put a filter to the "left" of
+Deliverance in a pipeline or to the right?
+
+As such, this test case just tries to show how filters can be setup
+and executed.
+
+Here is the output you get when starting the Paste server::
+
+  PYTHONPATH=. paster serve serve.ini
+  Creating filter right
+  Creating filter left
+  Starting server in PID 3410.
+  serving on http://127.0.0.1:8080
+
+Here is what you get when you go to a URL such as
+``http://localhost:8080/`` (any URL on 8080 will do):
+
+  In __call__ for filter left
+  In __call__ for filter right
+  In echo

Added: z3/deliverance/sandboxes/paul/environ/run.sh
==============================================================================
--- (empty file)
+++ z3/deliverance/sandboxes/paul/environ/run.sh	Tue Jun  3 17:17:27 2008
@@ -0,0 +1,2 @@
+
+PYTHONPATH=.:/Users/paul/projects/deliverance/trunk paster serve serve.ini
\ No newline at end of file

Added: z3/deliverance/sandboxes/paul/environ/serve.ini
==============================================================================
--- (empty file)
+++ z3/deliverance/sandboxes/paul/environ/serve.ini	Tue Jun  3 17:17:27 2008
@@ -0,0 +1,18 @@
+[server:main]
+use = egg:Paste#http
+
+[pipeline:main]
+pipeline = egg:Paste#evalerror
+	 egg:Paste#httpexceptions
+	 left
+	 right
+	 echo
+
+[app:echo]
+paste.app_factory = switcher:make_echo
+
+[filter:left]
+paste.filter_app_factory = switcher:make_left
+
+[filter:right]
+paste.filter_app_factory = switcher:make_right

Added: z3/deliverance/sandboxes/paul/environ/switcher.py
==============================================================================
--- (empty file)
+++ z3/deliverance/sandboxes/paul/environ/switcher.py	Tue Jun  3 17:17:27 2008
@@ -0,0 +1,33 @@
+from wsgifilter import Filter
+
+class Switcher(object):
+
+    def __init__(self, app, filtername):
+        self.app = app
+        self.filtername = filtername
+        print "Creating filter", filtername
+
+    def __call__(self, environ, start_response):
+        environ[self.filtername] = self.filtername
+        print "In __call__ for filter", self.filtername
+        response_iter = self.app(environ, start_response)
+        return response_iter
+
+def make_left(app, global_conf, **kw):
+    """Choose which Deliverance theme should be used"""
+
+    return Switcher(app, "left")
+
+def make_right(app, global_conf, **kw):
+    """Choose which Deliverance theme should be used"""
+
+    return Switcher(app, "right")
+
+def echo(environ, start_response):  
+    start_response("200 OK", [('Content-type', 'text/html')])
+    print "In echo"
+    return ["<h2>Hello World</h2>"]
+      
+
+def make_echo(global_config, **local_conf):
+    return echo


More information about the z3-checkins mailing list