changeset 4653:4d01cd04af70

support --debug=off/external/web or MOIN_DEBUGGER for flup frontend, default to off
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 14 Mar 2009 23:06:38 +0100
parents aa481a3b6a60
children a04008fe1233
files MoinMoin/web/flup_frontend.py MoinMoin/web/frontend.py
diffstat 2 files changed, 41 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/web/flup_frontend.py	Sat Mar 14 17:39:39 2009 +0100
+++ b/MoinMoin/web/flup_frontend.py	Sat Mar 14 23:06:38 2009 +0100
@@ -18,9 +18,13 @@
     AJP from a bound network or unix socket, in different flavours of
     multiprocessing/multithreading.
 
-    @copyright: 2008 MoinMoin:FlorianKrupicka
+    @copyright: 2008 MoinMoin:FlorianKrupicka,
+                2009 MoinMoin:ThomasWaldmann
     @license: GNU GPL, see COPYING for details.
 """
+
+import os, sys
+
 try:
     import flup.server.fcgi
     have_flup = True
@@ -38,6 +42,7 @@
 logging = log.getLogger(__name__)
 
 if have_flup:
+    from flup.server.fcgi_base import FCGI_RESPONDER
     class FlupFrontEnd(ServerFrontEnd):
         def add_options(self):
             super(FlupFrontEnd, self).add_options()
@@ -72,10 +77,42 @@
 
             mod = self.server_types[server_type]
             mod = __import__(mod, fromlist=['WSGIServer'])
-            WSGIServer = mod.WSGIServer
+            WSGIServerWrapped = mod.WSGIServer
+
+            class WSGIServer(WSGIServerWrapped):
+                def __init__(self, application, environ=None,
+                             multithreaded=True, multiprocess=False,
+                             bindAddress=None, umask=None, multiplexed=False,
+                             debug="off", roles=(FCGI_RESPONDER, )):
+                    WSGIServerWrapped.__init__(self, application, environ=environ,
+                                               multithreaded=multithreaded, multiprocess=multiprocess,
+                                               bindAddress=bindAddress, umask=umask, multiplexed=multiplexed,
+                                               debug=debug, roles=roles)
+
+                def error(self, req):
+                    """ Override the default handler, so it implements debug=web/external/off. """
+                    if self.debug == 'external':
+                        raise
+                    elif self.debug == 'web':
+                        import cgitb
+                        req.stdout.write('Content-Type: text/html\r\n\r\n' +
+                                         cgitb.html(sys.exc_info()))
+                    else: # 'off'
+                        errorpage = """<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
+<html><head>
+<title>Unhandled Exception</title>
+</head><body>
+<h1>Unhandled Exception</h1>
+<p>An unhandled exception was thrown by the application.</p>
+</body></html>
+"""
+                        req.stdout.write('Content-Type: text/html\r\n\r\n' + errorpage)
+
 
             kwargs = {}
 
+            kwargs['debug'] = options.debug or os.environ.get('MOIN_DEBUGGER', 'off')
+
             if options.port:
                 kwargs['bindAddress'] = (options.interface, options.port)
             elif options.interface and (
--- a/MoinMoin/web/frontend.py	Sat Mar 14 17:39:39 2009 +0100
+++ b/MoinMoin/web/frontend.py	Sat Mar 14 23:06:38 2009 +0100
@@ -19,8 +19,8 @@
 
     def add_options(self):
         parser = self.parser
-        parser.add_option("-d", "--debug", action="store_true",
-                          help="Enable debug mode of server (show tracebacks)")
+        parser.add_option("-d", "--debug", dest="debug",
+                          help="Debug mode of server (off/web/external, default is to use MOIN_DEBUGGER env var)")
         parser.add_option("-c", "--config-dir", dest="config_dir", metavar="DIR",
                           help=("Path to the directory containing the wiki "
                                 "configuration files. Default: current directory"))