source: cowsclient/branches/migrate-py26-pylons10/cowsclient/config/middleware.py @ 7348

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cowsclient/branches/migrate-py26-pylons10/cowsclient/config/middleware.py@7348
Revision 7348, 1.8 KB checked in by spascoe, 10 years ago (diff)

Various controller and template upgrades for Pylons-1.0

Line 
1"""Pylons middleware initialization"""
2from paste.cascade import Cascade
3from paste.registry import RegistryManager
4from paste.urlparser import StaticURLParser
5from paste.deploy.converters import asbool
6
7from beaker.middleware import SessionMiddleware
8from routes.middleware import RoutesMiddleware
9
10from pylons.middleware import ErrorHandler
11
12from pylons.wsgiapp import PylonsApp
13
14from cowsclient.config.environment import load_environment
15
16def make_app(global_conf, full_stack=True, **app_conf):
17    """Create a Pylons WSGI application and return it
18
19    ``global_conf``
20        The inherited configuration for this application. Normally from
21        the [DEFAULT] section of the Paste ini file.
22
23    ``full_stack``
24        Whether or not this application provides a full WSGI stack (by
25        default, meaning it handles its own exceptions and errors).
26        Disable full_stack when this application is "managed" by
27        another WSGI middleware.
28
29    ``app_conf``
30        The application's local configuration. Normally specified in the
31        [app:<name>] section of the Paste ini file (where <name>
32        defaults to main).
33    """
34    # Configure the Pylons environment
35    config = load_environment(global_conf, app_conf)
36
37    # The Pylons WSGI app
38    app = PylonsApp(config=config)
39
40    app = RoutesMiddleware(app, config['routes.map'])
41    app = SessionMiddleware(app, config)
42
43    # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
44
45    if asbool(full_stack):
46        # Handle Python exceptions
47        app = ErrorHandler(app, global_conf, **config['pylons.errorware'])
48
49    # Establish the Registry for this application
50    app = RegistryManager(app)
51
52    # Static files
53    static_app = StaticURLParser(config['pylons.paths']['static_files'])
54    app = Cascade([static_app, app])
55    app.config = config
56
57    return app
Note: See TracBrowser for help on using the repository browser.