Skip to content

Commit 5b792ea

Browse files
jonathan-golorryAsif Saif Uddin
authored and
Asif Saif Uddin
committed
Added Django 3.0 support by removing python2 support (#544)
* removed invalid python 2 compatibility imports from django * removed future imports that only mattered for python 2 * added a pre-commit configuration with default settings and pyupgrade * removed python 2.7 and added python 3.8 to travis configuration
1 parent f0d6b79 commit 5b792ea

20 files changed

+28
-40
lines changed

.pre-commit-config.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v2.4.0
6+
hooks:
7+
- id: trailing-whitespace
8+
- id: end-of-file-fixer
9+
- id: check-yaml
10+
- id: check-added-large-files
11+
- repo: https://github.com/asottile/pyupgrade
12+
rev: v1.25.2
13+
hooks:
14+
- id: pyupgrade

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
sudo: false
33
language: python
44
python:
5-
- 2.7
65
- 3.6
76
- 3.7
7+
- 3.8
88
cache: pip
99
dist: xenial
1010
install: travis_retry pip install tox-travis

README.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Edit your settings.py file:
6262
6363
.. note::
6464
If you need to support multiple mobile applications from a single Django application, see `Multiple Application Support <https://github.com/jazzband/django-push-notifications/wiki/Multiple-Application-Support>`_ for details.
65-
65+
6666
.. note::
6767
If you are planning on running your project with ``APNS_USE_SANDBOX=True``, then make sure you have set the
6868
*development* certificate as your ``APNS_CERTIFICATE``. Otherwise the app will not be able to connect to the correct host. See settings_ for details.
@@ -106,7 +106,7 @@ For WNS, you need both the ``WNS_PACKAGE_SECURITY_KEY`` and the ``WNS_SECRET_KEY
106106
**WNS settings**
107107

108108
- ``WNS_PACKAGE_SECURITY_KEY``: TODO
109-
- ``WNS_SECRET_KEY``: TODO
109+
- ``WNS_SECRET_KEY``: TODO
110110

111111
**WP settings**
112112

push_notifications/api/rest_framework.py

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

push_notifications/conf/app.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from django.core.exceptions import ImproperlyConfigured
2-
from django.utils.six import string_types
32

43
from ..settings import PUSH_NOTIFICATIONS_SETTINGS as SETTINGS
54
from .base import BaseConfig, check_apns_certificate
@@ -177,7 +176,7 @@ def _validate_apns_certificate(self, certfile):
177176
check_apns_certificate(content)
178177
except Exception as e:
179178
raise ImproperlyConfigured(
180-
"The APNS certificate file at %r is not readable: %s" % (certfile, e)
179+
"The APNS certificate file at {!r} is not readable: {}".format(certfile, e)
181180
)
182181

183182
def _validate_fcm_config(self, application_id, application_config):
@@ -323,7 +322,7 @@ def get_max_recipients(self, cloud_type, application_id=None):
323322

324323
def get_apns_certificate(self, application_id=None):
325324
r = self._get_application_settings(application_id, "APNS", "CERTIFICATE")
326-
if not isinstance(r, string_types):
325+
if not isinstance(r, str):
327326
# probably the (Django) file, and file path should be got
328327
if hasattr(r, "path"):
329328
return r.path

push_notifications/conf/legacy.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from django.core.exceptions import ImproperlyConfigured
2-
from django.utils.six import string_types
32

43
from ..settings import PUSH_NOTIFICATIONS_SETTINGS as SETTINGS
54
from .base import BaseConfig
@@ -87,7 +86,7 @@ def get_apns_certificate(self, application_id=None):
8786
application_id, "APNS_CERTIFICATE",
8887
"You need to setup PUSH_NOTIFICATIONS_SETTINGS properly to send messages"
8988
)
90-
if not isinstance(r, string_types):
89+
if not isinstance(r, str):
9190
# probably the (Django) file, and file path should be got
9291
if hasattr(r, "path"):
9392
return r.path

push_notifications/exceptions.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
21
class NotificationError(Exception):
32
pass

push_notifications/fields.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from django import forms
55
from django.core.validators import MaxValueValidator, MinValueValidator, RegexValidator
66
from django.db import connection, models
7-
from django.utils import six
87
from django.utils.translation import ugettext_lazy as _
98

109

@@ -55,7 +54,7 @@ def __init__(self, *args, **kwargs):
5554

5655
def prepare_value(self, value):
5756
# converts bigint from db to hex before it is displayed in admin
58-
if value and not isinstance(value, six.string_types) \
57+
if value and not isinstance(value, str) \
5958
and connection.vendor in ("mysql", "sqlite"):
6059
value = _unsigned_integer_to_hex_string(value)
6160
return super(forms.CharField, self).prepare_value(value)
@@ -92,7 +91,7 @@ def get_prep_value(self, value):
9291
""" Return the integer value to be stored from the hex string """
9392
if value is None or value == "":
9493
return None
95-
if isinstance(value, six.string_types):
94+
if isinstance(value, str):
9695
value = _hex_string_to_unsigned_integer(value)
9796
if _using_signed_storage():
9897
value = _unsigned_to_signed_integer(value)
@@ -108,7 +107,7 @@ def from_db_value(self, value, *args):
108107

109108
def to_python(self, value):
110109
""" Return a str representation of the hexadecimal """
111-
if isinstance(value, six.string_types):
110+
if isinstance(value, str):
112111
return value
113112
if value is None:
114113
return value

