annotate MoinMoin/failure.py @ 1079:029754c52b11

Changed file format of meta file (\r\n line endings). Enhanced docstrings.
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Fri, 28 Jul 2006 16:01:19 +0200
parents 141083b64fb1
children cae5575b07fa
rev   line source
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
2 """ MoinMoin failure
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
3
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
4 Handle fatal errors by showing a message and debugging information.
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
5
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
6 @copyright: 2004, 2005 by Nir Soffer <nirs@freeshell.org>
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
7 @license: GNU GPL, see COPYING for details.
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
8 """
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
9 import sys, os
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
10 from MoinMoin.support import cgitb
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
11
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
12
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
13 class View(cgitb.View):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
14 """ Display an error message and debugging information
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
15
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
16 Additions to cgitb.View:
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
17 - Multiple tracebacks support
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
18 - Debugging information is shown only in debug mode
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
19 - Moin application information
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
20 - General help text and links
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
21 - Handle multiple paragraphs in exception message
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
22
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
23 cgitb is heavily modified cgitb, but fully backward compatible with
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
24 the standard cgitb. It should not contain any moin specific code.
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
25
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
26 cgitb was refactored to be easy to customize by applications
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
27 developers. This moin specific subclass is an example.
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
28 """
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
29 debugInfoID = 'debug-info'
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 52
diff changeset
30
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
31 def formatContent(self):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
32 content = (
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
33 self.script(),
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
34 self.formatStylesheet(),
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
35 self.formatTitle(),
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
36 self.formatMessage(),
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
37 self.formatButtons(),
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
38 self.formatDebugInfo(),
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
39 self.formatTextTraceback()
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
40 )
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
41 return ''.join(content)
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 52
diff changeset
42
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
43 def script(self):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
44 return '''
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
45 <script type="text/javascript">
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
46 function toggleDebugInfo() {
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
47 var tb = document.getElementById('%s');
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
48 if (tb == null) return;
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
49 tb.style.display = tb.style.display ? '' : 'none';
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
50 }
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
51 </script>
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
52 ''' % self.debugInfoID
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
53
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
54 def stylesheet(self):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
55 return cgitb.View.stylesheet(self) + """
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
56 .cgitb .buttons {margin: 0.5em 0; padding: 5px 10px;}
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
57 .cgitb .buttons li {display: inline; margin: 0; padding: 0 0.25em;}
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
58 """
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
59
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
60 def formatMessage(self):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
61 """ handle multiple paragraphs messages and add general help """
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
62 f = self.formatter
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
63 text = [self.formatExceptionMessage(self.info),
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
64 f.paragraph("If you want to report a bug, please save "
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 52
diff changeset
65 "this page and attach it to your bug report."), ]
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
66 return ''.join(text)
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
67
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
68 def formatButtons(self):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
69 """ Add 'buttons' to the error dialog """
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
70 f = self.formatter
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 52
diff changeset
71 buttons = [f.link('javascript:toggleDebugInfo()',
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
72 'Show debugging information'),
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 52
diff changeset
73 f.link('http://moinmoin.wikiwikiweb.de/MoinMoinBugs',
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
74 'Report bug'),
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 52
diff changeset
75 f.link('http://moinmoin.wikiwikiweb.de/FrontPage',
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 52
diff changeset
76 'Visit MoinMoin wiki'), ]
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
77 return f.list(buttons, {'class': 'buttons'})
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 52
diff changeset
78
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
79 def formatDebugInfo(self):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
80 """ Put debugging information in a hidden div """
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
81 attributes = {'id': self.debugInfoID}
52
80b3d4e891ff merge moin--main--1.3--patch-931: fix hidding of huge tracebacks
Nir Soffer <nirs@freeshell.org>
parents: 49
diff changeset
82 info = [self.debugInfoHideScript(),
80b3d4e891ff merge moin--main--1.3--patch-931: fix hidding of huge tracebacks
Nir Soffer <nirs@freeshell.org>
parents: 49
diff changeset
83 self.formatTraceback(),
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 52
diff changeset
84 self.formatSystemDetails(), ]
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
85 return self.formatter.section(''.join(info), attributes)
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
86
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
87 def debugInfoHideScript(self):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
88 """ Hide debug info for javascript enabled browsers """
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
89 if self.debug:
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
90 return ''
52
80b3d4e891ff merge moin--main--1.3--patch-931: fix hidding of huge tracebacks
Nir Soffer <nirs@freeshell.org>
parents: 49
diff changeset
91 return '''
80b3d4e891ff merge moin--main--1.3--patch-931: fix hidding of huge tracebacks
Nir Soffer <nirs@freeshell.org>
parents: 49
diff changeset
92 <script type="text/javascript">toggleDebugInfo()</script>
80b3d4e891ff merge moin--main--1.3--patch-931: fix hidding of huge tracebacks
Nir Soffer <nirs@freeshell.org>
parents: 49
diff changeset
93 '''
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
94
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
95 def formatTraceback(self):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
96 return self.formatAllTracebacks(self.formatOneTraceback)
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 52
diff changeset
97
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
98 def formatTextTraceback(self):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
99 template = self.textTracebackTemplate()
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 52
diff changeset
100 return template % self.formatAllTracebacks(self.formatOneTextTraceback)
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
101
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
102 def formatAllTracebacks(self, formatFuction):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
103 """ Format multiple tracebacks using formatFunction """
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
104 tracebacks = []
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
105 for type, value, tb in self.exceptions():
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 52
diff changeset
106 if type is None:
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
107 break
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
108 tracebacks.append(formatFuction((type, value, tb)))
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
109 del tb
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
110 return ''.join(tracebacks)
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
111
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
112 def exceptions(self):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
113 """ Return a list of exceptions info, starting at self.info """
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
114 try:
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
115 return [self.info] + self.info[1].exceptions()
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
116 except AttributeError:
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
117 return [self.info]
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
118
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
119 def applicationDetails(self):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
120 """ Add MoinMoin details to system details """
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
121 from MoinMoin import version
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
122 return ['MoinMoin: Release %s (%s)' % (version.release,
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
123 version.revision)]
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
124
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
125 def formatExceptionMessage(self, info):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
126 """ Handle multiple paragraphs in exception message """
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
127 text = cgitb.View.exceptionMessage(self, info)
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
128 text = text.split('\n\n')
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
129 text = ''.join([self.formatter.paragraph(item) for item in text])
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
130 return text
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
131
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
132
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
133 def handle(request):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
134 """ Handle failures
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
135
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
136 Display fancy error view, or fallback to simple text traceback
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
137 """
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
138 savedError = sys.exc_info()
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
139 try:
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
140 debug = ('debug' in getattr(request, 'form', {}) or
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
141 'MOIN_DEBUG' in os.environ)
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
142 handler = cgitb.Hook(file=request, viewClass=View, debug=debug)
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
143 handler.handle()
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
144 except:
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
145 request.write('<pre>\n')
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
146 printTextException(request, savedError)
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
147 request.write('\nAdditionally cgitb raised this exception:\n')
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 52
diff changeset
148 printTextException(request)
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
149 request.write('</pre>\n')
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
150
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 52
diff changeset
151
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
152 def printTextException(request, info=None):
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
153 """ Simple text exception that should never fail
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
154
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
155 Print all exceptions in a composite error.
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
156 """
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
157 import traceback
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
158 from MoinMoin import wikiutil
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
159 if info is None:
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
160 info = sys.exc_info()
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
161 try:
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
162 exceptions = [info] + info[1].exceptions()
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
163 except AttributeError:
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
164 exceptions = [info]
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
165 for info in exceptions:
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
166 text = ''.join(traceback.format_exception(*info))
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
167 text = wikiutil.escape(text)
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
168 request.write(text)
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents:
diff changeset
169