source: cowsserver/branches/migrate-py26-pylons10/lib/cowsserver/config/middleware.py @ 7482

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cowsserver/branches/migrate-py26-pylons10/lib/cowsserver/config/middleware.py@7482
Revision 7482, 2.4 KB checked in by astephen, 11 years ago (diff)

config/middleware.py file updated to mirror standard pylons 1.0 version.
Also removed the switch for compatibility with pylons versions before
version 0.9.7.

Line 
1"""Pylons middleware initialization"""
2from beaker.middleware import SessionMiddleware
3from paste.cascade import Cascade
4from paste.registry import RegistryManager
5from paste.urlparser import StaticURLParser
6from paste.deploy.converters import asbool
7from pylons.middleware import ErrorHandler, StatusCodeRedirect
8from pylons.wsgiapp import PylonsApp
9from routes.middleware import RoutesMiddleware
10
11from cowsserver.config.environment import load_environment
12
13def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
14    """Create a Pylons WSGI application and return it
15
16    ``global_conf``
17        The inherited configuration for this application. Normally from
18        the [DEFAULT] section of the Paste ini file.
19
20    ``full_stack``
21        Whether this application provides a full WSGI stack (by default,
22        meaning it handles its own exceptions and errors). Disable
23        full_stack when this application is "managed" by another WSGI
24        middleware.
25
26    ``static_files``
27        Whether this application serves its own static files; disable
28        when another web server is responsible for serving them.
29
30    ``app_conf``
31        The application's local configuration. Normally specified in
32        the [app:<name>] section of the Paste ini file (where <name>
33        defaults to main).
34
35    """
36
37    # Configure the Pylons environment
38    config = load_environment(global_conf, app_conf)
39
40    # The Pylons WSGI app
41    app = PylonsApp(config=config)
42
43    # Routing/Session Middleware
44    app = RoutesMiddleware(app, config['routes.map'], singleton=False)
45    app = SessionMiddleware(app, config)
46
47    # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
48
49    if asbool(full_stack):
50        # Handle Python exceptions
51        app = ErrorHandler(app, global_conf, **config['pylons.errorware'])
52
53        # Display error documents for 401, 403, 404 status codes (and
54        # 500 when debug is disabled)
55        if asbool(config['debug']):
56            app = StatusCodeRedirect(app)
57        else:
58            app = StatusCodeRedirect(app, [400, 401, 403, 404, 500])
59
60    # Establish the Registry for this application
61    app = RegistryManager(app)
62
63    if asbool(static_files):
64        # Serve static files
65        static_app = StaticURLParser(config['pylons.paths']['static_files'])
66        app = Cascade([static_app, app])
67    app.config = config
68
69    return app
Note: See TracBrowser for help on using the repository browser.