diff --git a/common/lib/capa/capa/responsetypes.py b/common/lib/capa/capa/responsetypes.py index 65e903b576..3b17daa830 100644 --- a/common/lib/capa/capa/responsetypes.py +++ b/common/lib/capa/capa/responsetypes.py @@ -36,7 +36,7 @@ from datetime import datetime from .util import * from lxml import etree from lxml.html.soupparser import fromstring as fromstring_bs # uses Beautiful Soup!!! FIXME? -import xqueue_interface +import capa.xqueue_interface log = logging.getLogger(__name__) @@ -301,7 +301,7 @@ class LoncapaResponse(object): # response aid = self.answer_ids[-1] new_cmap.set_hint_and_mode(aid, hint_text, hintmode) - log.debug('after hint: new_cmap = %s' % new_cmap) + log.debug('after hint: new_cmap = %s', new_cmap) @abc.abstractmethod def get_score(self, student_answers): @@ -791,6 +791,10 @@ class OptionResponse(LoncapaResponse): class NumericalResponse(LoncapaResponse): + ''' + This response type expects a number or formulaic expression that evaluates + to a number (e.g. `4+5/2^2`), and accepts with a tolerance. + ''' response_tag = 'numericalresponse' hint_tag = 'numericalhint' @@ -807,12 +811,12 @@ class NumericalResponse(LoncapaResponse): '//*[@id=$id]//responseparam[@type="tolerance"]/@default', id=xml.get('id'))[0] self.tolerance = contextualize_text(self.tolerance_xml, context) - except Exception: + except IndexError: # xpath found an empty list, so (...)[0] is the error self.tolerance = '0' try: self.answer_id = xml.xpath('//*[@id=$id]//textline/@id', id=xml.get('id'))[0] - except Exception: + except IndexError: # Same as above self.answer_id = None def get_score(self, student_answers): @@ -837,7 +841,6 @@ class NumericalResponse(LoncapaResponse): except: # Use the traceback-preserving version of re-raising with a # different type - import sys type, value, traceback = sys.exc_info() raise StudentInputError, ("Could not interpret '%s' as a number" %