annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
1 """Pylons middleware initialization"""
43
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
2 from beaker.middleware import SessionMiddleware
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
3 from paste.cascade import Cascade
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
4 from paste.registry import RegistryManager
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
5 from paste.urlparser import StaticURLParser
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
6 from paste.deploy.converters import asbool
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
7 from pylons.middleware import ErrorHandler, StatusCodeRedirect
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
8 from pylons.wsgiapp import PylonsApp
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
9 from routes.middleware import RoutesMiddleware
547
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 341
diff changeset
10 from rhodecode.lib.middleware.simplehg import SimpleHg
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 341
diff changeset
11 from rhodecode.lib.middleware.https_fixup import HttpsFixup
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 341
diff changeset
12 from rhodecode.config.environment import load_environment
12
5f30a6d558dc Added pylons manage script
Marcin Kuzminski
parents: 10
diff changeset
13
43
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
14 def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
15 """Create a Pylons WSGI application and return it
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
16
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
17 ``global_conf``
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
18 The inherited configuration for this application. Normally from
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
19 the [DEFAULT] section of the Paste ini file.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
20
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
21 ``full_stack``
12
5f30a6d558dc Added pylons manage script
Marcin Kuzminski
parents: 10
diff changeset
22 Whether or not this application provides a full WSGI stack (by
5f30a6d558dc Added pylons manage script
Marcin Kuzminski
parents: 10
diff changeset
23 default, meaning it handles its own exceptions and errors).
5f30a6d558dc Added pylons manage script
Marcin Kuzminski
parents: 10
diff changeset
24 Disable full_stack when this application is "managed" by
5f30a6d558dc Added pylons manage script
Marcin Kuzminski
parents: 10
diff changeset
25 another WSGI middleware.
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
26
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
27 ``app_conf``
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
28 The application's local configuration. Normally specified in
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
29 the [app:<name>] section of the Paste ini file (where <name>
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
30 defaults to main).
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
31
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
32 """
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
33 # Configure the Pylons environment
43
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
34 config = load_environment(global_conf, app_conf)
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
35
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
36 # The Pylons WSGI app
43
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
37 app = PylonsApp(config=config)
101
8b06c420491d statics moved to pylons.
Marcin Kuzminski <marcin@python-works.com>
parents: 86
diff changeset
38
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
39 # Routing/Session/Cache Middleware
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
40 app = RoutesMiddleware(app, config['routes.map'])
21
fac1f62a1d71 Wrapped into mako templates,
Marcin Kuzminski
parents: 17
diff changeset
41 app = SessionMiddleware(app, config)
101
8b06c420491d statics moved to pylons.
Marcin Kuzminski <marcin@python-works.com>
parents: 86
diff changeset
42
204
a8ea3ce3cdc4 Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents: 203
diff changeset
43 # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
207
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 204
diff changeset
44
101
8b06c420491d statics moved to pylons.
Marcin Kuzminski <marcin@python-works.com>
parents: 86
diff changeset
45 app = SimpleHg(app, config)
41
71ffa932799d Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents: 31
diff changeset
46
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
47 if asbool(full_stack):
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
48 # Handle Python exceptions
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
49 app = ErrorHandler(app, global_conf, **config['pylons.errorware'])
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
50
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
51 # Display error documents for 401, 403, 404 status codes (and
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
52 # 500 when debug is disabled)
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
53 if asbool(config['debug']):
86
e47d1db5ef20 Added few options to configs,
Marcin Kuzminski <marcin@python-blog.com>
parents: 49
diff changeset
54 app = StatusCodeRedirect(app)
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
55 else:
86
e47d1db5ef20 Added few options to configs,
Marcin Kuzminski <marcin@python-blog.com>
parents: 49
diff changeset
56 app = StatusCodeRedirect(app, [400, 401, 403, 404, 500])
41
71ffa932799d Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents: 31
diff changeset
57
216
c8162373f214 Cleaned the way based was used to generate submenu for admin, now it's much more clear to use submenu. Cleaned admin and added comment to middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 207
diff changeset
58 #enable https redirets based on HTTP_X_URL_SCHEME set by proxy
207
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 204
diff changeset
59 app = HttpsFixup(app)
216
c8162373f214 Cleaned the way based was used to generate submenu for admin, now it's much more clear to use submenu. Cleaned admin and added comment to middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 207
diff changeset
60
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
61 # Establish the Registry for this application
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
62 app = RegistryManager(app)
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
63
43
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
64 if asbool(static_files):
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
65 # Serve static files
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
66 static_app = StaticURLParser(config['pylons.paths']['static_files'])
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
67 app = Cascade([static_app, app])
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
68
269
183c06406127 fixed bug in middleware config
Marcin Kuzminski <marcin@python-works.com>
parents: 216
diff changeset
69 app.config = config
43
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
70
12
5f30a6d558dc Added pylons manage script
Marcin Kuzminski
parents: 10
diff changeset
71 return app
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
72