From 95d4843abeecea96754a147f4f2cca33e620ad09 Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Wed, 4 Dec 2019 14:14:43 -0800 Subject: [PATCH] Fix Django 3.0 deprecations (#7074) --- rest_framework/fields.py | 4 ++-- rest_framework/relations.py | 4 ++-- rest_framework/schemas/inspectors.py | 4 ++-- rest_framework/schemas/utils.py | 2 +- rest_framework/views.py | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 9507914e8..8c80d6bd5 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -23,7 +23,7 @@ from django.utils.dateparse import ( parse_date, parse_datetime, parse_duration, parse_time ) from django.utils.duration import duration_string -from django.utils.encoding import is_protected_type, smart_text +from django.utils.encoding import is_protected_type, smart_str from django.utils.formats import localize_input, sanitize_separators from django.utils.ipv6 import clean_ipv6_address from django.utils.timezone import utc @@ -1082,7 +1082,7 @@ class DecimalField(Field): instance. """ - data = smart_text(data).strip() + data = smart_str(data).strip() if self.localize: data = sanitize_separators(data) diff --git a/rest_framework/relations.py b/rest_framework/relations.py index af4dd1804..3a2a8fb4b 100644 --- a/rest_framework/relations.py +++ b/rest_framework/relations.py @@ -6,7 +6,7 @@ from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist from django.db.models import Manager from django.db.models.query import QuerySet from django.urls import NoReverseMatch, Resolver404, get_script_prefix, resolve -from django.utils.encoding import smart_text, uri_to_iri +from django.utils.encoding import smart_str, uri_to_iri from django.utils.translation import gettext_lazy as _ from rest_framework.fields import ( @@ -452,7 +452,7 @@ class SlugRelatedField(RelatedField): try: return self.get_queryset().get(**{self.slug_field: data}) except ObjectDoesNotExist: - self.fail('does_not_exist', slug_name=self.slug_field, value=smart_text(data)) + self.fail('does_not_exist', slug_name=self.slug_field, value=smart_str(data)) except (TypeError, ValueError): self.fail('invalid') diff --git a/rest_framework/schemas/inspectors.py b/rest_framework/schemas/inspectors.py index 3b7e7f963..027472db1 100644 --- a/rest_framework/schemas/inspectors.py +++ b/rest_framework/schemas/inspectors.py @@ -6,7 +6,7 @@ See schemas.__init__.py for package overview. import re from weakref import WeakKeyDictionary -from django.utils.encoding import smart_text +from django.utils.encoding import smart_str from rest_framework.settings import api_settings from rest_framework.utils import formatting @@ -82,7 +82,7 @@ class ViewInspector: method_docstring = getattr(view, method_name, None).__doc__ if method_docstring: # An explicit docstring on the method or action. - return self._get_description_section(view, method.lower(), formatting.dedent(smart_text(method_docstring))) + return self._get_description_section(view, method.lower(), formatting.dedent(smart_str(method_docstring))) else: return self._get_description_section(view, getattr(view, 'action', method.lower()), view.get_view_description()) diff --git a/rest_framework/schemas/utils.py b/rest_framework/schemas/utils.py index 6724eb428..60ed69829 100644 --- a/rest_framework/schemas/utils.py +++ b/rest_framework/schemas/utils.py @@ -4,7 +4,7 @@ utils.py # Shared helper functions See schemas.__init__.py for package overview. """ from django.db import models -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from rest_framework.mixins import RetrieveModelMixin diff --git a/rest_framework/views.py b/rest_framework/views.py index bec10560a..69db053d6 100644 --- a/rest_framework/views.py +++ b/rest_framework/views.py @@ -7,7 +7,7 @@ from django.db import connection, models, transaction from django.http import Http404 from django.http.response import HttpResponseBase from django.utils.cache import cc_delim_re, patch_vary_headers -from django.utils.encoding import smart_text +from django.utils.encoding import smart_str from django.views.decorators.csrf import csrf_exempt from django.views.generic import View @@ -56,7 +56,7 @@ def get_view_description(view, html=False): if description is None: description = view.__class__.__doc__ or '' - description = formatting.dedent(smart_text(description)) + description = formatting.dedent(smart_str(description)) if html: return formatting.markup_description(description) return description