address deprecation warning for cgi.escape for logs cleanup.
This commit is contained in:
@@ -14,7 +14,6 @@ Used by capa_problem.py
|
||||
|
||||
import abc
|
||||
# TODO: Refactor this code and fix this issue.
|
||||
import cgi
|
||||
import inspect
|
||||
import json
|
||||
import logging
|
||||
@@ -35,6 +34,7 @@ import requests
|
||||
import six
|
||||
# specific library imports
|
||||
from calc import UndefinedVariable, UnmatchedParenthesis, evaluator
|
||||
from django.utils import html
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
from lxml import etree
|
||||
from lxml.html.soupparser import fromstring as fromstring_bs # uses Beautiful Soup!!! FIXME?
|
||||
@@ -1597,7 +1597,7 @@ class NumericalResponse(LoncapaResponse):
|
||||
|
||||
_ = edx_six.get_gettext(self.capa_system.i18n)
|
||||
general_exception = StudentInputError(
|
||||
_(u"Could not interpret '{student_answer}' as a number.").format(student_answer=cgi.escape(student_answer))
|
||||
_(u"Could not interpret '{student_answer}' as a number.").format(student_answer=html.escape(student_answer))
|
||||
)
|
||||
|
||||
# Begin `evaluator` block
|
||||
@@ -1620,13 +1620,13 @@ class NumericalResponse(LoncapaResponse):
|
||||
# `factorial() not defined for negative values`
|
||||
raise StudentInputError(
|
||||
_("Factorial function evaluated outside its domain:"
|
||||
"'{student_answer}'").format(student_answer=cgi.escape(student_answer))
|
||||
"'{student_answer}'").format(student_answer=html.escape(student_answer))
|
||||
)
|
||||
else:
|
||||
raise general_exception
|
||||
except ParseException:
|
||||
raise StudentInputError(
|
||||
_(u"Invalid math syntax: '{student_answer}'").format(student_answer=cgi.escape(student_answer))
|
||||
_(u"Invalid math syntax: '{student_answer}'").format(student_answer=html.escape(student_answer))
|
||||
)
|
||||
except Exception:
|
||||
raise general_exception
|
||||
@@ -3104,7 +3104,7 @@ class FormulaResponse(LoncapaResponse):
|
||||
except UndefinedVariable as err:
|
||||
log.debug(
|
||||
'formularesponse: undefined variable in formula=%s',
|
||||
cgi.escape(answer)
|
||||
html.escape(answer)
|
||||
)
|
||||
raise StudentInputError(
|
||||
err.args[0]
|
||||
@@ -3112,7 +3112,7 @@ class FormulaResponse(LoncapaResponse):
|
||||
except UnmatchedParenthesis as err:
|
||||
log.debug(
|
||||
'formularesponse: unmatched parenthesis in formula=%s',
|
||||
cgi.escape(answer)
|
||||
html.escape(answer)
|
||||
)
|
||||
raise StudentInputError(
|
||||
err.args[0]
|
||||
@@ -3127,18 +3127,18 @@ class FormulaResponse(LoncapaResponse):
|
||||
('formularesponse: factorial function used in response '
|
||||
'that tests negative and/or non-integer inputs. '
|
||||
'Provided answer was: %s'),
|
||||
cgi.escape(answer)
|
||||
html.escape(answer)
|
||||
)
|
||||
raise StudentInputError(
|
||||
_("Factorial function not permitted in answer "
|
||||
"for this problem. Provided answer was: "
|
||||
"{bad_input}").format(bad_input=cgi.escape(answer))
|
||||
"{bad_input}").format(bad_input=html.escape(answer))
|
||||
)
|
||||
# If non-factorial related ValueError thrown, handle it the same as any other Exception
|
||||
log.debug('formularesponse: error %s in formula', err)
|
||||
raise StudentInputError(
|
||||
_("Invalid input: Could not parse '{bad_input}' as a formula.").format(
|
||||
bad_input=cgi.escape(answer)
|
||||
bad_input=html.escape(answer)
|
||||
)
|
||||
)
|
||||
except Exception as err:
|
||||
@@ -3146,7 +3146,7 @@ class FormulaResponse(LoncapaResponse):
|
||||
log.debug('formularesponse: error %s in formula', err)
|
||||
raise StudentInputError(
|
||||
_("Invalid input: Could not parse '{bad_input}' as a formula").format(
|
||||
bad_input=cgi.escape(answer)
|
||||
bad_input=html.escape(answer)
|
||||
)
|
||||
)
|
||||
return out
|
||||
@@ -3890,7 +3890,7 @@ class ChoiceTextResponse(LoncapaResponse):
|
||||
# different type
|
||||
__, __, trace = sys.exc_info()
|
||||
msg = _("Could not interpret '{given_answer}' as a number.").format(
|
||||
given_answer=cgi.escape(answer_value)
|
||||
given_answer=html.escape(answer_value)
|
||||
)
|
||||
msg += " ({0})".format(trace)
|
||||
raise StudentInputError(msg)
|
||||
|
||||
Reference in New Issue
Block a user