Mercurial > kallithea
annotate pylons_app/config/middleware.py @ 151:988477a05db6
moved sqlalchemy session to base.
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 15 May 2010 19:05:13 +0200 |
parents | 8b06c420491d |
children | 93bd77e1f3c1 |
rev | line source |
---|---|
0 | 1 """Pylons middleware initialization""" |
43 | 2 from beaker.middleware import SessionMiddleware |
0 | 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 | |
41
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
10 from paste.auth.basic import AuthBasicHandler |
101
8b06c420491d
statics moved to pylons.
Marcin Kuzminski <marcin@python-works.com>
parents:
86
diff
changeset
|
11 from pylons_app.lib.simplehg import SimpleHg |
0 | 12 from pylons_app.config.environment import load_environment |
41
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
13 from pylons_app.lib.auth import authfunc |
12 | 14 |
43 | 15 def make_app(global_conf, full_stack=True, static_files=True, **app_conf): |
0 | 16 """Create a Pylons WSGI application and return it |
17 | |
18 ``global_conf`` | |
19 The inherited configuration for this application. Normally from | |
20 the [DEFAULT] section of the Paste ini file. | |
21 | |
22 ``full_stack`` | |
12 | 23 Whether or not this application provides a full WSGI stack (by |
24 default, meaning it handles its own exceptions and errors). | |
25 Disable full_stack when this application is "managed" by | |
26 another WSGI middleware. | |
0 | 27 |
28 ``app_conf`` | |
29 The application's local configuration. Normally specified in | |
30 the [app:<name>] section of the Paste ini file (where <name> | |
31 defaults to main). | |
32 | |
33 """ | |
34 # Configure the Pylons environment | |
43 | 35 config = load_environment(global_conf, app_conf) |
36 | |
0 | 37 |
38 # The Pylons WSGI app | |
43 | 39 app = PylonsApp(config=config) |
0 | 40 |
101
8b06c420491d
statics moved to pylons.
Marcin Kuzminski <marcin@python-works.com>
parents:
86
diff
changeset
|
41 |
0 | 42 # Routing/Session/Cache Middleware |
43 app = RoutesMiddleware(app, config['routes.map']) | |
21 | 44 app = SessionMiddleware(app, config) |
101
8b06c420491d
statics moved to pylons.
Marcin Kuzminski <marcin@python-works.com>
parents:
86
diff
changeset
|
45 |
8b06c420491d
statics moved to pylons.
Marcin Kuzminski <marcin@python-works.com>
parents:
86
diff
changeset
|
46 # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) |
8b06c420491d
statics moved to pylons.
Marcin Kuzminski <marcin@python-works.com>
parents:
86
diff
changeset
|
47 app = SimpleHg(app, config) |
8b06c420491d
statics moved to pylons.
Marcin Kuzminski <marcin@python-works.com>
parents:
86
diff
changeset
|
48 app = AuthBasicHandler(app, config['repos_name'] + ' mercurial repository', authfunc) |
41
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
49 |
0 | 50 if asbool(full_stack): |
51 # Handle Python exceptions | |
52 app = ErrorHandler(app, global_conf, **config['pylons.errorware']) | |
53 | |
54 # Display error documents for 401, 403, 404 status codes (and | |
55 # 500 when debug is disabled) | |
56 if asbool(config['debug']): | |
86
e47d1db5ef20
Added few options to configs,
Marcin Kuzminski <marcin@python-blog.com>
parents:
49
diff
changeset
|
57 app = StatusCodeRedirect(app) |
0 | 58 else: |
86
e47d1db5ef20
Added few options to configs,
Marcin Kuzminski <marcin@python-blog.com>
parents:
49
diff
changeset
|
59 app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) |
41
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
60 |
0 | 61 # Establish the Registry for this application |
62 app = RegistryManager(app) | |
63 | |
43 | 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 | |
12 | 71 return app |
0 | 72 |