Mercurial > kallithea
comparison rhodecode/config/middleware.py @ 547:1e757ac98988
renamed project to rhodecode
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 06 Oct 2010 03:18:16 +0200 |
parents | pylons_app/config/middleware.py@1ef52a70f3b7 |
children | fd63782c4426 |
comparison
equal
deleted
inserted
replaced
546:7c2f5e4d7bbf | 547:1e757ac98988 |
---|---|
1 """Pylons middleware initialization""" | |
2 from beaker.middleware import SessionMiddleware | |
3 from paste.cascade import Cascade | |
4 from paste.registry import RegistryManager | |
5 from paste.urlparser import StaticURLParser | |
6 from paste.deploy.converters import asbool | |
7 from pylons.middleware import ErrorHandler, StatusCodeRedirect | |
8 from pylons.wsgiapp import PylonsApp | |
9 from routes.middleware import RoutesMiddleware | |
10 from rhodecode.lib.middleware.simplehg import SimpleHg | |
11 from rhodecode.lib.middleware.https_fixup import HttpsFixup | |
12 from rhodecode.config.environment import load_environment | |
13 | |
14 def make_app(global_conf, full_stack=True, static_files=True, **app_conf): | |
15 """Create a Pylons WSGI application and return it | |
16 | |
17 ``global_conf`` | |
18 The inherited configuration for this application. Normally from | |
19 the [DEFAULT] section of the Paste ini file. | |
20 | |
21 ``full_stack`` | |
22 Whether or not this application provides a full WSGI stack (by | |
23 default, meaning it handles its own exceptions and errors). | |
24 Disable full_stack when this application is "managed" by | |
25 another WSGI middleware. | |
26 | |
27 ``app_conf`` | |
28 The application's local configuration. Normally specified in | |
29 the [app:<name>] section of the Paste ini file (where <name> | |
30 defaults to main). | |
31 | |
32 """ | |
33 # Configure the Pylons environment | |
34 config = load_environment(global_conf, app_conf) | |
35 | |
36 # The Pylons WSGI app | |
37 app = PylonsApp(config=config) | |
38 | |
39 # Routing/Session/Cache Middleware | |
40 app = RoutesMiddleware(app, config['routes.map']) | |
41 app = SessionMiddleware(app, config) | |
42 | |
43 # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) | |
44 | |
45 app = SimpleHg(app, config) | |
46 | |
47 if asbool(full_stack): | |
48 # Handle Python exceptions | |
49 app = ErrorHandler(app, global_conf, **config['pylons.errorware']) | |
50 | |
51 # Display error documents for 401, 403, 404 status codes (and | |
52 # 500 when debug is disabled) | |
53 if asbool(config['debug']): | |
54 app = StatusCodeRedirect(app) | |
55 else: | |
56 app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) | |
57 | |
58 #enable https redirets based on HTTP_X_URL_SCHEME set by proxy | |
59 app = HttpsFixup(app) | |
60 | |
61 # Establish the Registry for this application | |
62 app = RegistryManager(app) | |
63 | |
64 if asbool(static_files): | |
65 # Serve static files | |
66 static_app = StaticURLParser(config['pylons.paths']['static_files']) | |
67 app = Cascade([static_app, app]) | |
68 | |
69 app.config = config | |
70 | |
71 return app | |
72 |