[Mpuls-commits] r1196 - wasko/branches/2.0/waskaweb/config

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Feb 3 09:19:14 CET 2010


Author: torsten
Date: 2010-02-03 09:19:14 +0100 (Wed, 03 Feb 2010)
New Revision: 1196

Modified:
   wasko/branches/2.0/waskaweb/config/middleware.py
Log:
* waskaweb/config/middleware.py: Inserted fresh middleware.py from a
fresh initiated pylons project of version 0.9.7


Modified: wasko/branches/2.0/waskaweb/config/middleware.py
===================================================================
--- wasko/branches/2.0/waskaweb/config/middleware.py	2010-02-03 08:16:34 UTC (rev 1195)
+++ wasko/branches/2.0/waskaweb/config/middleware.py	2010-02-03 08:19:14 UTC (rev 1196)
@@ -1,68 +1,17 @@
-# Copyright 2007, 2008 Intevation GmbH, Germany, <info at intevation.de>
-# 
-# This file is part of mpuls WASKA (CoMPUter-based case fiLeS - 
-# Web-Anwendungs-Server fuer Kompetenzagenturen).
-# 
-# mpuls WASKA is free software: you can redistribute it and/or modify it under
-# the terms of the GNU Affero General Public License as published by the
-# Free Software Foundation, either version 3 of the License, or (at your
-# option) any later version.
-# 
-# mpuls WASKA is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
-# License for more details.
-# 
-# You should have received a copy of the GNU Affero General Public
-# License along with mpuls WASKA. If not, see <http://www.gnu.org/licenses/>.
-# 
-# mpuls WASKA has been developed on behalf of the 
-# Projekttraeger im Deutschen Zentrum fuer Luft- und Raumfahrt e.V. (PT-DLR)
-# within the programme Kompetenzagenturen (Durchfuehrungsphase) funded by
-# the Bundesministerium fuer Familie, Senioren, Frauen und Jugend and 
-# European Social Fund resources.
 """Pylons middleware initialization"""
-#import authkit.authenticate
-#import authkit.authorize
-#from authkit.permissions import ValidAuthKitUser
-#import authkit
-
 from beaker.middleware import CacheMiddleware, SessionMiddleware
-from routes.middleware import RoutesMiddleware
-
 from paste.cascade import Cascade
 from paste.registry import RegistryManager
 from paste.urlparser import StaticURLParser
 from paste.deploy.converters import asbool
-
 from pylons import config
-from pylons.error import error_template
-from pylons.middleware import error_mapper, ErrorDocuments, ErrorHandler
-#, \ StaticJavascripts
-
+from pylons.middleware import ErrorHandler, StatusCodeRedirect
 from pylons.wsgiapp import PylonsApp
+from routes.middleware import RoutesMiddleware
 
-#from waskaweb.lib.security import checkLogin
-
-
 from waskaweb.config.environment import load_environment
 
-#from authkit.authorize import NotAuthenticatedError
-
-#class MyValidAuthKitUser(ValidAuthKitUser):
-#    """
-#    Checks that the signed in user is one of the users specified when setting up
-#    the user management API.
-#    """
-#    def __init__(self):
-#        pass
-#    
-#    def check(self, app, environ, start_response):
-#        if not environ.get('REMOTE_USER'):
-#            raise NotAuthenticatedError('Not Authenticated')
-#        return app(environ, start_response)
-#
-def make_app(global_conf, full_stack=True, **app_conf):
+def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
     """Create a Pylons WSGI application and return it
 
     ``global_conf``
@@ -70,15 +19,20 @@
         the [DEFAULT] section of the Paste ini file.
 
     ``full_stack``
-        Whether or not this application provides a full WSGI stack (by
-        default, meaning it handles its own exceptions and errors).
-        Disable full_stack when this application is "managed" by
-        another WSGI middleware.
+        Whether this application provides a full WSGI stack (by default,
+        meaning it handles its own exceptions and errors). Disable
+        full_stack when this application is "managed" by another WSGI
+        middleware.
 
+    ``static_files``
+        Whether this application serves its own static files; disable
+        when another web server is responsible for serving them.
+
     ``app_conf``
-        The application's local configuration. Normally specified in the
-        [app:<name>] section of the Paste ini file (where <name>
+        The application's local configuration. Normally specified in
+        the [app:<name>] section of the Paste ini file (where <name>
         defaults to main).
+
     """
     # Configure the Pylons environment
     load_environment(global_conf, app_conf)
@@ -86,38 +40,30 @@
     # The Pylons WSGI app
     app = PylonsApp()
 
-    # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
+    # Routing/Session/Cache Middleware
     app = RoutesMiddleware(app, config['routes.map'])
     app = SessionMiddleware(app, config)
     app = CacheMiddleware(app, config)
 
+    # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
+
     if asbool(full_stack):
-        pass
         # Handle Python exceptions
-        #app = ErrorHandler(app, global_conf, error_template=error_template,
-        #                   **config['pylons.errorware'])
+        app = ErrorHandler(app, global_conf, **config['pylons.errorware'])
 
-
-        # We want to protect the whole application
-        #permission = MyValidAuthKitUser()
-        #app = authkit.authorize.middleware(app, permission)
-        #app = authkit.authenticate.middleware(app, app_conf)
-
         # Display error documents for 401, 403, 404 status codes (and
         # 500 when debug is disabled)
-        #app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf)
+        if asbool(config['debug']):
+            app = StatusCodeRedirect(app)
+        else:
+            app = StatusCodeRedirect(app, [400, 401, 403, 404, 500])
 
     # Establish the Registry for this application
     app = RegistryManager(app)
 
-    serve_static = config.get('serve_static')
-    serve_static = serve_static and serve_static.lower() == "true" or False
-
-    if serve_static:
-        print "Serve Static"
-        # Static files
-        ##javascripts_app = StaticJavascripts()
+    if asbool(static_files):
+        # Serve static files
         static_app = StaticURLParser(config['pylons.paths']['static_files'])
-        ##app = Cascade([static_app, javascripts_app, app])
         app = Cascade([static_app, app])
+
     return app



More information about the Mpuls-commits mailing list