changeset 4151:30ac757e72de

Added HTTPException catching middleware
author Florian Krupicka <florian.krupicka@googlemail.com>
date Sun, 08 Jun 2008 18:27:07 +0200
parents 72604cb46155
children ddcd459c3255
files MoinMoin/web/apps.py MoinMoin/wsgiapp.py
diffstat 2 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/web/apps.py	Sun Jun 08 12:16:15 2008 +0200
+++ b/MoinMoin/web/apps.py	Sun Jun 08 18:27:07 2008 +0200
@@ -6,9 +6,21 @@
                 2008-2008 MoinMoin:FlorianKrupicka
     @license: GNU GPL, see COPYING for details.
 """
+from werkzeug.exceptions import HTTPException
+
 from MoinMoin.web.request import Request
 from MoinMoin.web.contexts import XMLRPCContext
 
+class HTTPExceptionsMiddleware(object):
+    def __init__(self, app):
+        self.app = app
+
+    def __call__(self, environ, start_response):
+        try:
+            return self.app(environ, start_response)
+        except HTTPException, e:
+            return e(environ, start_response)
+
 class XMLRPCApp(object):
     """ Handles XML-RPC method calls or dispatches to next layer """
     
--- a/MoinMoin/wsgiapp.py	Sun Jun 08 12:16:15 2008 +0200
+++ b/MoinMoin/wsgiapp.py	Sun Jun 08 18:27:07 2008 +0200
@@ -12,6 +12,7 @@
 
 from MoinMoin.web.contexts import HTTPContext
 from MoinMoin.web.utils import check_spider, handle_auth_form
+from MoinMoin.web.apps import HTTPExceptionsMiddleware
 
 from MoinMoin.Page import Page
 from MoinMoin import config, wikiutil, user, caching, error
@@ -33,7 +34,7 @@
         request.clock.stop('load_multi_cfg')
     except error.NoConfigMatchedError:
         raise NotFound('<p>No wiki configuration matching the URL found!</p>')
-    
+
     request.isSpiderAgent = check_spider(request.user_agent, request.cfg)
     
     request.action = request.form.get('action', 'show')
@@ -112,3 +113,4 @@
     return response
 
 application = responder(application)
+application = HTTPExceptionsMiddleware(application)