diff --git a/common/djangoapps/util/file.py b/common/djangoapps/util/file.py index 1a41fe8910..53e6b7cae0 100644 --- a/common/djangoapps/util/file.py +++ b/common/djangoapps/util/file.py @@ -146,7 +146,9 @@ class UniversalNewlineIterator(object): """ Replace CR and CRLF with LF within `string`. """ - return string.replace('\r\n', '\n').replace('\r', '\n') + if six.PY2: + return string.replace('\r\n', '\n').replace('\r', '\n') + return string.replace('\r\n', '\n').replace('\r', '\n').encode('utf-8') def generate_lines(self): """ diff --git a/common/lib/capa/capa/capa_problem.py b/common/lib/capa/capa/capa_problem.py index fb572e00fd..5471bc4ea2 100644 --- a/common/lib/capa/capa/capa_problem.py +++ b/common/lib/capa/capa/capa_problem.py @@ -728,7 +728,10 @@ class LoncapaProblem(object): Main method called externally to get the HTML to be rendered for this capa Problem. """ self.do_targeted_feedback(self.tree) - html = contextualize_text(etree.tostring(self._extract_html(self.tree)), self.context) + html = contextualize_text( + etree.tostring(self._extract_html(self.tree)).decode('utf-8'), + self.context + ) return html def handle_input_ajax(self, data): diff --git a/common/lib/capa/capa/xqueue_interface.py b/common/lib/capa/capa/xqueue_interface.py index b70b6b9548..da7972c4f1 100644 --- a/common/lib/capa/capa/xqueue_interface.py +++ b/common/lib/capa/capa/xqueue_interface.py @@ -26,7 +26,7 @@ def make_hashkey(seed): Generate a string key by hashing """ h = hashlib.md5() - h.update(str(seed)) + h.update(six.b(str(seed))) return h.hexdigest() diff --git a/common/lib/xmodule/xmodule/modulestore/tests/factories.py b/common/lib/xmodule/xmodule/modulestore/tests/factories.py index 6995f6b858..2a685a8f74 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/factories.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/factories.py @@ -472,7 +472,7 @@ class StackTraceCounter(object): """ # pylint: disable=broad-except - stack = traceback.extract_stack()[:-2] + stack = [tuple(item) for item in traceback.extract_stack()[:-2]] if self._top_of_stack in stack: stack = stack[stack.index(self._top_of_stack):] @@ -484,7 +484,6 @@ class StackTraceCounter(object): safe_args.append(repr(arg)) except Exception as exc: safe_args.append('