source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/config/middleware.py @ 2484

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/trunk/ows_server/ows_server/config/middleware.py@2484
Revision 2484, 2.6 KB checked in by spascoe, 13 years ago (diff)

Created a dummy controller for testing the ows parameter parsing
features. It works :-)

Line 
1from paste import httpexceptions
2from paste.cascade import Cascade
3from paste.urlparser import StaticURLParser
4from paste.registry import RegistryManager
5from paste.deploy.config import ConfigMiddleware, CONFIG
6from paste.deploy.converters import asbool
7
8from pylons.error import error_template
9from pylons.middleware import ErrorHandler, ErrorDocuments, StaticJavascripts, error_mapper
10import pylons.wsgiapp
11
12from ows_server.config.environment import load_environment
13import ows_server.lib.helpers
14import ows_server.lib.app_globals as app_globals
15
16def make_app(global_conf, full_stack=True, **app_conf):
17    """Create a WSGI application and return it
18   
19    global_conf is a dict representing the Paste configuration options, the
20    paste.deploy.converters should be used when parsing Paste config options
21    to ensure they're treated properly.
22   
23    """
24    # Setup the Paste CONFIG object, adding app_conf/global_conf for legacy code
25    conf = global_conf.copy()
26    conf.update(app_conf)
27    conf.update(dict(app_conf=app_conf, global_conf=global_conf))
28    CONFIG.push_process_config(conf)
29
30    # Load our Pylons configuration defaults
31    config = load_environment(global_conf, app_conf)
32    config.init_app(global_conf, app_conf, package='ows_server',
33                    template_engine='kid')
34       
35    # Load our default Pylons WSGI app and make g available
36    app = pylons.wsgiapp.PylonsApp(config, helpers=ows_server.lib.helpers,
37                                   g=app_globals.Globals)
38    g = app.globals
39    app = ConfigMiddleware(app, conf)
40   
41    # YOUR MIDDLEWARE
42    # Put your own middleware here, so that any problems are caught by the error
43    # handling middleware underneath
44   
45    # If errror handling and exception catching will be handled by middleware
46    # for multiple apps, you will want to set full_stack = False in your config
47    # file so that it can catch the problems.
48    if asbool(full_stack):
49        # Change HTTPExceptions to HTTP responses
50        app = httpexceptions.make_middleware(app, global_conf)
51   
52        # Error Handling
53        app = ErrorHandler(app, global_conf, error_template=error_template, **config.errorware)
54   
55        # Display error documents for 401, 403, 404 status codes (if debug is disabled also
56        # intercepts 500)
57        #app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf)
58   
59    # Establish the Registry for this application
60    app = RegistryManager(app)
61   
62    static_app = StaticURLParser(config.paths['static_files'])
63    javascripts_app = StaticJavascripts()
64    app = Cascade([static_app, javascripts_app, app])
65    return app
Note: See TracBrowser for help on using the repository browser.