mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-30 18:09:59 +03:00
remove more python2 compat codes
This commit is contained in:
parent
1b817d92b4
commit
bcf64e57af
|
@ -10,12 +10,7 @@ from django.core import validators
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
from django.views.generic import View
|
from django.views.generic import View
|
||||||
|
|
||||||
try:
|
from collections.abc import Mapping, MutableMapping # noqa
|
||||||
# Python 3
|
|
||||||
from collections.abc import Mapping, MutableMapping # noqa
|
|
||||||
except ImportError:
|
|
||||||
# Python 2.7
|
|
||||||
from collections import Mapping, MutableMapping # noqa
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from django.urls import ( # noqa
|
from django.urls import ( # noqa
|
||||||
|
@ -292,7 +287,7 @@ else:
|
||||||
INDENT_SEPARATORS = (b',', b': ')
|
INDENT_SEPARATORS = (b',', b': ')
|
||||||
|
|
||||||
|
|
||||||
class CustomValidatorMessage(object):
|
class CustomValidatorMessage:
|
||||||
"""
|
"""
|
||||||
We need to avoid evaluation of `lazy` translated `message` in `django.core.validators.BaseValidator.__init__`.
|
We need to avoid evaluation of `lazy` translated `message` in `django.core.validators.BaseValidator.__init__`.
|
||||||
https://github.com/django/django/blob/75ed5900321d170debef4ac452b8b3cf8a1c2384/django/core/validators.py#L297
|
https://github.com/django/django/blob/75ed5900321d170debef4ac452b8b3cf8a1c2384/django/core/validators.py#L297
|
||||||
|
@ -302,7 +297,7 @@ class CustomValidatorMessage(object):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.message = kwargs.pop('message', self.message)
|
self.message = kwargs.pop('message', self.message)
|
||||||
super(CustomValidatorMessage, self).__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class MinValueValidator(CustomValidatorMessage, validators.MinValueValidator):
|
class MinValueValidator(CustomValidatorMessage, validators.MinValueValidator):
|
||||||
|
|
|
@ -183,18 +183,18 @@ def iter_options(grouped_choices, cutoff=None, cutoff_text=None):
|
||||||
"""
|
"""
|
||||||
Helper function for options and option groups in templates.
|
Helper function for options and option groups in templates.
|
||||||
"""
|
"""
|
||||||
class StartOptionGroup(object):
|
class StartOptionGroup:
|
||||||
start_option_group = True
|
start_option_group = True
|
||||||
end_option_group = False
|
end_option_group = False
|
||||||
|
|
||||||
def __init__(self, label):
|
def __init__(self, label):
|
||||||
self.label = label
|
self.label = label
|
||||||
|
|
||||||
class EndOptionGroup(object):
|
class EndOptionGroup:
|
||||||
start_option_group = False
|
start_option_group = False
|
||||||
end_option_group = True
|
end_option_group = True
|
||||||
|
|
||||||
class Option(object):
|
class Option:
|
||||||
start_option_group = False
|
start_option_group = False
|
||||||
end_option_group = False
|
end_option_group = False
|
||||||
|
|
||||||
|
@ -249,7 +249,7 @@ def get_error_detail(exc_info):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class CreateOnlyDefault(object):
|
class CreateOnlyDefault:
|
||||||
"""
|
"""
|
||||||
This class may be used to provide default values that are only used
|
This class may be used to provide default values that are only used
|
||||||
for create operations, but that do not return any value for update
|
for create operations, but that do not return any value for update
|
||||||
|
@ -276,7 +276,7 @@ class CreateOnlyDefault(object):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class CurrentUserDefault(object):
|
class CurrentUserDefault:
|
||||||
def set_context(self, serializer_field):
|
def set_context(self, serializer_field):
|
||||||
self.user = serializer_field.context['request'].user
|
self.user = serializer_field.context['request'].user
|
||||||
|
|
||||||
|
@ -303,7 +303,7 @@ MISSING_ERROR_MESSAGE = (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Field(object):
|
class Field:
|
||||||
_creation_counter = 0
|
_creation_counter = 0
|
||||||
|
|
||||||
default_error_messages = {
|
default_error_messages = {
|
||||||
|
|
|
@ -65,7 +65,7 @@ class Hyperlink(six.text_type):
|
||||||
is_hyperlink = True
|
is_hyperlink = True
|
||||||
|
|
||||||
|
|
||||||
class PKOnlyObject(object):
|
class PKOnlyObject:
|
||||||
"""
|
"""
|
||||||
This is a mock object, used for when we only need the pk of the object
|
This is a mock object, used for when we only need the pk of the object
|
||||||
instance, but still want to return an object with a .pk attribute,
|
instance, but still want to return an object with a .pk attribute,
|
||||||
|
|
|
@ -39,7 +39,7 @@ def zero_as_none(value):
|
||||||
return None if value == 0 else value
|
return None if value == 0 else value
|
||||||
|
|
||||||
|
|
||||||
class BaseRenderer(object):
|
class BaseRenderer:
|
||||||
"""
|
"""
|
||||||
All renderers should extend this class, setting the `media_type`
|
All renderers should extend this class, setting the `media_type`
|
||||||
and `format` attributes, and override the `.render()` method.
|
and `format` attributes, and override the `.render()` method.
|
||||||
|
|
|
@ -38,7 +38,7 @@ Route = namedtuple('Route', ['url', 'mapping', 'name', 'detail', 'initkwargs'])
|
||||||
DynamicRoute = namedtuple('DynamicRoute', ['url', 'name', 'detail', 'initkwargs'])
|
DynamicRoute = namedtuple('DynamicRoute', ['url', 'name', 'detail', 'initkwargs'])
|
||||||
|
|
||||||
|
|
||||||
class DynamicDetailRoute(object):
|
class DynamicDetailRoute:
|
||||||
def __new__(cls, url, name, initkwargs):
|
def __new__(cls, url, name, initkwargs):
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"`DynamicDetailRoute` is deprecated and will be removed in 3.10 "
|
"`DynamicDetailRoute` is deprecated and will be removed in 3.10 "
|
||||||
|
@ -49,7 +49,7 @@ class DynamicDetailRoute(object):
|
||||||
return DynamicRoute(url, name, True, initkwargs)
|
return DynamicRoute(url, name, True, initkwargs)
|
||||||
|
|
||||||
|
|
||||||
class DynamicListRoute(object):
|
class DynamicListRoute:
|
||||||
def __new__(cls, url, name, initkwargs):
|
def __new__(cls, url, name, initkwargs):
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"`DynamicListRoute` is deprecated and will be removed in 3.10 in "
|
"`DynamicListRoute` is deprecated and will be removed in 3.10 in "
|
||||||
|
|
|
@ -186,7 +186,7 @@ def import_from_string(val, setting_name):
|
||||||
raise ImportError(msg)
|
raise ImportError(msg)
|
||||||
|
|
||||||
|
|
||||||
class APISettings(object):
|
class APISettings:
|
||||||
"""
|
"""
|
||||||
A settings object, that allows API settings to be accessed as properties.
|
A settings object, that allows API settings to be accessed as properties.
|
||||||
For example:
|
For example:
|
||||||
|
|
|
@ -30,7 +30,7 @@ if requests is not None:
|
||||||
def get_all(self, key, default):
|
def get_all(self, key, default):
|
||||||
return self.getheaders(key)
|
return self.getheaders(key)
|
||||||
|
|
||||||
class MockOriginalResponse(object):
|
class MockOriginalResponse:
|
||||||
def __init__(self, headers):
|
def __init__(self, headers):
|
||||||
self.msg = HeaderDict(headers)
|
self.msg = HeaderDict(headers)
|
||||||
self.closed = False
|
self.closed = False
|
||||||
|
|
|
@ -10,7 +10,7 @@ from django.core.exceptions import ImproperlyConfigured
|
||||||
from rest_framework.settings import api_settings
|
from rest_framework.settings import api_settings
|
||||||
|
|
||||||
|
|
||||||
class BaseThrottle(object):
|
class BaseThrottle:
|
||||||
"""
|
"""
|
||||||
Rate throttling of requests.
|
Rate throttling of requests.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -32,7 +32,7 @@ def qs_filter(queryset, **kwargs):
|
||||||
return queryset.none()
|
return queryset.none()
|
||||||
|
|
||||||
|
|
||||||
class UniqueValidator(object):
|
class UniqueValidator:
|
||||||
"""
|
"""
|
||||||
Validator that corresponds to `unique=True` on a model field.
|
Validator that corresponds to `unique=True` on a model field.
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ class UniqueValidator(object):
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
class UniqueTogetherValidator(object):
|
class UniqueTogetherValidator:
|
||||||
"""
|
"""
|
||||||
Validator that corresponds to `unique_together = (...)` on a model class.
|
Validator that corresponds to `unique_together = (...)` on a model class.
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ class UniqueTogetherValidator(object):
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
class BaseUniqueForValidator(object):
|
class BaseUniqueForValidator:
|
||||||
message = None
|
message = None
|
||||||
missing_message = _('This field is required.')
|
missing_message = _('This field is required.')
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ from rest_framework.templatetags.rest_framework import replace_query_param
|
||||||
from rest_framework.utils.mediatypes import _MediaType
|
from rest_framework.utils.mediatypes import _MediaType
|
||||||
|
|
||||||
|
|
||||||
class BaseVersioning(object):
|
class BaseVersioning:
|
||||||
default_version = api_settings.DEFAULT_VERSION
|
default_version = api_settings.DEFAULT_VERSION
|
||||||
allowed_versions = api_settings.ALLOWED_VERSIONS
|
allowed_versions = api_settings.ALLOWED_VERSIONS
|
||||||
version_param = api_settings.VERSION_PARAM
|
version_param = api_settings.VERSION_PARAM
|
||||||
|
|
|
@ -33,7 +33,7 @@ def _is_extra_action(attr):
|
||||||
return hasattr(attr, 'mapping')
|
return hasattr(attr, 'mapping')
|
||||||
|
|
||||||
|
|
||||||
class ViewSetMixin(object):
|
class ViewSetMixin:
|
||||||
"""
|
"""
|
||||||
This is the magic.
|
This is the magic.
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
# coding: utf-8
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
|
|
|
@ -249,7 +249,7 @@ class SessionAuthTests(TestCase):
|
||||||
assert response.status_code == status.HTTP_403_FORBIDDEN
|
assert response.status_code == status.HTTP_403_FORBIDDEN
|
||||||
|
|
||||||
|
|
||||||
class BaseTokenAuthTests(object):
|
class BaseTokenAuthTests:
|
||||||
"""Token authentication"""
|
"""Token authentication"""
|
||||||
model = None
|
model = None
|
||||||
path = None
|
path = None
|
||||||
|
|
|
@ -5,10 +5,8 @@ from django.contrib.contenttypes.fields import (
|
||||||
)
|
)
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.encoding import python_2_unicode_compatible
|
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
|
||||||
class Tag(models.Model):
|
class Tag(models.Model):
|
||||||
"""
|
"""
|
||||||
Tags have a descriptive slug, and are attached to an arbitrary object.
|
Tags have a descriptive slug, and are attached to an arbitrary object.
|
||||||
|
@ -22,7 +20,6 @@ class Tag(models.Model):
|
||||||
return self.tag
|
return self.tag
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
|
||||||
class Bookmark(models.Model):
|
class Bookmark(models.Model):
|
||||||
"""
|
"""
|
||||||
A URL bookmark that may have multiple tags attached.
|
A URL bookmark that may have multiple tags attached.
|
||||||
|
@ -34,7 +31,6 @@ class Bookmark(models.Model):
|
||||||
return 'Bookmark: %s' % self.url
|
return 'Bookmark: %s' % self.url
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
|
||||||
class Note(models.Model):
|
class Note(models.Model):
|
||||||
"""
|
"""
|
||||||
A textual note that may have multiple tags attached.
|
A textual note that may have multiple tags attached.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user