WSGI Dispatcher

Overview

Development Status :: 4 - Beta
Intended Audience :: Developers
License :: OSI Approved :: GNU General Public License (GPL)
Operating System :: OS Independent
Programming Language :: Python
Topic :: Internet :: WWW/HTTP :: WSGI :: Middleware

The WSGI Dispatcher middleware does three things:

  1. It checks environ['wsgiorg.routing_args'] and invokes a WSGI application from a list of predefined directories if there is a match or a returns an HTTP 404.
  2. It checks environ['PATH_INFO'] for one or more predefined URLs and serves static content from corresponding directories.
  3. It checks environ['PATH_INFO'] for one or more predefined URLs and invokes WSGI applications (which may well be other dispatchers).

The dispatcher is intented to work behind WSGI URL parsers like Routes which parse request URLs and place named or positional arguments in environ['wsgiorg.routing_args'].

Download

WSGIDispatcher-0.3.tar.gz (Development Status :: 4 - Beta)

WSGIDispatcher-0.2.tar.gz (Development Status :: 4 - Beta)

WSGIDispatcher-0.1.tar.gz (Development Status :: 3 - Alpha)

Detailed Description

Constructor Arguments

The WSGI Dispatcher constructor accepts the following arguments:

Additional Functionality

Furthermore, the functionality of the dispatcher can be customised setting the following WSGI Dispatcher properties:

Serving Static Resources and Secondary Dispatching

Furthermore, the dispatcher uses Paste's URLMap to serve static content and/or to call other WSGI applications based on specific URLs.

For more information on the syntax of URLs (url) and the matching behaviour please refer to URLMap documentation.

Examples

      from paste.pony import PonyMiddleware
      from routes.middleware import Mapper, RoutesMiddleware
      # Mapper needed for Routes.
      from config.routing import mapper
      from wsgi_dispatcher import WSGIDispatcher

      # Define the routes using Routes here.
      mapper = Mapper()
      mapper.connect('/webapp', controller="webapp")
      mapper.create_regs('webapp')

      dispatcher = WSGIDispatcher(controller_dirs = ["controllers"])
      dispatcher.classname_transform_func=lambda x: x[0].upper() + x[1:]
      dispatcher.add_static_dir('/test/', 'public/static')
      app = RoutesMiddleware(dispatcher, mapper)