view wsgintegrate/dispatcher.py @ 11:88b611ed2c5e

debugging code
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 14 Jul 2011 00:05:39 -0700
parents ec815b7cb142
children e07b0f675c17
line wrap: on
line source

"""
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
      except:
        print app
        raise
    else:
      response = exc.HTTPNotFound()
    return response(environ, start_response)