From 089eddc47abf26545219a08b4a319b4467c65834 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Wed, 8 Nov 2017 23:48:52 +0000 Subject: [PATCH] Eliminate references to django.utils.six.text_type --- wagtail/tests/customuser/fields.py | 3 +-- wagtail/tests/customuser/tests.py | 3 +-- wagtail/tests/testapp/models.py | 3 +-- wagtail/utils/setup.py | 4 +--- wagtail/wagtailadmin/edit_handlers.py | 3 +-- wagtail/wagtailadmin/menu.py | 6 +++--- wagtail/wagtailadmin/search.py | 4 ++-- wagtail/wagtailcore/blocks/field_block.py | 5 ++--- wagtail/wagtailcore/models.py | 2 +- wagtail/wagtailcore/tests/test_streamfield.py | 3 +-- wagtail/wagtailforms/models.py | 3 +-- wagtail/wagtailimages/models.py | 4 ++-- wagtail/wagtailimages/views/serve.py | 3 +-- wagtail/wagtailsearch/backends/base.py | 3 +-- wagtail/wagtailsnippets/views/chooser.py | 3 +-- 15 files changed, 20 insertions(+), 32 deletions(-) diff --git a/wagtail/tests/customuser/fields.py b/wagtail/tests/customuser/fields.py index eb38c93299..059b161b64 100644 --- a/wagtail/tests/customuser/fields.py +++ b/wagtail/tests/customuser/fields.py @@ -3,14 +3,13 @@ from __future__ import absolute_import, unicode_literals import random from django.db import models -from django.utils.six import text_type LOWER_BOUND = -2147483648 UPPER_BOUND = 2147483647 SHIFT = 92147483647 -class ConvertedValue(text_type): +class ConvertedValue(str): def __new__(cls, value): value = int(value) diff --git a/wagtail/tests/customuser/tests.py b/wagtail/tests/customuser/tests.py index 299a24adff..fdc0ec74bc 100644 --- a/wagtail/tests/customuser/tests.py +++ b/wagtail/tests/customuser/tests.py @@ -4,7 +4,6 @@ import json from django.db import connections from django.test import TestCase -from django.utils.six import text_type from wagtail.tests.utils import WagtailTestUtils @@ -21,7 +20,7 @@ class TestConvertedValueField(TestCase, WagtailTestUtils): def test_db_value_is_different(self): self.assertEqual(self.user.pk, self.pk_db_value) - self.assertNotEqual(text_type(self.user.pk), text_type(self.pk_db_value)) + self.assertNotEqual(str(self.user.pk), str(self.pk_db_value)) def test_custom_user_primary_key_is_hashable(self): hash(self.user.pk) diff --git a/wagtail/tests/testapp/models.py b/wagtail/tests/testapp/models.py index 1000503b82..b9770e229b 100644 --- a/wagtail/tests/testapp/models.py +++ b/wagtail/tests/testapp/models.py @@ -12,7 +12,6 @@ from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator from django.core.serializers.json import DjangoJSONEncoder from django.db import models from django.shortcuts import render -from django.utils.six import text_type from modelcluster.contrib.taggit import ClusterTaggableManager from modelcluster.fields import ParentalKey, ParentalManyToManyField from modelcluster.models import ClusterableModel @@ -463,7 +462,7 @@ class FormPageWithCustomSubmission(AbstractEmailForm): if self.to_address: addresses = [x.strip() for x in self.to_address.split(',')] - content = '\n'.join([x[1].label + ': ' + text_type(form.data.get(x[0])) for x in form.fields.items()]) + content = '\n'.join([x[1].label + ': ' + str(form.data.get(x[0])) for x in form.fields.items()]) send_mail(self.subject, content, addresses, self.from_address,) def serve(self, request, *args, **kwargs): diff --git a/wagtail/utils/setup.py b/wagtail/utils/setup.py index d06cecc09c..c2e23d0149 100644 --- a/wagtail/utils/setup.py +++ b/wagtail/utils/setup.py @@ -45,9 +45,7 @@ class assets_mixin(object): try: with io.open(path, 'w', encoding='utf-8') as f: - from django.utils import six - - f.write(six.text_type(json.dumps(package, indent=2, ensure_ascii=False))) + f.write(str(json.dumps(package, indent=2, ensure_ascii=False))) except (IOError) as e: print('Error setting the version for front-end assets: ' + str(e)) # noqa raise SystemExit(1) diff --git a/wagtail/wagtailadmin/edit_handlers.py b/wagtail/wagtailadmin/edit_handlers.py index f63db6ab5a..2d4b23a078 100644 --- a/wagtail/wagtailadmin/edit_handlers.py +++ b/wagtail/wagtailadmin/edit_handlers.py @@ -10,7 +10,6 @@ from django.forms.models import fields_for_model from django.template.loader import render_to_string from django.utils.functional import curry from django.utils.safestring import mark_safe -from django.utils.six import text_type from django.utils.translation import ugettext_lazy from taggit.managers import TaggableManager @@ -188,7 +187,7 @@ class EditHandler(object): """ rendered_fields = self.required_fields() missing_fields_html = [ - text_type(self.form[field_name]) + str(self.form[field_name]) for field_name in self.form.fields if field_name not in rendered_fields ] diff --git a/wagtail/wagtailadmin/menu.py b/wagtail/wagtailadmin/menu.py index faf0a6f8c9..ba65bf753d 100644 --- a/wagtail/wagtailadmin/menu.py +++ b/wagtail/wagtailadmin/menu.py @@ -5,7 +5,7 @@ from django.forms import Media, MediaDefiningClass from django.forms.utils import flatatt from django.template.loader import render_to_string from django.utils.safestring import mark_safe -from django.utils.six import text_type, with_metaclass +from django.utils.six import with_metaclass from django.utils.text import slugify from wagtail.wagtailcore import hooks @@ -18,7 +18,7 @@ class MenuItem(with_metaclass(MediaDefiningClass)): self.label = label self.url = url self.classnames = classnames - self.name = (name or slugify(text_type(label))) + self.name = (name or slugify(str(label))) self.order = order if attrs: @@ -34,7 +34,7 @@ class MenuItem(with_metaclass(MediaDefiningClass)): return True def is_active(self, request): - return request.path.startswith(text_type(self.url)) + return request.path.startswith(str(self.url)) def get_context(self, request): """Defines context for the template, overridable to use more data""" diff --git a/wagtail/wagtailadmin/search.py b/wagtail/wagtailadmin/search.py index ce598425cd..799a96ef02 100644 --- a/wagtail/wagtailadmin/search.py +++ b/wagtail/wagtailadmin/search.py @@ -5,7 +5,7 @@ from django.forms.utils import flatatt from django.template.loader import render_to_string from django.utils.functional import cached_property, total_ordering from django.utils.safestring import mark_safe -from django.utils.six import text_type, with_metaclass +from django.utils.six import with_metaclass from django.utils.text import slugify from wagtail.wagtailadmin.forms import SearchForm @@ -20,7 +20,7 @@ class SearchArea(with_metaclass(MediaDefiningClass)): self.label = label self.url = url self.classnames = classnames - self.name = (name or slugify(text_type(label))) + self.name = (name or slugify(str(label))) self.order = order if attrs: diff --git a/wagtail/wagtailcore/blocks/field_block.py b/wagtail/wagtailcore/blocks/field_block.py index ff7b0dbe2f..72560ff278 100644 --- a/wagtail/wagtailcore/blocks/field_block.py +++ b/wagtail/wagtailcore/blocks/field_block.py @@ -6,7 +6,6 @@ from django import forms from django.db.models.fields import BLANK_CHOICE_DASH from django.forms.fields import CallableChoiceIterator from django.template.loader import render_to_string -from django.utils import six from django.utils.dateparse import parse_date, parse_datetime, parse_time from django.utils.encoding import force_text from django.utils.functional import cached_property @@ -515,11 +514,11 @@ class RawHTMLBlock(FieldBlock): def get_prep_value(self, value): # explicitly convert to a plain string, just in case we're using some serialisation method # that doesn't cope with SafeText values correctly - return six.text_type(value) + return str(value) def value_for_form(self, value): # need to explicitly mark as unsafe, or it'll output unescaped HTML in the textarea - return six.text_type(value) + return str(value) def value_from_form(self, value): return mark_safe(value) diff --git a/wagtail/wagtailcore/models.py b/wagtail/wagtailcore/models.py index ddcb40e1dd..f31e1fe95d 100644 --- a/wagtail/wagtailcore/models.py +++ b/wagtail/wagtailcore/models.py @@ -1518,7 +1518,7 @@ class PageRevision(models.Model): return self.get_next_by_created_at(page=self.page) def __str__(self): - return '"' + six.text_type(self.page) + '" at ' + six.text_type(self.created_at) + return '"' + str(self.page) + '" at ' + str(self.created_at) class Meta: verbose_name = _('page revision') diff --git a/wagtail/wagtailcore/tests/test_streamfield.py b/wagtail/wagtailcore/tests/test_streamfield.py index c9318fde7c..22c400322a 100644 --- a/wagtail/wagtailcore/tests/test_streamfield.py +++ b/wagtail/wagtailcore/tests/test_streamfield.py @@ -8,7 +8,6 @@ from django.db import models from django.template import Context, Template, engines from django.test import TestCase from django.utils.safestring import SafeText -from django.utils.six import text_type from wagtail.tests.testapp.models import StreamModel from wagtail.wagtailcore import blocks @@ -189,7 +188,7 @@ class TestStreamFieldRenderingBase(TestCase): class TestStreamFieldRendering(TestStreamFieldRenderingBase): def test_to_string(self): - rendered = text_type(self.instance.body) + rendered = str(self.instance.body) self.assertHTMLEqual(rendered, self.expected) self.assertIsInstance(rendered, SafeText) diff --git a/wagtail/wagtailforms/models.py b/wagtail/wagtailforms/models.py index 4ea6f1e8c3..ca7380cb89 100644 --- a/wagtail/wagtailforms/models.py +++ b/wagtail/wagtailforms/models.py @@ -7,7 +7,6 @@ from django.contrib.contenttypes.models import ContentType from django.core.serializers.json import DjangoJSONEncoder from django.db import models from django.shortcuts import render -from django.utils.six import text_type from django.utils.text import slugify from django.utils.translation import ugettext_lazy as _ from unidecode import unidecode @@ -104,7 +103,7 @@ class AbstractFormField(Orderable): # unidecode will return an ascii string while slugify wants a # unicode string on the other hand, slugify returns a safe-string # which will be converted to a normal str - return str(slugify(text_type(unidecode(self.label)))) + return str(slugify(str(unidecode(self.label)))) panels = [ FieldPanel('label'), diff --git a/wagtail/wagtailimages/models.py b/wagtail/wagtailimages/models.py index 4246041ffd..a62405c48d 100644 --- a/wagtail/wagtailimages/models.py +++ b/wagtail/wagtailimages/models.py @@ -14,7 +14,7 @@ from django.forms.utils import flatatt from django.urls import reverse from django.utils.functional import cached_property from django.utils.safestring import mark_safe -from django.utils.six import BytesIO, string_types, text_type +from django.utils.six import BytesIO, string_types from django.utils.translation import ugettext_lazy as _ from taggit.managers import TaggableManager from unidecode import unidecode @@ -168,7 +168,7 @@ class AbstractImage(CollectionMember, index.Indexed, models.Model): except IOError as e: # re-throw this as a SourceImageIOError so that calling code can distinguish # these from IOErrors elsewhere in the process - raise SourceImageIOError(text_type(e)) + raise SourceImageIOError(str(e)) # Seek to beginning image_file.seek(0) diff --git a/wagtail/wagtailimages/views/serve.py b/wagtail/wagtailimages/views/serve.py index cb1cd52114..c842c0b435 100644 --- a/wagtail/wagtailimages/views/serve.py +++ b/wagtail/wagtailimages/views/serve.py @@ -11,7 +11,6 @@ from django.core.exceptions import ImproperlyConfigured, PermissionDenied from django.http import HttpResponse, HttpResponsePermanentRedirect, StreamingHttpResponse from django.shortcuts import get_object_or_404 from django.utils.decorators import classonlymethod -from django.utils.six import text_type from django.views.generic import View from wagtail.utils.sendfile import sendfile @@ -25,7 +24,7 @@ def generate_signature(image_id, filter_spec, key=None): key = settings.SECRET_KEY # Key must be a bytes object - if isinstance(key, text_type): + if isinstance(key, str): key = key.encode() # Based on libthumbor hmac generation diff --git a/wagtail/wagtailsearch/backends/base.py b/wagtail/wagtailsearch/backends/base.py index dd9e95bb4a..c0fc4cc8ab 100644 --- a/wagtail/wagtailsearch/backends/base.py +++ b/wagtail/wagtailsearch/backends/base.py @@ -4,7 +4,6 @@ from __future__ import absolute_import, unicode_literals from django.db.models.lookups import Lookup from django.db.models.query import QuerySet from django.db.models.sql.where import SubqueryConstraint, WhereNode -from django.utils.six import text_type from wagtail.wagtailsearch.index import class_is_indexed @@ -58,7 +57,7 @@ class BaseSearchQuery(object): if result is None: raise FilterError( 'Could not apply filter on search results: "' + field_attname + '__' + - lookup + ' = ' + text_type(value) + '". Lookup "' + lookup + '"" not recognised.' + lookup + ' = ' + str(value) + '". Lookup "' + lookup + '"" not recognised.' ) return result diff --git a/wagtail/wagtailsnippets/views/chooser.py b/wagtail/wagtailsnippets/views/chooser.py index e1318c1177..53c20a4593 100644 --- a/wagtail/wagtailsnippets/views/chooser.py +++ b/wagtail/wagtailsnippets/views/chooser.py @@ -4,7 +4,6 @@ import json from django.shortcuts import get_object_or_404, render from django.urls import reverse -from django.utils.six import text_type from django.utils.translation import ugettext as _ from wagtail.utils.pagination import paginate @@ -78,7 +77,7 @@ def chosen(request, app_label, model_name, id): snippet_json = json.dumps({ 'id': item.id, - 'string': text_type(item), + 'string': str(item), 'edit_link': reverse('wagtailsnippets:edit', args=( app_label, model_name, item.id)) })