source: TI12-security/trunk/NDGSecurity/python/Tests/ndgsecuredpylons/ndgsecuredpylons/config/middleware.py @ 7080

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDGSecurity/python/Tests/ndgsecuredpylons/ndgsecuredpylons/config/middleware.py@7080
Revision 7080, 2.0 KB checked in by pjkersha, 9 years ago (diff)
  • Property svn:keywords set to Id
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 pylons import config
8from pylons.error import error_template
9from pylons.middleware import error_mapper, ErrorDocuments, ErrorHandler, \
10    StaticJavascripts
11from pylons.wsgiapp import PylonsApp
12
13from ndgsecuredpylons.config.environment import load_environment
14
15def make_app(global_conf, full_stack=True, **app_conf):
16    """Create a Pylons WSGI application and return it
17
18    ``global_conf``
19        The inherited configuration for this application. Normally from
20        the [DEFAULT] section of the Paste ini file.
21
22    ``full_stack``
23        Whether or not this application provides a full WSGI stack (by
24        default, meaning it handles its own exceptions and errors).
25        Disable full_stack when this application is "managed" by
26        another WSGI middleware.
27
28    ``app_conf``
29        The application's local configuration. Normally specified in the
30        [app:<name>] section of the Paste ini file (where <name>
31        defaults to main).
32    """
33    # Configure the Pylons environment
34    load_environment(global_conf, app_conf)
35
36    # The Pylons WSGI app
37    app = PylonsApp()
38
39    # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
40
41    if asbool(full_stack):
42        # Handle Python exceptions
43        app = ErrorHandler(app, global_conf, error_template=error_template,
44                           **config['pylons.errorware'])
45
46        # Display error documents for 401, 403, 404 status codes (and
47        # 500 when debug is disabled)
48        app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf)
49
50    # Establish the Registry for this application
51    app = RegistryManager(app)
52
53    # Static files
54    javascripts_app = StaticJavascripts()
55    static_app = StaticURLParser(config['pylons.paths']['static_files'])
56    app = Cascade([static_app, javascripts_app, app])
57    return app
Note: See TracBrowser for help on using the repository browser.