Skip to content

Commit 7c1d303

Browse files
authored
Merge pull request jazzband#77 from davesque/remove-python-2
Remove python 2 support
2 parents df927ed + fc5e7ff commit 7c1d303

31 files changed

+55
-126
lines changed

.travis.yml

-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ sudo: required
66
cache: pip
77

88
python:
9-
- "2.7"
109
- "3.5"
1110
- "3.6"
1211
- "3.7"
@@ -25,14 +24,8 @@ matrix:
2524
exclude:
2625
- python: "3.7"
2726
env: DJANGO=1.11
28-
- python: "2.7"
29-
env: DJANGO=2.0
30-
- python: "2.7"
31-
env: DJANGO=2.1
3227
- python: "3.5"
3328
env: DJANGO=2.1
34-
- python: "2.7"
35-
env: DJANGO=master
3629
- python: "3.5"
3730
env: DJANGO=master
3831
- python: "3.6"

README.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ variable defaults should be safe.
2121
Requirements
2222
------------
2323

24-
* Python (2.7, 3.5, 3.6, 3.7)
24+
* Python (3.5, 3.6, 3.7)
2525
* Django (1.11, 2.0, 2.1)
2626
* Django REST Framework (3.5, 3.6, 3.7, 3.8, 3.9)
2727

@@ -290,7 +290,7 @@ generated by the ``TokenObtainPairView``:
290290
class MyTokenObtainPairSerializer(TokenObtainPairSerializer):
291291
@classmethod
292292
def get_token(cls, user):
293-
token = super(MyTokenObtainPairSerializer, cls).get_token(user)
293+
token = super().get_token(user)
294294
295295
# Add custom claims
296296
token['name'] = user.name

rest_framework_simplejwt/authentication.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
from __future__ import unicode_literals
2-
3-
from django.utils.six import text_type
41
from django.utils.translation import ugettext_lazy as _
52
from rest_framework import HTTP_HEADER_ENCODING, authentication
63

@@ -53,7 +50,7 @@ def get_header(self, request):
5350
"""
5451
header = request.META.get('HTTP_AUTHORIZATION')
5552

56-
if isinstance(header, text_type):
53+
if isinstance(header, str):
5754
# Work around django test client oddness
5855
header = header.encode(HTTP_HEADER_ENCODING)
5956

rest_framework_simplejwt/backends.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import unicode_literals
2-
31
from django.utils.translation import ugettext_lazy as _
42
from jwt import InvalidTokenError
53
import jwt
@@ -17,7 +15,7 @@
1715
)
1816

1917

20-
class TokenBackend(object):
18+
class TokenBackend:
2119
def __init__(self, algorithm, signing_key=None, verifying_key=None):
2220
if algorithm not in ALLOWED_ALGORITHMS:
2321
raise TokenBackendError(format_lazy(_("Unrecognized algorithm type '{}'"), algorithm))

rest_framework_simplejwt/compat.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import unicode_literals
2-
31
import warnings
42

53
try:

rest_framework_simplejwt/exceptions.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import unicode_literals
2-
31
from django.utils.translation import ugettext_lazy as _
42
from rest_framework import exceptions, status
53

@@ -12,7 +10,7 @@ class TokenBackendError(Exception):
1210
pass
1311

1412

15-
class DetailDictMixin(object):
13+
class DetailDictMixin:
1614
def __init__(self, detail=None, code=None):
1715
"""
1816
Builds a detail dictionary for the error to give more information to API
@@ -28,7 +26,7 @@ def __init__(self, detail=None, code=None):
2826
if code is not None:
2927
detail_dict['code'] = code
3028

31-
super(DetailDictMixin, self).__init__(detail_dict)
29+
super().__init__(detail_dict)
3230

3331

3432
class AuthenticationFailed(DetailDictMixin, exceptions.AuthenticationFailed):

rest_framework_simplejwt/models.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
from __future__ import unicode_literals
2-
31
from django.contrib.auth import models as auth_models
42
from django.db.models.manager import EmptyManager
5-
from django.utils.encoding import python_2_unicode_compatible
63
from django.utils.functional import cached_property
74

85
from .compat import CallableFalse, CallableTrue
96
from .settings import api_settings
107

118

