diff --git a/cms/djangoapps/contentstore/courseware_index.py b/cms/djangoapps/contentstore/courseware_index.py index 4161571e18..ef9946ddff 100644 --- a/cms/djangoapps/contentstore/courseware_index.py +++ b/cms/djangoapps/contentstore/courseware_index.py @@ -11,7 +11,7 @@ from django.urls import resolve from django.utils.translation import ugettext as _ from django.utils.translation import ugettext_lazy from search.search_engine_base import SearchEngine -from six import add_metaclass +from six import add_metaclass, string_types from contentstore.course_group_config import GroupConfiguration from course_modes.models import CourseMode @@ -621,7 +621,7 @@ class CourseAboutSearchIndexer(object): if section_content: if about_information.index_flags & AboutInfo.ANALYSE: analyse_content = section_content - if isinstance(section_content, basestring): + if isinstance(section_content, string_types): analyse_content = strip_html_content_to_text(section_content) course_info['content'][about_information.property_name] = analyse_content if about_information.index_flags & AboutInfo.PROPERTY: diff --git a/cms/djangoapps/contentstore/views/helpers.py b/cms/djangoapps/contentstore/views/helpers.py index 73811cf43d..e036553e32 100644 --- a/cms/djangoapps/contentstore/views/helpers.py +++ b/cms/djangoapps/contentstore/views/helpers.py @@ -7,6 +7,7 @@ from __future__ import absolute_import import urllib from uuid import uuid4 +import six from django.conf import settings from django.http import HttpResponse from django.utils.translation import ugettext as _ @@ -222,7 +223,7 @@ def create_xblock(parent_locator, user, category, display_name, boilerplate=None # TODO need to fix components that are sending definition_data as strings, instead of as dicts # For now, migrate them into dicts here. - if isinstance(data, basestring): + if isinstance(data, six.string_types): data = {'data': data} created_block = store.create_child( diff --git a/common/djangoapps/util/string_utils.py b/common/djangoapps/util/string_utils.py index 43b3a1dc92..40885d0f99 100644 --- a/common/djangoapps/util/string_utils.py +++ b/common/djangoapps/util/string_utils.py @@ -17,7 +17,7 @@ def _has_non_ascii_characters(data_string): """ Check if provided string contains non ascii characters - :param data_string: basestring or unicode object + :param data_string: str or unicode object """ try: data_string.encode('ascii') diff --git a/common/lib/capa/capa/templates/choicegroup.html b/common/lib/capa/capa/templates/choicegroup.html index d750187fa0..f4b39c7969 100644 --- a/common/lib/capa/capa/templates/choicegroup.html +++ b/common/lib/capa/capa/templates/choicegroup.html @@ -1,9 +1,12 @@ <%page expression_filter="h"/> -<%! from openedx.core.djangolib.markup import HTML %> +<%! +from openedx.core.djangolib.markup import HTML +import six +%> <% def is_radio_input(choice_id): - return input_type == 'radio' and ((isinstance(value, basestring) and (choice_id == value)) or ( - not isinstance(value, basestring) and choice_id in value + return input_type == 'radio' and ((isinstance(value, six.string_types) and (choice_id == value)) or ( + not isinstance(value, six.string_types) and choice_id in value )) %>
diff --git a/common/lib/xmodule/xmodule/assetstore/__init__.py b/common/lib/xmodule/xmodule/assetstore/__init__.py index 86e6e909f7..ec2af80340 100644 --- a/common/lib/xmodule/xmodule/assetstore/__init__.py +++ b/common/lib/xmodule/xmodule/assetstore/__init__.py @@ -57,12 +57,12 @@ class AssetMetadata(object): EXPORTED_ASSET_FILENAME = u'assets.xml' @contract(asset_id='AssetKey', - pathname='basestring|None', internal_name='basestring|None', - locked='bool|None', contenttype='basestring|None', - thumbnail='basestring|None', fields='dict|None', - curr_version='basestring|None', prev_version='basestring|None', - created_by='int|long|None', created_by_email='basestring|None', created_on='datetime|None', - edited_by='int|long|None', edited_by_email='basestring|None', edited_on='datetime|None') + pathname='str|None', internal_name='str|None', + locked='bool|None', contenttype='str|None', + thumbnail='str|None', fields='dict|None', + curr_version='str|None', prev_version='str|None', + created_by='int|long|None', created_by_email='str|None', created_on='datetime|None', + edited_by='int|long|None', edited_by_email='str|None', edited_on='datetime|None') def __init__(self, asset_id, pathname=None, internal_name=None, locked=None, contenttype=None, diff --git a/common/lib/xmodule/xmodule/library_content_module.py b/common/lib/xmodule/xmodule/library_content_module.py index f5cb4be411..beb1377fe9 100644 --- a/common/lib/xmodule/xmodule/library_content_module.py +++ b/common/lib/xmodule/xmodule/library_content_module.py @@ -237,7 +237,7 @@ class LibraryContentModule(LibraryContentFields, XModule, StudioEditableModule): Function that handles the actual publishing. Must have the signature: - <'removed'|'assigned'> -> result:T -> removed:T -> reason:basestring -> None + <'removed'|'assigned'> -> result:T -> removed:T -> reason:str -> None Where T is a collection of block_keys as returned by `format_block_keys`. diff --git a/common/lib/xmodule/xmodule/modulestore/__init__.py b/common/lib/xmodule/xmodule/modulestore/__init__.py index f274d2fa3f..7993996fe7 100644 --- a/common/lib/xmodule/xmodule/modulestore/__init__.py +++ b/common/lib/xmodule/xmodule/modulestore/__init__.py @@ -603,7 +603,7 @@ class ModuleStoreAssetBase(object): return mdata @contract( - course_key='CourseKey', asset_type='None | basestring', + course_key='CourseKey', asset_type='None | str', start='int | None', maxresults='int | None', sort='tuple(str,int) | None' ) def get_all_asset_metadata(self, course_key, asset_type, start=0, maxresults=-1, sort=None, **kwargs): diff --git a/common/lib/xmodule/xmodule/modulestore/django.py b/common/lib/xmodule/xmodule/modulestore/django.py index 75010a0f6a..4c1bd60185 100644 --- a/common/lib/xmodule/xmodule/modulestore/django.py +++ b/common/lib/xmodule/xmodule/modulestore/django.py @@ -9,6 +9,8 @@ from __future__ import absolute_import from importlib import import_module import gettext import logging + +import six from pkg_resources import resource_filename import re @@ -250,7 +252,7 @@ def create_modulestore_instance( FUNCTION_KEYS = ['render_template'] for key in FUNCTION_KEYS: - if key in _options and isinstance(_options[key], basestring): + if key in _options and isinstance(_options[key], six.string_types): _options[key] = load_function(_options[key]) request_cache = DEFAULT_REQUEST_CACHE diff --git a/common/lib/xmodule/xmodule/modulestore/mixed.py b/common/lib/xmodule/xmodule/modulestore/mixed.py index ed21b89339..e9eabb5272 100644 --- a/common/lib/xmodule/xmodule/modulestore/mixed.py +++ b/common/lib/xmodule/xmodule/modulestore/mixed.py @@ -495,7 +495,7 @@ class MixedModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase): return store.find_asset_metadata(asset_key, **kwargs) @strip_key - @contract(course_key='CourseKey', asset_type='None | basestring', start=int, maxresults=int, sort='tuple|None') + @contract(course_key='CourseKey', asset_type='None | str', start=int, maxresults=int, sort='tuple|None') def get_all_asset_metadata(self, course_key, asset_type, start=0, maxresults=-1, sort=None, **kwargs): """ Returns a list of static assets for a course. diff --git a/lms/djangoapps/courseware/rules.py b/lms/djangoapps/courseware/rules.py index 00326ec44a..7c01087c16 100644 --- a/lms/djangoapps/courseware/rules.py +++ b/lms/djangoapps/courseware/rules.py @@ -8,23 +8,23 @@ import traceback import laboratory import rules -from bridgekeeper.rules import Rule, EMPTY -from course_modes.models import CourseMode +import six +from bridgekeeper.rules import EMPTY, Rule from django.conf import settings from django.db.models import Q from opaque_keys.edx.django.models import CourseKeyField from opaque_keys.edx.keys import CourseKey, UsageKey -from openedx.core.djangoapps.content.course_overviews.models import CourseOverview -from student.models import CourseEnrollment, CourseAccessRole from xblock.core import XBlock + +from course_modes.models import CourseMode +from openedx.core.djangoapps.content.course_overviews.models import CourseOverview +from student.models import CourseAccessRole, CourseEnrollment from xmodule.course_module import CourseDescriptor from xmodule.error_module import ErrorDescriptor from xmodule.x_module import XModule - from .access import has_access - LOG = logging.getLogger(__name__) @@ -112,7 +112,7 @@ class HasStaffAccessToContent(Rule): course_key = instance elif isinstance(instance, UsageKey): course_key = instance.course_key - elif isinstance(instance, basestring): + elif isinstance(instance, six.string_types): course_key = CourseKey.from_string(instance) return self.filter(user, CourseOverview.objects.filter(id=course_key)).exists() diff --git a/lms/templates/dashboard/_dashboard_course_listing.html b/lms/templates/dashboard/_dashboard_course_listing.html index def15e99e4..44c7861c18 100644 --- a/lms/templates/dashboard/_dashboard_course_listing.html +++ b/lms/templates/dashboard/_dashboard_course_listing.html @@ -2,6 +2,7 @@ <%! import urllib +import six from django.utils.translation import ugettext as _ from django.utils.translation import ungettext @@ -149,7 +150,7 @@ from util.course import get_link_for_about_page, get_encoded_course_sharing_utm_ % endif % else: - % if isinstance(course_date, basestring): + % if isinstance(course_date, six.string_types): ${container_string.format(date=course_date)} % elif course_date is not None: diff --git a/lms/templates/experiments/user_metadata.html b/lms/templates/experiments/user_metadata.html index a8df2afcc0..00a1a3daa4 100644 --- a/lms/templates/experiments/user_metadata.html +++ b/lms/templates/experiments/user_metadata.html @@ -3,6 +3,7 @@ from openedx.core.djangolib.js_utils import dump_js_escaped_json from eventtracking import tracker from opaque_keys.edx.keys import CourseKey +import six %> <% user_metadata = { @@ -59,7 +60,7 @@ if course_key: if not course_id: user_metadata['course_id'] = unicode(course_key) - elif isinstance(course_key, basestring): + elif isinstance(course_key, six.string_types): user_metadata['course_id'] = course_key %> diff --git a/openedx/core/djangoapps/django_comment_common/tests.py b/openedx/core/djangoapps/django_comment_common/tests.py index 3935d7e623..8ca050751a 100644 --- a/openedx/core/djangoapps/django_comment_common/tests.py +++ b/openedx/core/djangoapps/django_comment_common/tests.py @@ -127,7 +127,7 @@ class CourseDiscussionSettingsTest(ModuleStoreTestCase): def test_invalid_data_types(self): exception_msg_template = "Incorrect field type for `{}`. Type must be `{}`" fields = [ - {'name': 'division_scheme', 'type': basestring}, + {'name': 'division_scheme', 'type': six.string_types[0]}, {'name': 'always_divide_inline_discussions', 'type': bool}, {'name': 'divided_discussions', 'type': list} ] diff --git a/openedx/core/djangoapps/django_comment_common/utils.py b/openedx/core/djangoapps/django_comment_common/utils.py index fd05b19b7e..77bf03cf82 100644 --- a/openedx/core/djangoapps/django_comment_common/utils.py +++ b/openedx/core/djangoapps/django_comment_common/utils.py @@ -153,10 +153,11 @@ def set_course_discussion_settings(course_key, **kwargs): A CourseDiscussionSettings object. """ fields = { - 'division_scheme': basestring, + 'division_scheme': six.string_types[0], 'always_divide_inline_discussions': bool, 'divided_discussions': list, } + course_discussion_settings = get_course_discussion_settings(course_key) for field, field_type in fields.items(): if field in kwargs: