-
Notifications
You must be signed in to change notification settings - Fork 76
/
middleware_def_engine.py
57 lines (45 loc) · 2.34 KB
/
middleware_def_engine.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from paste import httpexceptions
from paste.cascade import Cascade
from paste.urlparser import StaticURLParser
from paste.registry import RegistryManager
from paste.deploy.config import ConfigMiddleware, CONFIG
from paste.deploy.converters import asbool
from pylons.error import error_template
from pylons import config
from pylons.middleware import ErrorHandler, ErrorDocuments, StaticJavascripts, error_mapper
import pylons.wsgiapp
import projectname.lib.helpers
import projectname.lib.app_globals as app_globals
from projectname.config.environment import load_environment
def make_app(global_conf, full_stack=True, **app_conf):
"""Create a WSGI application and return it
global_conf is a dict representing the Paste configuration options, the
paste.deploy.converters should be used when parsing Paste config options
to ensure they're treated properly.
"""
load_environment(global_conf, app_conf)
# Pull the other engine and put a new one up first
config.template_engines.pop()
kidopts = {'kid.assume_encoding':'utf-8', 'kid.encoding':'utf-8'}
pylons.config.add_template_engine('kid', 'projectname.kidtemplates', kidopts)
# Load our default Pylons WSGI app and make g available
app = pylons.wsgiapp.PylonsApp(helpers=projectname.lib.helpers,
g=app_globals.Globals)
app = ConfigMiddleware(app, config._current_obj())
# If errror handling and exception catching will be handled by middleware
# for multiple apps, you will want to set full_stack = False in your config
# file so that it can catch the problems.
if asbool(full_stack):
# Change HTTPExceptions to HTTP responses
app = httpexceptions.make_middleware(app, global_conf)
# Error Handling
app = ErrorHandler(app, global_conf, error_template=error_template, **config['pylons.errorware'])
# Display error documents for 401, 403, 404 status codes (if debug is disabled also
# intercepts 500)
app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf)
# Establish the Registry for this application
app = RegistryManager(app)
static_app = StaticURLParser(config['pylons.paths']['static_files'])
javascripts_app = StaticJavascripts()
app = Cascade([static_app, javascripts_app, app])
return app