|
1 | | -# $Id: client.py,v 1.239 2008-08-18 05:04:02 richard Exp $ |
2 | | - |
3 | 1 | """WWW request handler (also used in the stand-alone server). |
4 | 2 | """ |
5 | 3 | __docformat__ = 'restructuredtext' |
6 | 4 |
|
7 | 5 | import base64, binascii, cgi, codecs, mimetypes, os |
8 | | -import random, re, rfc822, stat, time, urllib, urlparse |
| 6 | +import quopri random, re, rfc822, stat, sys, time, urllib, urlparse |
9 | 7 | import Cookie, socket, errno |
10 | 8 | from Cookie import CookieError, BaseCookie, SimpleCookie |
| 9 | +from cStringIO import StringIO |
11 | 10 |
|
12 | 11 | from roundup import roundupdb, date, hyperdb, password |
13 | 12 | from roundup.cgi import templating, cgitb, TranslationService |
@@ -927,7 +926,30 @@ def renderContext(self): |
927 | 926 | raise Unauthorised, str(message) |
928 | 927 | except: |
929 | 928 | # everything else |
930 | | - return cgitb.pt_html(i18n=self.translator) |
| 929 | + if self.instance.config.WEB_DEBUG: |
| 930 | + return cgitb.pt_html(i18n=self.translator) |
| 931 | + exc_info = sys.exc_info() |
| 932 | + try: |
| 933 | + # If possible, send the HTML page template traceback |
| 934 | + # to the administrator. |
| 935 | + to = [self.mailer.config.ADMIN_EMAIL] |
| 936 | + subject = "Templating Error: %s" % exc_info[1] |
| 937 | + content = cgitb.pt_html() |
| 938 | + message, writer = self.mailer.get_standard_message( |
| 939 | + to, subject) |
| 940 | + writer.addheader('Content-Transfer-Encoding', 'quoted-printable') |
| 941 | + body = writer.startbody('text/html; charset=utf-8') |
| 942 | + content = StringIO(content) |
| 943 | + quopri.encode(content, body, 0) |
| 944 | + self.mailer.smtp_send(to, message) |
| 945 | + # Now report the error to the user. |
| 946 | + return self._(error_message) |
| 947 | + except: |
| 948 | + # Reraise the original exception. The user will |
| 949 | + # receive an error message, and the adminstrator will |
| 950 | + # receive a traceback, albeit with less information |
| 951 | + # than the one we tried to generate above. |
| 952 | + raise exc_info[0], exc_info[1], exc_info[2] |
931 | 953 |
|
932 | 954 | # these are the actions that are available |
933 | 955 | actions = ( |
|
0 commit comments