* INCR-145: Run python-modernize on openedx/core/djangoapps/contentserver

* INCR-145: [FIXED] line over length limit

* INCR-145: [ADD] Missing whitespace
This commit is contained in:
Amit
2019-05-10 00:44:45 +03:00
committed by Jeremy Bowman
parent a74cddefee
commit 1d1bbc3176
7 changed files with 27 additions and 10 deletions

View File

@@ -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

View File

@@ -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:

View File

@@ -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':

View File

@@ -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

View File

@@ -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

View File

@@ -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 '<CourseAssetCacheTtlConfig(cache_ttl={})>'.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 '<WhitelistedCdnConfig(cdn_user_agents={})>'.format(self.get_cdn_user_agents())
def __unicode__(self):
return unicode(repr(self))
return six.text_type(repr(self))

View File

@@ -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')