Mercurial > public > src > rhodecode
annotate pylons_app/config/middleware.py @ 43:2e1247e62c5b
changed for pylons 0.1 / 1.0
added admin controller
author | marcink |
---|---|
date | Wed, 07 Apr 2010 15:28:50 +0200 |
parents | 71ffa932799d |
children | 9db7782727b3 |
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 |
0 | 11 from pylons_app.config.environment import load_environment |
41
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
12 from pylons_app.lib.auth import authfunc |
12 | 13 |
43 | 14 def make_app(global_conf, full_stack=True, static_files=True, **app_conf): |
0 | 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`` | |
12 | 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. | |
0 | 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 | |
43 | 34 config = load_environment(global_conf, app_conf) |
35 | |
0 | 36 |
37 # The Pylons WSGI app | |
43 | 38 app = PylonsApp(config=config) |
0 | 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) |
41
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
45 app = AuthBasicHandler(app, config['repos_name'] + ' mercurial repository', authfunc) |
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
46 |
0 | 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']): | |
14 | 54 #don't handle 404, since mercurial does it for us. |
43 | 55 app = StatusCodeRedirect(app, [400, 401, 403]) |
0 | 56 else: |
14 | 57 app = StatusCodeRedirect(app, [400, 401, 403, 500]) |
41
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
31
diff
changeset
|
58 |
0 | 59 # Establish the Registry for this application |
60 app = RegistryManager(app) | |
61 | |
43 | 62 if asbool(static_files): |
63 # Serve static files | |
64 static_app = StaticURLParser(config['pylons.paths']['static_files']) | |
65 app = Cascade([static_app, app]) | |
66 | |
67 app.config = config | |
68 | |
12 | 69 return app |
0 | 70 |