# HG changeset patch # User Thomas Waldmann # Date 1237068398 -3600 # Node ID 4d01cd04af706bb25613bf8f1638305af688d906 # Parent aa481a3b6a6092c1bfb3c56b57149174eee044ee support --debug=off/external/web or MOIN_DEBUGGER for flup frontend, default to off diff -r aa481a3b6a60 -r 4d01cd04af70 MoinMoin/web/flup_frontend.py --- 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 = """ + +Unhandled Exception + +

Unhandled Exception

+

An unhandled exception was thrown by the application.

+ +""" + 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 ( diff -r aa481a3b6a60 -r 4d01cd04af70 MoinMoin/web/frontend.py --- 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"))