diff wsgintegrate/dispatcher.py @ 0:ec815b7cb142

initial commit of wsgintegrate
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 07 Jun 2011 08:03:09 -0700
parents
children 88b611ed2c5e
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wsgintegrate/dispatcher.py	Tue Jun 07 08:03:09 2011 -0700
@@ -0,0 +1,26 @@
+"""
+multi-application dispatcher for WSGI apps
+"""
+
+from webob import Request
+from webob import exc
+
+class Dispatcher(object):
+
+  def __init__(self, *apps):
+    self.apps = apps
+    self.codes = set([404])
+
+  def __call__(self, environ, start_response):
+    request = Request(environ)
+    for app in self.apps:
+      try:
+        response = request.get_response(app)
+        if response.status_int in self.codes:
+          continue
+        break
+      except exc.HTTPNotFound:
+        continue
+    else:
+      response = exc.HTTPNotFound()
+    return response(environ, start_response)