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

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

Upgrade the server code to make consistent with newer pylons codebase - v0.9.6.1.
This mainly involves the replacement of the Response object, and associated methods,
with the inbuild, default response object. Typical changes include:

render_response -> render - with required settings on the response object
made before the render call against the response object

Response(...) -> response.write() - for content + response.headers.. = .. for headers info

  • also included the replacement of depricated functions, as highlighted by

the server logging

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 import config
9from pylons.error import error_template
10from pylons.middleware import ErrorHandler, ErrorDocuments, StaticJavascripts, error_mapper
11from pylons.wsgiapp import PylonsApp
12
13from ows_server.config.environment import load_environment
14
15from ows_server.config.ndgMiddleware import ndgMiddleware
16
17# Logging doesn't need configuring if you have paste.translogger in your config file.
18#import logging
19
20def make_app(global_conf, full_stack=True, **app_conf):
21    """Create a WSGI application and return it
22   
23    global_conf is a dict representing the Paste configuration options, the
24    paste.deploy.converters should be used when parsing Paste config options
25    to ensure they're treated properly.
26   
27    """
28    # Setup the Paste CONFIG object, adding app_conf/global_conf for legacy code
29    conf = global_conf.copy()
30    conf.update(app_conf)
31    conf.update(dict(app_conf=app_conf, global_conf=global_conf))
32    CONFIG.push_process_config(conf)
33
34    # Load our Pylons configuration defaults
35    load_environment(global_conf, app_conf)
36       
37    # Load our default Pylons WSGI app and make g available
38    app = PylonsApp()
39    g = app.globals
40    app = ConfigMiddleware(app, conf)
41   
42    # YOUR MIDDLEWARE
43    # Put your own middleware here, so that any problems are caught by the error
44    # handling middleware underneath
45
46    app = ndgMiddleware(app,g)
47    g=app.globals
48   
49    # Configure logging
50    #logging.basicConfig(format='%(thread)s %(name)s %(levelname)s %(message)s')
51   
52    # If errror handling and exception catching will be handled by middleware
53    # for multiple apps, you will want to set full_stack = False in your config
54    # file so that it can catch the problems.
55    if asbool(full_stack):
56        # Change HTTPExceptions to HTTP responses
57        app = httpexceptions.make_middleware(app, global_conf)
58   
59        # Error Handling
60        app = ErrorHandler(app, global_conf, error_template=error_template, **config['pylons.errorware'])
61   
62        # Display error documents for 401, 403, 404 status codes (if debug is disabled also
63        # intercepts 500)
64        #app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf)
65   
66    # Establish the Registry for this application
67    app = RegistryManager(app)
68   
69    # Allow static files from outside the egg too ... g.htdocs defined in ndgDiscovery.config
70    if g.htdocs:
71        static_paths = [g.htdocs,config['pylons.paths']['static_files']]
72    else: static_paths= [config['pylons.paths']['static_files']]
73    static_app = [StaticURLParser(path) for path in static_paths]
74    javascripts_app = StaticJavascripts()
75    app = Cascade(static_app +[javascripts_app, app])
76    return app
Note: See TracBrowser for help on using the repository browser.