Changeset 7482


Ignore:
Timestamp:
21/09/10 11:15:49 (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
  • cowsserver/branches/migrate-py26-pylons10/lib/cowsserver/config/middleware.py

    r7345 r7482  
    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 pylons import config 
    87from pylons.middleware import ErrorHandler, StatusCodeRedirect 
    98from pylons.wsgiapp import PylonsApp 
    10  
    11 from pylons import __version__ as pylons_version 
    12  
    13 def is_096(): 
    14     parts = pylons_version.split('.') 
    15     return parts[:3] == ['0', '9', '6'] 
    16          
    17  
    18 if not is_096(): 
    19     from beaker.middleware import SessionMiddleware 
    20     from routes.middleware import RoutesMiddleware 
    21  
     9from routes.middleware import RoutesMiddleware 
    2210 
    2311from cowsserver.config.environment import load_environment 
    2412 
    25  
    26 def make_app(global_conf, full_stack=True, **app_conf): 
     13def make_app(global_conf, full_stack=True, static_files=True, **app_conf): 
    2714    """Create a Pylons WSGI application and return it 
    2815 
     
    3219 
    3320    ``full_stack`` 
    34         Whether or not this application provides a full WSGI stack (by 
    35         default, meaning it handles its own exceptions and errors). 
    36         Disable full_stack when this application is "managed" by 
    37         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. 
    3829 
    3930    ``app_conf`` 
    40         The application's local configuration. Normally specified in the 
    41         [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> 
    4233        defaults to main). 
     34 
    4335    """ 
    44  
    45     if is_096(): 
    46         return make_app_096(global_conf, fullstack, **app_conf) 
    4736 
    4837    # Configure the Pylons environment 
     
    5241    app = PylonsApp(config=config) 
    5342 
     43    # Routing/Session Middleware 
     44    app = RoutesMiddleware(app, config['routes.map'], singleton=False) 
     45    app = SessionMiddleware(app, config) 
     46 
    5447    # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) 
    55     app = RoutesMiddleware(app, config['routes.map']) 
    56     app = SessionMiddleware(app, config) 
    5748 
    5849    if asbool(full_stack): 
     
    6051        app = ErrorHandler(app, global_conf, **config['pylons.errorware']) 
    6152 
     53        # Display error documents for 401, 403, 404 status codes (and 
     54        # 500 when debug is disabled) 
    6255        if asbool(config['debug']): 
    6356            app = StatusCodeRedirect(app) 
    6457        else: 
    65             app = StatusCodeRedirect(app, [401, 403, 404, 500]) 
     58            app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) 
    6659 
    6760    # Establish the Registry for this application 
    6861    app = RegistryManager(app) 
    6962 
    70     # Static files 
    71     static_app = StaticURLParser(config['pylons.paths']['static_files']) 
    72     app = Cascade([static_app, app]) 
     63    if asbool(static_files): 
     64        # Serve static files 
     65        static_app = StaticURLParser(config['pylons.paths']['static_files']) 
     66        app = Cascade([static_app, app]) 
    7367    app.config = config 
    7468 
    7569    return app 
    76  
    77  
    78 def make_app_096(global_conf, full_stack=True, **app_conf): 
    79     """Create a Pylons WSGI application and return it 
    80  
    81     Legacy app config for Pylons 0.9.6 
    82     """ 
    83  
    84     from pylons.middleware import StaticJavascripts 
    85  
    86     # Configure the Pylons environment 
    87     load_environment(global_conf, app_conf) 
    88  
    89     # The Pylons WSGI app 
    90     app = PylonsApp() 
    91  
    92     # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) 
    93      
    94     if asbool(full_stack): 
    95         # Handle Python exceptions 
    96         app = ErrorHandler(app, global_conf, **config['pylons.errorware']) 
    97  
    98     # Establish the Registry for this application 
    99     app = RegistryManager(app) 
    100  
    101     # Static files 
    102     javascripts_app = StaticJavascripts() 
    103     static_app = StaticURLParser(config['pylons.paths']['static_files']) 
    104     app = Cascade([static_app, javascripts_app, app]) 
    105     return app 
Note: See TracChangeset for help on using the changeset viewer.