Show More
@@ -1,74 +1,74 b'' | |||||
1 | """Pylons middleware initialization""" |
|
1 | """Pylons middleware initialization""" | |
2 | from beaker.middleware import CacheMiddleware, SessionMiddleware |
|
2 | from beaker.middleware import CacheMiddleware, SessionMiddleware | |
3 | from paste.cascade import Cascade |
|
3 | from paste.cascade import Cascade | |
4 | from paste.registry import RegistryManager |
|
4 | from paste.registry import RegistryManager | |
5 | from paste.urlparser import StaticURLParser |
|
5 | from paste.urlparser import StaticURLParser | |
6 | from paste.deploy.converters import asbool |
|
6 | from paste.deploy.converters import asbool | |
7 | from pylons import config |
|
7 | from pylons import config | |
8 | from pylons.middleware import ErrorHandler, StatusCodeRedirect |
|
8 | from pylons.middleware import ErrorHandler, StatusCodeRedirect | |
9 | from pylons.wsgiapp import PylonsApp |
|
9 | from pylons.wsgiapp import PylonsApp | |
10 | from routes.middleware import RoutesMiddleware |
|
10 | from routes.middleware import RoutesMiddleware | |
11 |
|
11 | |||
12 | from pylons_app.config.environment import load_environment |
|
12 | from pylons_app.config.environment import load_environment | |
13 |
|
13 | |||
14 | def make_app(global_conf, full_stack = True, static_files = True, **app_conf): |
|
14 | def make_app(global_conf, full_stack = True, static_files = True, **app_conf): | |
15 | """Create a Pylons WSGI application and return it |
|
15 | """Create a Pylons WSGI application and return it | |
16 |
|
16 | |||
17 | ``global_conf`` |
|
17 | ``global_conf`` | |
18 | The inherited configuration for this application. Normally from |
|
18 | The inherited configuration for this application. Normally from | |
19 | the [DEFAULT] section of the Paste ini file. |
|
19 | the [DEFAULT] section of the Paste ini file. | |
20 |
|
20 | |||
21 | ``full_stack`` |
|
21 | ``full_stack`` | |
22 | Whether this application provides a full WSGI stack (by default, |
|
22 | Whether this application provides a full WSGI stack (by default, | |
23 | meaning it handles its own exceptions and errors). Disable |
|
23 | meaning it handles its own exceptions and errors). Disable | |
24 | full_stack when this application is "managed" by another WSGI |
|
24 | full_stack when this application is "managed" by another WSGI | |
25 | middleware. |
|
25 | middleware. | |
26 |
|
26 | |||
27 | ``static_files`` |
|
27 | ``static_files`` | |
28 | Whether this application serves its own static files; disable |
|
28 | Whether this application serves its own static files; disable | |
29 | when another web server is responsible for serving them. |
|
29 | when another web server is responsible for serving them. | |
30 |
|
30 | |||
31 | ``app_conf`` |
|
31 | ``app_conf`` | |
32 | The application's local configuration. Normally specified in |
|
32 | The application's local configuration. Normally specified in | |
33 | the [app:<name>] section of the Paste ini file (where <name> |
|
33 | the [app:<name>] section of the Paste ini file (where <name> | |
34 | defaults to main). |
|
34 | defaults to main). | |
35 |
|
35 | |||
36 | """ |
|
36 | """ | |
37 | # Configure the Pylons environment |
|
37 | # Configure the Pylons environment | |
38 | load_environment(global_conf, app_conf) |
|
38 | load_environment(global_conf, app_conf) | |
39 |
|
39 | |||
40 | # The Pylons WSGI app |
|
40 | # The Pylons WSGI app | |
41 | app = PylonsApp() |
|
41 | app = PylonsApp() | |
42 |
|
42 | |||
43 | # Routing/Session/Cache Middleware |
|
43 | # Routing/Session/Cache Middleware | |
44 | app = RoutesMiddleware(app, config['routes.map']) |
|
44 | app = RoutesMiddleware(app, config['routes.map']) | |
45 | app = SessionMiddleware(app, config) |
|
45 | app = SessionMiddleware(app, config) | |
46 | app = CacheMiddleware(app, config) |
|
46 | app = CacheMiddleware(app, config) | |
47 |
|
47 | |||
48 | # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) |
|
48 | # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) | |
49 |
|
49 | |||
50 | if asbool(full_stack): |
|
50 | if asbool(full_stack): | |
51 | # Handle Python exceptions |
|
51 | # Handle Python exceptions | |
52 | app = ErrorHandler(app, global_conf, **config['pylons.errorware']) |
|
52 | app = ErrorHandler(app, global_conf, **config['pylons.errorware']) | |
53 |
|
53 | |||
54 | # Display error documents for 401, 403, 404 status codes (and |
|
54 | # Display error documents for 401, 403, 404 status codes (and | |
55 | # 500 when debug is disabled) |
|
55 | # 500 when debug is disabled) | |
56 | if asbool(config['debug']): |
|
56 | if asbool(config['debug']): | |
57 | app = StatusCodeRedirect(app) |
|
57 | app = StatusCodeRedirect(app) | |
58 | else: |
|
58 | else: | |
59 | app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) |
|
59 | app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) | |
60 |
|
60 | |||
61 | # Establish the Registry for this application |
|
61 | # Establish the Registry for this application | |
62 | app = RegistryManager(app) |
|
62 | app = RegistryManager(app) | |
63 |
|
63 | |||
64 | if asbool(static_files): |
|
64 | if asbool(static_files): | |
65 | # Serve static files |
|
65 | # Serve static files | |
66 | static_app = StaticURLParser(config['pylons.paths']['static_files']) |
|
66 | static_app = StaticURLParser(config['pylons.paths']['static_files']) | |
67 | app = Cascade([static_app, app]) |
|
67 | app = Cascade([static_app, app]) | |
68 |
|
68 | |||
69 | #dozer debug |
|
69 | #dozer debug | |
70 | if asbool(config['debug']): |
|
70 | # if asbool(config['debug']): | |
71 | from dozer import Logview |
|
71 | # from dozer import Logview | |
72 | app = Logview(app, config) |
|
72 | # app = Logview(app, config) | |
73 |
|
73 | |||
74 | return app |
|
74 | return app |
General Comments 0
You need to be logged in to leave comments.
Login now