Skip to content

Commit

Permalink
Remove Django 1.10 compat code
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan P Kilby committed Jan 8, 2018
1 parent d33f7e6 commit 1ff0b16
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ skip=.tox
atomic=true
multi_line_output=5
known_standard_library=types
known_third_party=pytest,_pytest,django
known_third_party=pytest,_pytest,django,pytz
known_first_party=rest_framework
1 change: 0 additions & 1 deletion requirements/requirements-optionals.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Optional packages which may be used with REST framework.
pytz==2017.2
markdown==2.6.4
django-guardian==1.4.9
django-filter==1.1.0
Expand Down
3 changes: 1 addition & 2 deletions rest_framework/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
import base64
import binascii

from django.contrib.auth import get_user_model
from django.contrib.auth import authenticate, get_user_model
from django.middleware.csrf import CsrfViewMiddleware
from django.utils.six import text_type
from django.utils.translation import ugettext_lazy as _

from rest_framework import HTTP_HEADER_ENCODING, exceptions
from rest_framework.compat import authenticate


def get_authorization_header(request):
Expand Down
2 changes: 1 addition & 1 deletion rest_framework/authtoken/serializers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.contrib.auth import authenticate
from django.utils.translation import ugettext_lazy as _

from rest_framework import serializers
from rest_framework.compat import authenticate


class AuthTokenSerializer(serializers.Serializer):
Expand Down
15 changes: 0 additions & 15 deletions rest_framework/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from __future__ import unicode_literals

import django
from django.conf import settings
from django.core import validators
from django.utils import six
Expand Down Expand Up @@ -245,12 +244,6 @@ def md_filter_add_syntax_highlight(md):
def md_filter_add_syntax_highlight(md):
return False

# pytz is required from Django 1.11. Remove when dropping Django 1.10 support.
try:
import pytz # noqa
from pytz.exceptions import InvalidTimeError
except ImportError:
InvalidTimeError = Exception

# Django 1.x url routing syntax. Remove when dropping Django 1.11 support.
try:
Expand Down Expand Up @@ -301,11 +294,3 @@ class MinLengthValidator(CustomValidatorMessage, validators.MinLengthValidator):

class MaxLengthValidator(CustomValidatorMessage, validators.MaxLengthValidator):
pass


def authenticate(request=None, **credentials):
from django.contrib.auth import authenticate
if django.VERSION < (1, 11):
return authenticate(**credentials)
else:
return authenticate(request=request, **credentials)
5 changes: 3 additions & 2 deletions rest_framework/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
from django.utils.ipv6 import clean_ipv6_address
from django.utils.timezone import utc
from django.utils.translation import ugettext_lazy as _
from pytz.exceptions import InvalidTimeError

from rest_framework import ISO_8601
from rest_framework.compat import (
InvalidTimeError, MaxLengthValidator, MaxValueValidator,
MinLengthValidator, MinValueValidator, unicode_repr, unicode_to_repr
MaxLengthValidator, MaxValueValidator, MinLengthValidator,
MinValueValidator, unicode_repr, unicode_to_repr
)
from rest_framework.exceptions import ErrorDetail, ValidationError
from rest_framework.settings import api_settings
Expand Down
15 changes: 2 additions & 13 deletions rest_framework/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,11 @@
"""
from __future__ import unicode_literals

import django
from django.conf.urls import url
from django.contrib.auth import views

if django.VERSION < (1, 11):
login = views.login
login_kwargs = {'template_name': 'rest_framework/login.html'}
logout = views.logout
else:
login = views.LoginView.as_view(template_name='rest_framework/login.html')
login_kwargs = {}
logout = views.LogoutView.as_view()


app_name = 'rest_framework'
urlpatterns = [
url(r'^login/$', login, login_kwargs, name='login'),
url(r'^logout/$', logout, name='logout'),
url(r'^login/$', views.LoginView.as_view(template_name='rest_framework/login.html'), name='login'),
url(r'^logout/$', views.LogoutView.as_view(), name='logout'),
]
12 changes: 3 additions & 9 deletions tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,16 @@
from decimal import ROUND_DOWN, ROUND_UP, Decimal

import pytest
import pytz
from django.http import QueryDict
from django.test import TestCase, override_settings
from django.utils import six
from django.utils.timezone import activate, deactivate, utc

import rest_framework
from rest_framework import compat, serializers
from rest_framework import serializers
from rest_framework.fields import DjangoImageField, is_simple_callable

try:
import pytz
except ImportError:
pytz = None

try:
import typings
except ImportError:
Expand Down Expand Up @@ -1250,7 +1246,6 @@ class TestNaiveDateTimeField(FieldValues):
field = serializers.DateTimeField(default_timezone=None)


@pytest.mark.skipif(pytz is None, reason='pytz not installed')
class TestTZWithDateTimeField(FieldValues):
"""
Valid and invalid values for `DateTimeField` when not using UTC as the timezone.
Expand All @@ -1273,7 +1268,6 @@ def setup_class(cls):
cls.field = serializers.DateTimeField(default_timezone=kolkata)


@pytest.mark.skipif(pytz is None, reason='pytz not installed')
@override_settings(TIME_ZONE='UTC', USE_TZ=True)
class TestDefaultTZDateTimeField(TestCase):
"""
Expand Down Expand Up @@ -1312,7 +1306,7 @@ class TestNaiveDayLightSavingTimeTimeZoneDateTimeField(FieldValues):
class MockTimezone:
@staticmethod
def localize(value, is_dst):
raise compat.InvalidTimeError()
raise pytz.InvalidTimeError()

def __str__(self):
return 'America/New_York'
Expand Down

0 comments on commit 1ff0b16

Please sign in to comment.