diff --git a/common/lib/capa/capa/responsetypes.py b/common/lib/capa/capa/responsetypes.py index 2f3ede8174..12b7c6db13 100644 --- a/common/lib/capa/capa/responsetypes.py +++ b/common/lib/capa/capa/responsetypes.py @@ -2471,7 +2471,7 @@ class CustomResponse(LoncapaResponse): msg = msg.replace('<', '<') # Use etree to prettify the HTML - msg = etree.tostring(fromstring_bs(msg), pretty_print=True) + msg = etree.tostring(fromstring_bs(msg), pretty_print=True).decode('utf-8') msg = msg.replace(' ', '') diff --git a/common/lib/capa/capa/safe_exec/safe_exec.py b/common/lib/capa/capa/safe_exec/safe_exec.py index 794fafb3e1..4b62faae08 100644 --- a/common/lib/capa/capa/safe_exec/safe_exec.py +++ b/common/lib/capa/capa/safe_exec/safe_exec.py @@ -7,6 +7,7 @@ import hashlib from codejail.safe_exec import SafeExecException, json_safe from codejail.safe_exec import not_safe_exec as codejail_not_safe_exec from codejail.safe_exec import safe_exec as codejail_safe_exec +import six from six import text_type from . import lazymod @@ -64,7 +65,7 @@ def update_hash(hasher, obj): `obj` in the process. Only primitive JSON-safe types are supported. """ - hasher.update(str(type(obj))) + hasher.update(six.b(str(type(obj)))) if isinstance(obj, (tuple, list)): for e in obj: update_hash(hasher, e) @@ -73,7 +74,7 @@ def update_hash(hasher, obj): update_hash(hasher, k) update_hash(hasher, obj[k]) else: - hasher.update(repr(obj)) + hasher.update(six.b(repr(obj))) def safe_exec( @@ -116,7 +117,7 @@ def safe_exec( if cache: safe_globals = json_safe(globals_dict) md5er = hashlib.md5() - md5er.update(repr(code)) + md5er.update(six.b(repr(code))) update_hash(md5er, safe_globals) key = "safe_exec.%r.%s" % (random_seed, md5er.hexdigest()) cached = cache.get(key) diff --git a/common/lib/xmodule/xmodule/capa_base.py b/common/lib/xmodule/xmodule/capa_base.py index 167df35e7c..52d474cdfb 100644 --- a/common/lib/xmodule/xmodule/capa_base.py +++ b/common/lib/xmodule/xmodule/capa_base.py @@ -85,8 +85,8 @@ def randomization_bin(seed, problem_id): we'll combine the system's per-student seed with the problem id in picking the bin. """ r_hash = hashlib.sha1() - r_hash.update(str(seed)) - r_hash.update(str(problem_id)) + r_hash.update(six.b(str(seed))) + r_hash.update(six.b(str(problem_id))) # get the first few digits of the hash, convert to an int, then mod. return int(r_hash.hexdigest()[:7], 16) % NUM_RANDOMIZATION_BINS diff --git a/lms/djangoapps/instructor_task/api_helper.py b/lms/djangoapps/instructor_task/api_helper.py index 10afaef641..01e9400775 100644 --- a/lms/djangoapps/instructor_task/api_helper.py +++ b/lms/djangoapps/instructor_task/api_helper.py @@ -14,6 +14,7 @@ from celery.result import AsyncResult from celery.states import FAILURE, READY_STATES, REVOKED, SUCCESS from django.utils.translation import ugettext as _ from opaque_keys.edx.keys import UsageKey +import six from six import text_type from courseware.courses import get_problems_in_section @@ -390,7 +391,7 @@ def encode_problem_and_student_input(usage_key, student=None): task_key_stub = "_{problem}".format(problem=text_type(usage_key)) # create the key value by using MD5 hash: - task_key = hashlib.md5(task_key_stub).hexdigest() + task_key = hashlib.md5(six.b(task_key_stub)).hexdigest() return task_input, task_key