Mercurial > kallithea
annotate pylons_app/config/middleware.py @ 41:71ffa932799d
Added app basic auth.
Changed few deprecations for new pylons.
added sqlite logging for user actions.
author | Marcin Kuzminski <marcin@python-blog.com> |
---|---|
date | Wed, 07 Apr 2010 00:51:55 +0200 |
parents | 2963f2894a7a |
children | 2e1247e62c5b |
rev | line source |
---|---|
0 | 1 """Pylons middleware initialization""" |
2 from beaker.middleware import CacheMiddleware, 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 import config | |
8 from pylons.middleware import ErrorHandler, StatusCodeRedirect | |
9 from pylons.wsgiapp import PylonsApp | |
10 from routes.middleware import RoutesMiddleware | |
41
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
11 from paste.auth.basic import AuthBasicHandler |
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 |
31
2963f2894a7a
Tempalting change, bugfix for serving raw files, and diffs. Now raw files are not parsed thruough mako, and diffs are mako safe (not parsed also)
Marcin Kuzminski <marcin@python-blog.com>
parents:
21
diff
changeset
|
15 def make_app(global_conf, full_stack=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 | |
35 load_environment(global_conf, app_conf) | |
36 | |
37 # The Pylons WSGI app | |
38 app = PylonsApp() | |
39 | |
12 | 40 # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) |
41 | |
0 | 42 # Routing/Session/Cache Middleware |
43 app = RoutesMiddleware(app, config['routes.map']) | |
21 | 44 app = SessionMiddleware(app, config) |
45 app = CacheMiddleware(app, config) | |
41
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
46 app = AuthBasicHandler(app, config['repos_name'] + ' mercurial repository', authfunc) |
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
47 |
0 | 48 if asbool(full_stack): |
49 # Handle Python exceptions | |
50 app = ErrorHandler(app, global_conf, **config['pylons.errorware']) | |
51 | |
52 # Display error documents for 401, 403, 404 status codes (and | |
53 # 500 when debug is disabled) | |
54 if asbool(config['debug']): | |
14 | 55 #don't handle 404, since mercurial does it for us. |
56 app = StatusCodeRedirect(app, [400, 401, 403, 500]) | |
0 | 57 else: |
14 | 58 app = StatusCodeRedirect(app, [400, 401, 403, 500]) |
41
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
59 |
0 | 60 # Establish the Registry for this application |
61 app = RegistryManager(app) | |
62 | |
12 | 63 # Static files (If running in production, and Apache or another web |
64 # server is handling this static content, remove the following 3 lines) | |
65 static_app = StaticURLParser(config['pylons.paths']['static_files']) | |
66 app = Cascade([static_app, app]) | |
67 return app | |
0 | 68 |