From 1d1bbc3176e47e66c498d75e769ee8ed99b0acd1 Mon Sep 17 00:00:00 2001 From: Amit <43564590+amitvadhel@users.noreply.github.com> Date: Fri, 10 May 2019 00:44:45 +0300 Subject: [PATCH] INCR-145 (#20486) * INCR-145: Run python-modernize on openedx/core/djangoapps/contentserver * INCR-145: [FIXED] line over length limit * INCR-145: [ADD] Missing whitespace --- openedx/core/djangoapps/contentserver/admin.py | 2 ++ openedx/core/djangoapps/contentserver/caching.py | 10 +++++++--- openedx/core/djangoapps/contentserver/middleware.py | 6 +++++- .../contentserver/migrations/0001_initial.py | 2 +- .../migrations/0002_cdnuseragentsconfig.py | 2 +- openedx/core/djangoapps/contentserver/models.py | 8 ++++++-- .../contentserver/test/test_contentserver.py | 7 +++++-- 7 files changed, 27 insertions(+), 10 deletions(-) diff --git a/openedx/core/djangoapps/contentserver/admin.py b/openedx/core/djangoapps/contentserver/admin.py index cf663403f0..416973de7e 100644 --- a/openedx/core/djangoapps/contentserver/admin.py +++ b/openedx/core/djangoapps/contentserver/admin.py @@ -2,6 +2,8 @@ Django admin page for CourseAssetCacheTtlConfig, which allows you to configure the TTL that gets used when sending cachability headers back with request course assets. """ +from __future__ import absolute_import + from config_models.admin import ConfigurationModelAdmin from django.contrib import admin diff --git a/openedx/core/djangoapps/contentserver/caching.py b/openedx/core/djangoapps/contentserver/caching.py index b7bfdb2b75..41af2582f7 100644 --- a/openedx/core/djangoapps/contentserver/caching.py +++ b/openedx/core/djangoapps/contentserver/caching.py @@ -1,6 +1,10 @@ """ Helper functions for caching course assets. """ +from __future__ import absolute_import + +import six + from django.core.cache import caches from django.core.cache.backends.base import InvalidCacheBackendError from opaque_keys import InvalidKeyError @@ -19,14 +23,14 @@ def set_cached_content(content): """ Stores the given piece of content in the cache, using its location as the key. """ - CONTENT_CACHE.set(unicode(content.location).encode("utf-8"), content, version=STATIC_CONTENT_VERSION) + CONTENT_CACHE.set(six.text_type(content.location).encode("utf-8"), content, version=STATIC_CONTENT_VERSION) def get_cached_content(location): """ Retrieves the given piece of content by its location if cached. """ - return CONTENT_CACHE.get(unicode(location).encode("utf-8"), version=STATIC_CONTENT_VERSION) + return CONTENT_CACHE.get(six.text_type(location).encode("utf-8"), version=STATIC_CONTENT_VERSION) def del_cached_content(location): @@ -38,7 +42,7 @@ def del_cached_content(location): """ def location_str(loc): """Force the location to a Unicode string.""" - return unicode(loc).encode("utf-8") + return six.text_type(loc).encode("utf-8") locations = [location_str(location)] try: diff --git a/openedx/core/djangoapps/contentserver/middleware.py b/openedx/core/djangoapps/contentserver/middleware.py index ed587049ce..1ce41a0618 100644 --- a/openedx/core/djangoapps/contentserver/middleware.py +++ b/openedx/core/djangoapps/contentserver/middleware.py @@ -2,8 +2,11 @@ Middleware to serve assets. """ +from __future__ import absolute_import + import logging import datetime +import six log = logging.getLogger(__name__) try: import newrelic.agent @@ -133,7 +136,8 @@ class StaticContentServer(object): except ValueError as exception: # If the header field is syntactically invalid it should be ignored. log.exception( - u"%s in Range header: %s for content: %s", text_type(exception), header_value, unicode(loc) + u"%s in Range header: %s for content: %s", + text_type(exception), header_value, six.text_type(loc) ) else: if unit != 'bytes': diff --git a/openedx/core/djangoapps/contentserver/migrations/0001_initial.py b/openedx/core/djangoapps/contentserver/migrations/0001_initial.py index 7ba62f8503..8e946537eb 100644 --- a/openedx/core/djangoapps/contentserver/migrations/0001_initial.py +++ b/openedx/core/djangoapps/contentserver/migrations/0001_initial.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- #pylint: skip-file -from __future__ import unicode_literals +from __future__ import absolute_import, unicode_literals from django.db import migrations, models import django.db.models.deletion diff --git a/openedx/core/djangoapps/contentserver/migrations/0002_cdnuseragentsconfig.py b/openedx/core/djangoapps/contentserver/migrations/0002_cdnuseragentsconfig.py index a078ae35e5..4598cbed3f 100644 --- a/openedx/core/djangoapps/contentserver/migrations/0002_cdnuseragentsconfig.py +++ b/openedx/core/djangoapps/contentserver/migrations/0002_cdnuseragentsconfig.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import absolute_import, unicode_literals from django.db import migrations, models import django.db.models.deletion diff --git a/openedx/core/djangoapps/contentserver/models.py b/openedx/core/djangoapps/contentserver/models.py index 23c9c6f16b..13463ad643 100644 --- a/openedx/core/djangoapps/contentserver/models.py +++ b/openedx/core/djangoapps/contentserver/models.py @@ -2,6 +2,10 @@ Models for contentserver """ +from __future__ import absolute_import + +import six + from config_models.models import ConfigurationModel from django.db.models.fields import PositiveIntegerField, TextField @@ -30,7 +34,7 @@ class CourseAssetCacheTtlConfig(ConfigurationModel): return ''.format(self.get_cache_ttl()) def __unicode__(self): - return unicode(repr(self)) + return six.text_type(repr(self)) class CdnUserAgentsConfig(ConfigurationModel): @@ -57,4 +61,4 @@ class CdnUserAgentsConfig(ConfigurationModel): return ''.format(self.get_cdn_user_agents()) def __unicode__(self): - return unicode(repr(self)) + return six.text_type(repr(self)) diff --git a/openedx/core/djangoapps/contentserver/test/test_contentserver.py b/openedx/core/djangoapps/contentserver/test/test_contentserver.py index a2d16aac5d..b74e88e5d8 100644 --- a/openedx/core/djangoapps/contentserver/test/test_contentserver.py +++ b/openedx/core/djangoapps/contentserver/test/test_contentserver.py @@ -1,11 +1,14 @@ """ Tests for StaticContentServer """ +from __future__ import absolute_import + import copy import datetime import ddt import logging +import six import unittest from uuid import uuid4 @@ -89,14 +92,14 @@ class ContentStoreToyCourseTest(SharedModuleStoreTestCase): # A locked asset cls.locked_asset = cls.course_key.make_asset_key('asset', 'sample_static.html') - cls.url_locked = unicode(cls.locked_asset) + cls.url_locked = six.text_type(cls.locked_asset) cls.url_locked_versioned = get_versioned_asset_url(cls.url_locked) cls.url_locked_versioned_old_style = get_old_style_versioned_asset_url(cls.url_locked) cls.contentstore.set_attr(cls.locked_asset, 'locked', True) # An unlocked asset cls.unlocked_asset = cls.course_key.make_asset_key('asset', 'another_static.txt') - cls.url_unlocked = unicode(cls.unlocked_asset) + cls.url_unlocked = six.text_type(cls.unlocked_asset) cls.url_unlocked_versioned = get_versioned_asset_url(cls.url_unlocked) cls.url_unlocked_versioned_old_style = get_old_style_versioned_asset_url(cls.url_unlocked) cls.length_unlocked = cls.contentstore.get_attr(cls.unlocked_asset, 'length')