changeset 4250:43da090ab838

Fixed exception-handling for MoinMoinFinish and relocated it to MoinMoin.web.request
author Florian Krupicka <florian.krupicka@googlemail.com>
date Sun, 27 Jul 2008 15:16:19 +0200
parents b8ea98d74d8d
children 3c6e893424f6
files MoinMoin/request/__init__.py MoinMoin/web/contexts.py MoinMoin/web/request.py MoinMoin/wsgiapp.py
diffstat 4 files changed, 25 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/request/__init__.py	Fri Jul 25 22:48:12 2008 +0200
+++ b/MoinMoin/request/__init__.py	Sun Jul 27 15:16:19 2008 +0200
@@ -74,9 +74,7 @@
 
 # Exceptions -----------------------------------------------------------
 
-class MoinMoinFinish(Exception):
-    """ Raised to jump directly to end of run() function, where finish is called """
-
+from MoinMoin.web.request import MoinMoinFinish
 
 class HeadersAlreadySentException(Exception):
     """ Is raised if the headers were already sent when emit_http_headers is called."""
--- a/MoinMoin/web/contexts.py	Fri Jul 25 22:48:12 2008 +0200
+++ b/MoinMoin/web/contexts.py	Sun Jul 27 15:16:19 2008 +0200
@@ -18,8 +18,7 @@
 from MoinMoin.formatter import text_html
 from MoinMoin.theme import load_theme_fallback
 from MoinMoin.util.clock import Clock
-from MoinMoin.request import MoinMoinFinish
-from MoinMoin.web.request import Request
+from MoinMoin.web.request import Request, MoinMoinFinish
 from MoinMoin.web.utils import check_spider, UniqueIDGenerator
 from MoinMoin.web.exceptions import Forbidden, SurgeProtection
 
--- a/MoinMoin/web/request.py	Fri Jul 25 22:48:12 2008 +0200
+++ b/MoinMoin/web/request.py	Sun Jul 27 15:16:19 2008 +0200
@@ -20,6 +20,9 @@
 from MoinMoin import log
 logging = log.getLogger(__name__)
 
+class MoinMoinFinish(Exception):
+    """ Raised to jump directly to end of run() function, where finish is called """
+
 class Request(WerkzeugRequest, WerkzeugResponse):
     """ A full featured Request/Response object.
 
--- a/MoinMoin/wsgiapp.py	Fri Jul 25 22:48:12 2008 +0200
+++ b/MoinMoin/wsgiapp.py	Sun Jul 27 15:16:19 2008 +0200
@@ -10,7 +10,7 @@
 from werkzeug.exceptions import HTTPException
 
 from MoinMoin.web.contexts import AllContext, Context, XMLRPCContext
-from MoinMoin.web.request import Request
+from MoinMoin.web.request import Request, MoinMoinFinish
 from MoinMoin.web.utils import check_forbidden, check_setuid, check_surge_protect
 
 from MoinMoin.Page import Page
@@ -55,21 +55,25 @@
     request = context.request
 
     # preliminary access checks (forbidden, bots, surge protection)
-    check_forbidden(context)
-    check_surge_protect(context)
-
-    action_name = context.action
+    try:
+        check_forbidden(context)
+        check_surge_protect(context)
 
-    # handle XMLRPC calls
-    if action_name == 'xmlrpc':
-        response = xmlrpc.xmlrpc(XMLRPCContext(request))
-    elif action_name == 'xmlrpc2':
-        response = xmlrpc.xmlrpc2(XMLRPCContext(request))
-    else:
-        response = dispatch(request, context, action_name)
-    context.cfg.session_service.finalize(context, context.session)
-    context.clock.stop('run')
-    return response
+        action_name = context.action
+
+        # handle XMLRPC calls
+        if action_name == 'xmlrpc':
+            response = xmlrpc.xmlrpc(XMLRPCContext(request))
+        elif action_name == 'xmlrpc2':
+            response = xmlrpc.xmlrpc2(XMLRPCContext(request))
+        else:
+            response = dispatch(request, context, action_name)
+        context.cfg.session_service.finalize(context, context.session)
+        return response
+    except MoinMoinFinish:
+        return request
+    finally:
+        context.clock.stop('run')
 
 def remove_prefix(path, prefix=None):
     """ Remove an url prefix from the path info and return shortened path. """
@@ -247,10 +251,9 @@
         context = init(request)
         response = run(context)
     except HTTPException, e:
-        context.clock.stop('run')
-        context.clock.stop('total')
         response = e
 
+    context.clock.stop('total')
     return response(environ, start_response)
 
 class ProxyTrust(object):