Attachment 'moinmoinloader193ErrorCatch.py'
Download 1 from MoinMoin.web.serving import make_application
2 ## import the ISAPI WSGI glue
3 import isapi_wsgi
4 import sys
5 from sys import exc_info
6 from traceback import format_tb
7
8 class ExceptionMiddleware(object):
9 """The middleware we use."""
10
11 def __init__(self, app):
12 self.app = app
13
14 def __call__(self, environ, start_response):
15 """Call the application can catch exceptions."""
16 appiter = None
17 # just call the application and send the output back
18 # unchanged but catch exceptions
19 try:
20 appiter = self.app(environ, start_response)
21 for item in appiter:
22 yield item
23 # if an exception occours we get the exception information
24 # and prepare a traceback we can render
25 except:
26 e_type, e_value, tb = exc_info()
27 traceback = ['Traceback (most recent call last):']
28 traceback += format_tb(tb)
29 traceback.append('%s: %s' % (e_type.__name__, e_value))
30 # we might have not a stated response by now. try
31 # to start one with the status code 500 or ignore an
32 # raised exception if the application already started one.
33 try:
34 start_response('500 INTERNAL SERVER ERROR', [('Content-Type', 'text/plain')])
35 except:
36 pass
37 yield '\n'.join(traceback)
38
39 # wsgi applications might have a close function. If it exists
40 # it *must* be called.
41 if hasattr(appiter, 'close'):
42 appiter.close()
43
44 # The entry points for the ISAPI extension.
45
46 def __ExtensionFactory__():
47 #add path to sys.paht where wikiconfig.py can be found
48 sys.path.insert(0, 'c:/moin')
49 ## new way to instantiate in 1.9
50 moinmoinApp = make_application(shared=True)
51 errorHandledApp=ExceptionMiddleware(moinmoinApp)
52 return isapi_wsgi.ISAPIThreadPoolHandler(errorHandledApp)
53
54 ## Installation code
55 if __name__=='__main__':
56 from isapi.install import *
57
58 # If run from the command-line, install ourselves.
59 params = ISAPIParameters()
60
61 sm = [ScriptMapParams(Extension="*", Flags=0)]
62
63 # Create a Virtual Directory per wiki
64 params.VirtualDirs = [ VirtualDirParameters(
65 #Server="mshost",
66 Name="wiki",
67 Description = "ISAPI-WSGI gateway for testwiki" ,
68 ScriptMaps = sm,
69 ScriptMapUpdate = "replace" )
70 ]
71
72 HandleCommandLine(params)
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.