From 2ac5fa160c79552e26ef6ad38f85f75bedafb0a5 Mon Sep 17 00:00:00 2001 From: DawoudSheraz Date: Thu, 14 Nov 2019 16:33:07 +0500 Subject: [PATCH] remove unnecessary logs --- common/lib/capa/capa/capa_problem.py | 3 +-- common/lib/capa/capa/util.py | 31 ++-------------------------- 2 files changed, 3 insertions(+), 31 deletions(-) diff --git a/common/lib/capa/capa/capa_problem.py b/common/lib/capa/capa/capa_problem.py index 9a19aa468f..ee327dde52 100644 --- a/common/lib/capa/capa/capa_problem.py +++ b/common/lib/capa/capa/capa_problem.py @@ -736,8 +736,7 @@ class LoncapaProblem(object): self.do_targeted_feedback(self.tree) html = contextualize_text( etree.tostring(self._extract_html(self.tree)).decode('utf-8'), - self.context, - six.text_type(self.capa_module.location) + self.context ) return html diff --git a/common/lib/capa/capa/util.py b/common/lib/capa/capa/util.py index b186df6bb6..8f1063e90a 100644 --- a/common/lib/capa/capa/util.py +++ b/common/lib/capa/capa/util.py @@ -98,7 +98,7 @@ def compare_with_tolerance(student_complex, instructor_complex, tolerance=defaul return abs(student_complex - instructor_complex) <= tolerance -def contextualize_text(text, context, problem_location=None): # private +def contextualize_text(text, context): # private """ Takes a string with variables. E.g. $a+$b. Does a substitution of those variables from the context @@ -110,33 +110,6 @@ def contextualize_text(text, context, problem_location=None): # private except UnicodeEncodeError: return value.encode('utf8', errors='ignore') - def replace_or_log_error(data_string, old_value, new_value): - """Tries to replace context variable with value and logs exception if there is an error""" - try: - data_string = data_string.replace(old_value, new_value) - return data_string - except Exception: # pylint: disable=broad-except - if problem_location and problem_location == 'block-v1:MITx+CTL.SC3x+2T2019+type@problem+block@cb29c9209862423d87bef76c4ef15695': # pylint: disable=line-too-long - log.error( - u'ContextualizeTextError: data_string(%s), old_value(%s), new_value(%s)', - type(data_string), - type(old_value), - type(new_value), - ) - log.error( - u'ContextualizeTextError: data_string: %s', - data_string, - ) - log.error( - u'ContextualizeTextError: new_value : %s', - new_value, - ) - log.error( - u'ContextualizeTextError: old_value: %s', - old_value, - ) - raise - if not text: return text @@ -150,7 +123,7 @@ def contextualize_text(text, context, problem_location=None): # private if context_key in (text.decode('utf-8') if six.PY3 and isinstance(text, bytes) else text): text = convert_to_str(text) context_value = convert_to_str(context[key]) - text = replace_or_log_error(text, context_key, context_value) + text = text.replace(context_key, context_value) return text