1 | from paste import httpexceptions |
---|
2 | from paste.cascade import Cascade |
---|
3 | from paste.urlparser import StaticURLParser |
---|
4 | from paste.registry import RegistryManager |
---|
5 | from paste.deploy.config import ConfigMiddleware, CONFIG |
---|
6 | from paste.deploy.converters import asbool |
---|
7 | |
---|
8 | from pylons.error import error_template |
---|
9 | from pylons.middleware import ErrorHandler, ErrorDocuments, StaticJavascripts, error_mapper |
---|
10 | import pylons.wsgiapp |
---|
11 | |
---|
12 | from ows_server.config.environment import load_environment |
---|
13 | import ows_server.lib.helpers |
---|
14 | import ows_server.lib.app_globals as app_globals |
---|
15 | |
---|
16 | def 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 | |
---|
34 | # Load our default Pylons WSGI app and make g available |
---|
35 | app = pylons.wsgiapp.PylonsApp(config, helpers=ows_server.lib.helpers, |
---|
36 | g=app_globals.Globals) |
---|
37 | g = app.globals |
---|
38 | app = ConfigMiddleware(app, conf) |
---|
39 | |
---|
40 | # YOUR MIDDLEWARE |
---|
41 | # Put your own middleware here, so that any problems are caught by the error |
---|
42 | # handling middleware underneath |
---|
43 | |
---|
44 | # If errror handling and exception catching will be handled by middleware |
---|
45 | # for multiple apps, you will want to set full_stack = False in your config |
---|
46 | # file so that it can catch the problems. |
---|
47 | if asbool(full_stack): |
---|
48 | # Change HTTPExceptions to HTTP responses |
---|
49 | app = httpexceptions.make_middleware(app, global_conf) |
---|
50 | |
---|
51 | # Error Handling |
---|
52 | app = ErrorHandler(app, global_conf, error_template=error_template, **config.errorware) |
---|
53 | |
---|
54 | # Display error documents for 401, 403, 404 status codes (if debug is disabled also |
---|
55 | # intercepts 500) |
---|
56 | app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf) |
---|
57 | |
---|
58 | # Establish the Registry for this application |
---|
59 | app = RegistryManager(app) |
---|
60 | |
---|
61 | static_app = StaticURLParser(config.paths['static_files']) |
---|
62 | javascripts_app = StaticJavascripts() |
---|
63 | app = Cascade([static_app, javascripts_app, app]) |
---|
64 | return app |
---|