12-
@python_2_unicode_compatible
13-
class TokenUser(object):
9+
class TokenUser:
1410
"""
1511
A dummy user class modeled after django.contrib.auth.models.AnonymousUser.
1612
Used in conjunction with the `JWTTokenUserAuthentication` backend to

rest_framework_simplejwt/serializers.py

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
from __future__ import unicode_literals
2-
31
from django.contrib.auth import authenticate
4-
from django.utils.six import text_type
52
from django.utils.translation import ugettext_lazy as _
63
from rest_framework import serializers
74

@@ -17,14 +14,14 @@ def __init__(self, *args, **kwargs):
1714
kwargs['style']['input_type'] = 'password'
1815
kwargs['write_only'] = True
1916

20-
super(PasswordField, self).__init__(*args, **kwargs)
17+
super().__init__(*args, **kwargs)
2118

2219

2320
class TokenObtainSerializer(serializers.Serializer):
2421
username_field = User.USERNAME_FIELD
2522

2623
def __init__(self, *args, **kwargs):
27-
super(TokenObtainSerializer, self).__init__(*args, **kwargs)
24+
super().__init__(*args, **kwargs)
2825

2926
self.fields[self.username_field] = serializers.CharField()
3027
self.fields['password'] = PasswordField()
@@ -60,12 +57,12 @@ def get_token(cls, user):
6057
return RefreshToken.for_user(user)
6158

6259
def validate(self, attrs):
63-
data = super(TokenObtainPairSerializer, self).validate(attrs)
60+
data = super().validate(attrs)
6461

6562
refresh = self.get_token(self.user)
6663

67-
data['refresh'] = text_type(refresh)
68-
data['access'] = text_type(refresh.access_token)
64+
data['refresh'] = str(refresh)
65+
data['access'] = str(refresh.access_token)
6966

7067
return data
7168

@@ -76,11 +73,11 @@ def get_token(cls, user):
7673
return SlidingToken.for_user(user)
7774

7875
def validate(self, attrs):
79-
data = super(TokenObtainSlidingSerializer, self).validate(attrs)
76+
data = super().validate(attrs)
8077

8178
token = self.get_token(self.user)
8279

83-
data['token'] = text_type(token)
80+
data['token'] = str(token)
8481

8582
return data
8683

@@ -91,7 +88,7 @@ class TokenRefreshSerializer(serializers.Serializer):
9188
def validate(self, attrs):
9289
refresh = RefreshToken(attrs['refresh'])
9390

94-
data = {'access': text_type(refresh.access_token)}
91+
data = {'access': str(refresh.access_token)}
9592

9693
if api_settings.ROTATE_REFRESH_TOKENS:
9794
if api_settings.BLACKLIST_AFTER_ROTATION:
@@ -106,7 +103,7 @@ def validate(self, attrs):
106103
refresh.set_jti()
107104
refresh.set_exp()
108105

109-
data['refresh'] = text_type(refresh)
106+
data['refresh'] = str(refresh)
110107

111108
return data
112109

@@ -124,7 +121,7 @@ def validate(self, attrs):
124121
# Update the "exp" claim
125122
token.set_exp()
126123

127-
return {'token': text_type(token)}
124+
return {'token': str(token)}
128125

129126

130127
class TokenVerifySerializer(serializers.Serializer):

rest_framework_simplejwt/settings.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import unicode_literals
2-
31
from datetime import timedelta
42

53
from django.conf import settings

rest_framework_simplejwt/state.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import unicode_literals
2-
31
from django.contrib.auth import get_user_model
42

53
from .backends import TokenBackend

rest_framework_simplejwt/token_blacklist/admin.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class OutstandingTokenAdmin(admin.ModelAdmin):
2222
)
2323

2424
def get_queryset(self, *args, **kwargs):
25-
qs = super(OutstandingTokenAdmin, self).get_queryset(*args, **kwargs)
25+
qs = super().get_queryset(*args, **kwargs)
2626

2727
return qs.select_related('user')
2828

@@ -41,7 +41,7 @@ def has_delete_permission(self, *args, **kwargs):
4141
def has_change_permission(self, request, obj=None):
4242
return (
4343
request.method in ['GET', 'HEAD'] and
44-
super(OutstandingTokenAdmin, self).has_change_permission(request, obj)
44+
super().has_change_permission(request, obj)
4545
)
4646

4747
admin.site.register(OutstandingToken, OutstandingTokenAdmin)
@@ -64,7 +64,7 @@ class BlacklistedTokenAdmin(admin.ModelAdmin):
6464
)
6565

6666
def get_queryset(self, *args, **kwargs):
67-
qs = super(BlacklistedTokenAdmin, self).get_queryset(*args, **kwargs)
67+
qs = super().get_queryset(*args, **kwargs)
6868

6969
return qs.select_related('token__user')
7070

rest_framework_simplejwt/token_blacklist/models.py

-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
from django.conf import settings
44
from django.db import models
5-
from django.utils.six import python_2_unicode_compatible
65

76

8-
@python_2_unicode_compatible
97
class OutstandingToken(models.Model):
108
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True, blank=True)
119

@@ -31,7 +29,6 @@ def __str__(self):
3129
)
3230

3331

34-
@python_2_unicode_compatible
3532
class BlacklistedToken(models.Model):
3633
token = models.OneToOneField(OutstandingToken, on_delete=models.CASCADE)
3734

rest_framework_simplejwt/tokens.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
from __future__ import unicode_literals
2-
31
from datetime import timedelta
42
from uuid import uuid4
53

64
from django.conf import settings
7-
from django.utils.six import python_2_unicode_compatible, text_type
85
from django.utils.translation import ugettext_lazy as _
96

107
from .exceptions import TokenBackendError, TokenError
@@ -15,8 +12,7 @@
1512
)
1613

1714

18-
@python_2_unicode_compatible
19-
class Token(object):
15+
class Token:
2016
"""
2117
A class which validates and wraps an existing JWT or can be used to build a
2218
new JWT.
@@ -164,15 +160,15 @@ def for_user(cls, user):
164160
"""
165161
user_id = getattr(user, api_settings.USER_ID_FIELD)
166162
if not isinstance(user_id, int):
167-
user_id = text_type(user_id)
163+
user_id = str(user_id)
168164

169165
token = cls()
170166
token[api_settings.USER_ID_CLAIM] = user_id
171167

172168
return token
173169

174170

175-
class BlacklistMixin(object):
171+
class BlacklistMixin:
176172
"""
177173
If the `rest_framework_simplejwt.token_blacklist` app was configured to be
178174
used, tokens created from `BlacklistMixin` subclasses will insert
@@ -183,7 +179,7 @@ class BlacklistMixin(object):
183179
def verify(self, *args, **kwargs):
184180
self.check_blacklist()
185181