push_notifications/migrations/0001_initial.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import unicode_literals
3-
42
from django.conf import settings
53
from django.db import migrations, models
64

push_notifications/migrations/0002_auto_20160106_0850.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# -*- coding: utf-8 -*-
22
# Generated by Django 1.9.1 on 2016-01-06 08:50
3-
from __future__ import unicode_literals
4-
53
from django.db import migrations, models
64

75

push_notifications/migrations/0003_wnsdevice.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# -*- coding: utf-8 -*-
22
# Generated by Django 1.9.6 on 2016-06-13 20:46
3-
from __future__ import unicode_literals
4-
53
import django.db.models.deletion
64
from django.conf import settings
75
from django.db import migrations, models

push_notifications/migrations/0004_fcm.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# -*- coding: utf-8 -*-
22
# Generated by Django 1.9.6 on 2016-06-13 20:46
3-
from __future__ import unicode_literals
4-
53
from django.conf import settings
64
from django.db import migrations, models
75

push_notifications/migrations/0005_applicationid.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import unicode_literals
3-
42
from django.conf import settings
53
from django.db import migrations, models
64

push_notifications/migrations/0006_webpushdevice.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import unicode_literals
3-
42
from django.conf import settings
53
from django.db import migrations, models
64

push_notifications/models.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
from __future__ import unicode_literals
2-
31
from django.db import models
4-
from django.utils.encoding import python_2_unicode_compatible
52
from django.utils.translation import ugettext_lazy as _
63

74
from .fields import HexIntegerField
@@ -20,7 +17,6 @@
2017
)
2118

2219

23-
@python_2_unicode_compatible
2420
class Device(models.Model):
2521
name = models.CharField(max_length=255, verbose_name=_("Name"), blank=True, null=True)
2622
active = models.BooleanField(
@@ -49,7 +45,7 @@ def __str__(self):
4945
return (
5046
self.name or
5147
str(self.device_id or "") or
52-
"%s for %s" % (self.__class__.__name__, self.user or "unknown user")
48+
"{} for {}".format(self.__class__.__name__, self.user or "unknown user")
5349
)
5450

5551

push_notifications/webpush.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class WebPushError(NotificationError):
1111
def get_subscription_info(application_id, uri, browser, auth, p256dh):
1212
url = get_manager().get_wp_post_url(application_id, browser)
1313
return {
14-
"endpoint": "%s/%s" % (url, uri),
14+
"endpoint": "{}/{}".format(url, uri),
1515
"keys": {
1616
"auth": auth,
1717
"p256dh": p256dh,

tests/test_data/good_revoked.pem

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Bag Attributes
22
friendlyName: Apple Development IOS Push Services: com.baseride.Magnitapp
3-
localKeyID: 38 EE 6A 28 9F 92 3A 56 3F 30 A4 06 13 94 4F 76 E7 BB 58 6C
3+
localKeyID: 38 EE 6A 28 9F 92 3A 56 3F 30 A4 06 13 94 4F 76 E7 BB 58 6C
44
subject=/UID=com.baseride.Magnitapp/CN=Apple Development IOS Push Services: com.baseride.Magnitapp/OU=QAMD48Y2CA/C=US
55
issuer=/C=US/O=Apple Inc./OU=Apple Worldwide Developer Relations/CN=Apple Worldwide Developer Relations Certification Authority
66
-----BEGIN CERTIFICATE-----
@@ -37,7 +37,7 @@ hlCAJBuqEvGPrme/SYkqLv2p1WKw4IJ8IKaza6QI7MQYI1UMIabbBVbq2GxaJuEO
3737
-----END CERTIFICATE-----
3838
Bag Attributes
3939
friendlyName: PushNotificationCloudBus
40-
localKeyID: 38 EE 6A 28 9F 92 3A 56 3F 30 A4 06 13 94 4F 76 E7 BB 58 6C
40+
localKeyID: 38 EE 6A 28 9F 92 3A 56 3F 30 A4 06 13 94 4F 76 E7 BB 58 6C
4141
Key Attributes: <No Attributes>
4242
-----BEGIN RSA PRIVATE KEY-----
4343
MIIEogIBAAKCAQEA0W06MJky6FWGgQ2JHV3zzGwF4oHYPFOFwCEKe2nJhIZ5DKqz

tests/test_data/good_with_passwd.pem

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ NonhJADFD84YUTCnZC/xreAbjY7ss90fKLzxJfzMB+Wskf/EKQ==
3232
-----END CERTIFICATE-----
3333
Bag Attributes
3434
friendlyName: CloudTrack Push
35-
localKeyID: C6 2F A2 B9 4D AD EF C6 33 8B 75 04 C1 63 FC 03 4C C6 29 6D
35+
localKeyID: C6 2F A2 B9 4D AD EF C6 33 8B 75 04 C1 63 FC 03 4C C6 29 6D
3636
Key Attributes: <No Attributes>
3737
-----BEGIN RSA PRIVATE KEY-----
3838
Proc-Type: 4,ENCRYPTED

tests/test_gcm_push_payload.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import
2-
31
from django.test import TestCase
42

53
from push_notifications.gcm import send_bulk_message, send_message

tests/test_models.py

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

53
from django.test import TestCase

0 commit comments

Comments
 (0)