From 9301ec38f35d840984602fa911795b11bcfe2ad6 Mon Sep 17 00:00:00 2001 From: aarif Date: Thu, 12 Sep 2019 17:29:34 +0500 Subject: [PATCH] python 3 fixes --- cms/djangoapps/contentstore/views/item.py | 2 +- common/lib/xmodule/xmodule/modulestore/split_mongo/split.py | 2 +- lms/djangoapps/badges/backends/badgr.py | 2 +- lms/djangoapps/course_api/tests/test_api.py | 2 +- lms/djangoapps/courseware/module_render.py | 2 +- lms/djangoapps/courseware/tests/test_module_render.py | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cms/djangoapps/contentstore/views/item.py b/cms/djangoapps/contentstore/views/item.py index 87c9df98ac..a21bf41f5c 100644 --- a/cms/djangoapps/contentstore/views/item.py +++ b/cms/djangoapps/contentstore/views/item.py @@ -92,7 +92,7 @@ def hash_resource(resource): Hash a :class:`web_fragments.fragment.FragmentResource`. """ md5 = hashlib.md5() - md5.update(repr(resource)) + md5.update(repr(resource).encode('utf-8')) return md5.hexdigest() diff --git a/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py b/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py index 77eea07e6c..6cbe821deb 100644 --- a/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py +++ b/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py @@ -2597,7 +2597,7 @@ class SplitMongoModuleStore(SplitBulkWriteMixin, ModuleStoreWriteBase): block_key.id, new_parent_block_key.id, ) - new_block_id = hashlib.sha1(unique_data).hexdigest()[:20] + new_block_id = hashlib.sha1(unique_data.encode('utf-8')).hexdigest()[:20] new_block_key = BlockKey(block_key.type, new_block_id) # Now clone block_key to new_block_key: diff --git a/lms/djangoapps/badges/backends/badgr.py b/lms/djangoapps/badges/backends/badgr.py index 956b508712..4c82958825 100644 --- a/lms/djangoapps/badges/backends/badgr.py +++ b/lms/djangoapps/badges/backends/badgr.py @@ -67,7 +67,7 @@ class BadgrBackend(BadgeBackend): if badge_class.issuing_component and badge_class.course_id: # Make this unique to the course, and down to 64 characters. # We don't do this to badges without issuing_component set for backwards compatibility. - slug = hashlib.sha256(slug + six.text_type(badge_class.course_id)).hexdigest() + slug = hashlib.sha256((slug + six.text_type(badge_class.course_id)).encode('utf-8')).hexdigest() if len(slug) > MAX_SLUG_LENGTH: # Will be 64 characters. slug = hashlib.sha256(slug).hexdigest() diff --git a/lms/djangoapps/course_api/tests/test_api.py b/lms/djangoapps/course_api/tests/test_api.py index 907ff569cb..b359c6f104 100644 --- a/lms/djangoapps/course_api/tests/test_api.py +++ b/lms/djangoapps/course_api/tests/test_api.py @@ -176,7 +176,7 @@ class TestGetCourseListMultipleCourses(CourseListTestMixin, ModuleStoreTestCase) """Verify that courses are filtered by the provided org key.""" # Create a second course to be filtered out of queries. alternate_course = self.create_course( - org=md5(self.course.org).hexdigest() + org=md5(self.course.org.encode('utf-8')).hexdigest() ) self.assertNotEqual(alternate_course.org, self.course.org) diff --git a/lms/djangoapps/courseware/module_render.py b/lms/djangoapps/courseware/module_render.py index 6f6cce2750..cdd9f8c6d8 100644 --- a/lms/djangoapps/courseware/module_render.py +++ b/lms/djangoapps/courseware/module_render.py @@ -1225,7 +1225,7 @@ def hash_resource(resource): """ md5 = hashlib.md5() for data in resource: - md5.update(repr(data)) + md5.update(repr(data).encode('utf-8')) return md5.hexdigest() diff --git a/lms/djangoapps/courseware/tests/test_module_render.py b/lms/djangoapps/courseware/tests/test_module_render.py index e5ada7ec0e..4ee1b6ca1d 100644 --- a/lms/djangoapps/courseware/tests/test_module_render.py +++ b/lms/djangoapps/courseware/tests/test_module_render.py @@ -1402,7 +1402,7 @@ class TestProctoringRendering(SharedModuleStoreTestCase): ) if attempt_status: - create_exam_attempt(exam_id, self.request.user.id, taking_as_proctored=True) + create_exam_attempt(six.text_type(exam_id).encode('utf-8'), self.request.user.id, taking_as_proctored=True) update_attempt_status(exam_id, self.request.user.id, attempt_status) return usage_key