diff --git a/openedx/core/djangolib/fields.py b/openedx/core/djangolib/fields.py
index a93a350661..a15bcd1a21 100644
--- a/openedx/core/djangolib/fields.py
+++ b/openedx/core/djangolib/fields.py
@@ -1,6 +1,7 @@
"""
Custom Django fields.
"""
+from __future__ import absolute_import
from django.db import models
diff --git a/openedx/core/djangolib/js_utils.py b/openedx/core/djangolib/js_utils.py
index b8356dbdac..c8fed03af0 100644
--- a/openedx/core/djangolib/js_utils.py
+++ b/openedx/core/djangolib/js_utils.py
@@ -1,6 +1,7 @@
"""
Utilities for dealing with Javascript and JSON.
"""
+from __future__ import absolute_import
import json
from django.utils.html import escapejs
diff --git a/openedx/core/djangolib/markup.py b/openedx/core/djangolib/markup.py
index 42ff88b26a..d06ac3a4d6 100644
--- a/openedx/core/djangolib/markup.py
+++ b/openedx/core/djangolib/markup.py
@@ -2,6 +2,7 @@
Utilities for use in Mako markup.
"""
+from __future__ import absolute_import
import markupsafe
import bleach
from mako.filters import decode
diff --git a/openedx/core/djangolib/oauth2_retirement_utils.py b/openedx/core/djangolib/oauth2_retirement_utils.py
index 2d02b6964d..6e2ee15672 100644
--- a/openedx/core/djangolib/oauth2_retirement_utils.py
+++ b/openedx/core/djangolib/oauth2_retirement_utils.py
@@ -2,6 +2,7 @@
Removes user PII from OAuth2 models.
"""
+from __future__ import absolute_import
from oauth2_provider.models import (
AccessToken as DOTAccessToken,
Application as DOTApplication,
diff --git a/openedx/core/djangolib/testing/tests/test_utils.py b/openedx/core/djangolib/testing/tests/test_utils.py
index a8b14f5e72..951bba414e 100644
--- a/openedx/core/djangolib/testing/tests/test_utils.py
+++ b/openedx/core/djangolib/testing/tests/test_utils.py
@@ -1,6 +1,7 @@
"""
Test that testing utils do what they say.
"""
+from __future__ import absolute_import
from crum import set_current_request
from django.contrib.auth import get_user_model
diff --git a/openedx/core/djangolib/testing/utils.py b/openedx/core/djangolib/testing/utils.py
index a362985547..81d38ad7a9 100644
--- a/openedx/core/djangolib/testing/utils.py
+++ b/openedx/core/djangolib/testing/utils.py
@@ -8,6 +8,7 @@ Utility classes for testing django applications.
A TestCase baseclass that has per-test isolated caches.
"""
+from __future__ import absolute_import
import copy
import re
from unittest import skipUnless
diff --git a/openedx/core/djangolib/tests/test_js_utils.py b/openedx/core/djangolib/tests/test_js_utils.py
index 6eba7bef43..0b25cccf17 100644
--- a/openedx/core/djangolib/tests/test_js_utils.py
+++ b/openedx/core/djangolib/tests/test_js_utils.py
@@ -3,13 +3,15 @@
"""
Tests for js_utils.py
"""
-import HTMLParser
+from __future__ import absolute_import
+import six.moves.html_parser # pylint: disable=import-error
import json
from unittest import TestCase
from mako.template import Template
from openedx.core.djangolib.js_utils import dump_js_escaped_json, js_escaped_string
+import six # pylint: disable=ungrouped-imports
class TestJSUtils(TestCase):
@@ -71,7 +73,7 @@ class TestJSUtils(TestCase):
"""
malicious_js_string = ""
- expected_escaped_string_for_js = unicode(
+ expected_escaped_string_for_js = six.text_type(
r"\u003C/script\u003E\u003Cscript\u003Ealert(\u0027hello, \u0027)\u003B\u003C/script\u003E"
)
escaped_string_for_js = js_escaped_string(malicious_js_string)
@@ -179,7 +181,7 @@ class TestJSUtils(TestCase):
should be parseable into a near equivalent to test_dict.
"""
- html_parser = HTMLParser.HTMLParser()
+ html_parser = six.moves.html_parser.HTMLParser()
expected_json = html_parser.unescape(expected_json_for_html_string)
parsed_expected_dict = json.loads(expected_json)
diff --git a/openedx/core/djangolib/tests/test_markup.py b/openedx/core/djangolib/tests/test_markup.py
index b8800b8fd0..9d68a6f333 100644
--- a/openedx/core/djangolib/tests/test_markup.py
+++ b/openedx/core/djangolib/tests/test_markup.py
@@ -3,6 +3,7 @@
Tests for openedx.core.djangolib.markup
"""
+from __future__ import absolute_import
import unittest
import ddt
@@ -11,6 +12,7 @@ from django.utils.translation import ungettext
from mako.template import Template
from openedx.core.djangolib.markup import HTML, Text, strip_all_tags_but_br
+import six
@ddt.ddt
@@ -27,8 +29,8 @@ class FormatHtmlTest(unittest.TestCase):
)
def test_simple(self, before_after):
(before, after) = before_after
- self.assertEqual(unicode(Text(_(before))), after)
- self.assertEqual(unicode(Text(before)), after)
+ self.assertEqual(six.text_type(Text(_(before))), after) # pylint: disable=translation-of-non-string
+ self.assertEqual(six.text_type(Text(before)), after)
def test_formatting(self):
# The whole point of this function is to make sure this works:
@@ -37,7 +39,7 @@ class FormatHtmlTest(unittest.TestCase):
end=HTML(""),
)
self.assertEqual(
- unicode(out),
+ six.text_type(out),
u"Point & click here!",
)
@@ -49,7 +51,7 @@ class FormatHtmlTest(unittest.TestCase):
end=HTML(""),
)
self.assertEqual(
- unicode(out),
+ six.text_type(out),
u"Send email",
)
diff --git a/openedx/core/djangolib/tests/test_oauth2_retirement_utils.py b/openedx/core/djangolib/tests/test_oauth2_retirement_utils.py
index fcc13ce344..aa150ec77e 100644
--- a/openedx/core/djangolib/tests/test_oauth2_retirement_utils.py
+++ b/openedx/core/djangolib/tests/test_oauth2_retirement_utils.py
@@ -2,6 +2,7 @@
Contains tests for OAuth2 model-retirement methods.
"""
+from __future__ import absolute_import
import datetime
from django.test import TestCase
diff --git a/openedx/core/djangolib/tests/test_translation_utils.py b/openedx/core/djangolib/tests/test_translation_utils.py
index f122834343..af88277c28 100644
--- a/openedx/core/djangolib/tests/test_translation_utils.py
+++ b/openedx/core/djangolib/tests/test_translation_utils.py
@@ -3,6 +3,7 @@
Tests for openedx.core.djangolib.translation_utils
"""
+from __future__ import absolute_import
import unittest
import datetime
diff --git a/openedx/core/djangolib/translation_utils.py b/openedx/core/djangolib/translation_utils.py
index 51617be121..9f8a8b6ac1 100644
--- a/openedx/core/djangolib/translation_utils.py
+++ b/openedx/core/djangolib/translation_utils.py
@@ -1,3 +1,8 @@
+"""
+i18n utility functions
+"""
+
+from __future__ import absolute_import
from django.utils.translation import ugettext as _, override
from django.utils.formats import dateformat, get_format