Changeset 7494 for cowsclient


Ignore:
Timestamp:
21/09/10 22:16:20 (9 years ago)
Author:
astephen
Message:

config/middleware.py file updated to mirror standard pylons 1.0 version.
Also removed the switch for compatibility with pylons versions before
version 0.9.7.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cowsclient/branches/migrate-py26-pylons10/cowsclient/config/middleware.py

    r7348 r7494  
    11"""Pylons middleware initialization""" 
     2from beaker.middleware import SessionMiddleware 
    23from paste.cascade import Cascade 
    34from paste.registry import RegistryManager 
    45from paste.urlparser import StaticURLParser 
    56from paste.deploy.converters import asbool 
    6  
    7 from beaker.middleware import SessionMiddleware 
     7from pylons.middleware import ErrorHandler, StatusCodeRedirect 
     8from pylons.wsgiapp import PylonsApp 
    89from routes.middleware import RoutesMiddleware 
    9  
    10 from pylons.middleware import ErrorHandler 
    11  
    12 from pylons.wsgiapp import PylonsApp 
    1310 
    1411from cowsclient.config.environment import load_environment 
    1512 
    16 def make_app(global_conf, full_stack=True, **app_conf): 
     13def make_app(global_conf, full_stack=True, static_files=True, **app_conf): 
    1714    """Create a Pylons WSGI application and return it 
    1815 
     
    2219 
    2320    ``full_stack`` 
    24         Whether or not this application provides a full WSGI stack (by 
    25         default, meaning it handles its own exceptions and errors). 
    26         Disable full_stack when this application is "managed" by 
    27         another WSGI middleware. 
     21        Whether this application provides a full WSGI stack (by default, 
     22        meaning it handles its own exceptions and errors). Disable 
     23        full_stack when this application is "managed" by another WSGI 
     24        middleware. 
     25 
     26    ``static_files`` 
     27        Whether this application serves its own static files; disable 
     28        when another web server is responsible for serving them. 
    2829 
    2930    ``app_conf`` 
    30         The application's local configuration. Normally specified in the 
    31         [app:<name>] section of the Paste ini file (where <name> 
     31        The application's local configuration. Normally specified in 
     32        the [app:<name>] section of the Paste ini file (where <name> 
    3233        defaults to main). 
     34 
    3335    """ 
    3436    # Configure the Pylons environment 
     
    3840    app = PylonsApp(config=config) 
    3941 
    40     app = RoutesMiddleware(app, config['routes.map']) 
     42    # Routing/Session Middleware 
     43    app = RoutesMiddleware(app, config['routes.map'], singleton=False) 
    4144    app = SessionMiddleware(app, config) 
    4245 
     
    4750        app = ErrorHandler(app, global_conf, **config['pylons.errorware']) 
    4851 
     52        # Display error documents for 401, 403, 404 status codes (and 
     53        # 500 when debug is disabled) 
     54        if asbool(config['debug']): 
     55            app = StatusCodeRedirect(app) 
     56        else: 
     57            app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) 
     58 
    4959    # Establish the Registry for this application 
    5060    app = RegistryManager(app) 
    5161 
    52     # Static files 
    53     static_app = StaticURLParser(config['pylons.paths']['static_files']) 
    54     app = Cascade([static_app, app]) 
     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 
    5567    app.config = config 
    5668 
Note: See TracChangeset for help on using the changeset viewer.