From 8283636e3948850cc941817347108cc7cd127c7e Mon Sep 17 00:00:00 2001 From: ichuang Date: Fri, 29 Jun 2012 14:50:11 -0400 Subject: [PATCH] inputtypes: if externalresponse server message is bad, don't crash --- common/lib/capa/inputtypes.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/common/lib/capa/inputtypes.py b/common/lib/capa/inputtypes.py index 75588e8aea..52ce5ddf35 100644 --- a/common/lib/capa/inputtypes.py +++ b/common/lib/capa/inputtypes.py @@ -232,7 +232,15 @@ def textbox(element, value, status, render_template, msg=''): 'rows':rows, 'cols':cols, } html = render_template("textbox.html", context) - return etree.XML(html) + try: + xhtml = etree.XML(html) + except Exception,err: + newmsg = 'error %s in rendering message' % (str(err).replace('<','<')) + newmsg += '
Original message: %s' % msg.replace('<','<') + context['msg'] = newmsg + html = render_template("textbox.html", context) + xhtml = etree.XML(html) + return xhtml #----------------------------------------------------------------------------- @register_render_function