186-
super(BlacklistMixin, self).verify(*args, **kwargs)
182+
super().verify(*args, **kwargs)
187183

188184
def check_blacklist(self):
189185
"""
@@ -219,7 +215,7 @@ def for_user(cls, user):
219215
"""
220216
Adds this token to the outstanding token list.
221217
"""
222-
token = super(BlacklistMixin, cls).for_user(user)
218+
token = super().for_user(user)
223219

224220
jti = token['jti']
225221
exp = token['exp']
@@ -240,7 +236,7 @@ class SlidingToken(BlacklistMixin, Token):
240236
lifetime = api_settings.SLIDING_TOKEN_LIFETIME
241237

242238
def __init__(self, *args, **kwargs):
243-
super(SlidingToken, self).__init__(*args, **kwargs)
239+
super().__init__(*args, **kwargs)
244240

245241
if self.token is None:
246242
# Set sliding refresh expiration claim if new token

rest_framework_simplejwt/utils.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
from __future__ import unicode_literals
2-
31
from calendar import timegm
42
from datetime import datetime
53

64
from django.conf import settings
7-
from django.utils import six
85
from django.utils.functional import lazy
96
from django.utils.timezone import is_naive, make_aware, utc
107

@@ -31,4 +28,4 @@ def datetime_from_epoch(ts):
3128
def format_lazy(s, *args, **kwargs):
3229
return s.format(*args, **kwargs)
3330

34-
format_lazy = lazy(format_lazy, six.text_type)
31+
format_lazy = lazy(format_lazy, str)

rest_framework_simplejwt/views.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import unicode_literals
2-
31
from rest_framework import generics, status
42
from rest_framework.response import Response
53

runtests.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#! /usr/bin/env python
2-
from __future__ import print_function, unicode_literals
3-
42
import os
53
import subprocess
64
import sys

setup.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3-
from __future__ import unicode_literals
4-
53
from io import open
64
import os
75
import re

tests/conftest.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
from __future__ import unicode_literals
2-
3-
41
def pytest_configure():
52
from django.conf import settings
63

0 commit comments

Comments
 (0)