From 9bc0f1b82a1b8235b1af7c3e8cdefa8ceaac471f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Tue, 24 Apr 2018 21:04:33 +0300 Subject: [PATCH] Dropping Python 2 support --- .travis.yml | 1 - README.md | 2 +- hc/api/tests/test_notify.py | 3 +-- hc/api/transports.py | 2 +- hc/front/validators.py | 2 +- hc/front/views.py | 2 +- hc/lib/jsonschema.py | 3 +-- hc/payments/tests/test_pdf_invoice.py | 7 +++---- hc/payments/views.py | 5 +++-- 9 files changed, 12 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index de7f6928..0fb30cb4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: python python: - - "2.7" - "3.5" - "3.6" install: diff --git a/README.md b/README.md index 9dd3d607..4c613433 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ It is live here: [http://healthchecks.io/](http://healthchecks.io/) The building blocks are: -* Python 2 or Python 3 +* Python 3 * Django 1.11 * PostgreSQL or MySQL diff --git a/hc/api/tests/test_notify.py b/hc/api/tests/test_notify.py index c0d72003..c66ad1d8 100644 --- a/hc/api/tests/test_notify.py +++ b/hc/api/tests/test_notify.py @@ -9,7 +9,6 @@ from hc.api.models import Channel, Check, Notification from hc.test import BaseTestCase from mock import patch from requests.exceptions import ConnectionError, Timeout -from six import binary_type class NotifyTestCase(BaseTestCase): @@ -143,7 +142,7 @@ class NotifyTestCase(BaseTestCase): args, kwargs = mock_request.call_args # unicode should be encoded into utf-8 - self.assertTrue(isinstance(kwargs["data"], binary_type)) + self.assertIsInstance(kwargs["data"], bytes) @patch("hc.api.transports.requests.request") def test_webhooks_handle_json_value(self, mock_request): diff --git a/hc/api/transports.py b/hc/api/transports.py index 23d2248e..aa3af302 100644 --- a/hc/api/transports.py +++ b/hc/api/transports.py @@ -3,7 +3,7 @@ from django.template.loader import render_to_string from django.utils import timezone import json import requests -from six.moves.urllib.parse import quote +from urllib.parse import quote from hc.accounts.models import Profile from hc.lib import emails diff --git a/hc/front/validators.py b/hc/front/validators.py index 1a843c8c..77eabb7e 100644 --- a/hc/front/validators.py +++ b/hc/front/validators.py @@ -1,6 +1,6 @@ from croniter import croniter from django.core.exceptions import ValidationError -from six.moves.urllib_parse import urlparse +from urllib.parse import urlparse from pytz import all_timezones diff --git a/hc/front/views.py b/hc/front/views.py index 1523b53f..b17c32ba 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -1,5 +1,6 @@ from datetime import datetime, timedelta as td import json +from urllib.parse import urlencode from croniter import croniter from django.conf import settings @@ -14,7 +15,6 @@ from django.template.loader import render_to_string from django.urls import reverse from django.utils import timezone from django.utils.crypto import get_random_string -from django.utils.six.moves.urllib.parse import urlencode from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_POST from hc.api.decorators import uuid_or_400 diff --git a/hc/lib/jsonschema.py b/hc/lib/jsonschema.py index 7653b057..86f2df35 100644 --- a/hc/lib/jsonschema.py +++ b/hc/lib/jsonschema.py @@ -5,7 +5,6 @@ Supports only a tiny subset of jsonschema. """ from croniter import croniter -from six import string_types from pytz import all_timezones @@ -15,7 +14,7 @@ class ValidationError(Exception): def validate(obj, schema, obj_name="value"): if schema.get("type") == "string": - if not isinstance(obj, string_types): + if not isinstance(obj, str): raise ValidationError("%s is not a string" % obj_name) if "maxLength" in schema and len(obj) > schema["maxLength"]: raise ValidationError("%s is too long" % obj_name) diff --git a/hc/payments/tests/test_pdf_invoice.py b/hc/payments/tests/test_pdf_invoice.py index 35738892..0c7d8cc3 100644 --- a/hc/payments/tests/test_pdf_invoice.py +++ b/hc/payments/tests/test_pdf_invoice.py @@ -4,7 +4,6 @@ from unittest import skipIf from django.utils.timezone import now from hc.payments.models import Subscription from hc.test import BaseTestCase -import six try: import reportlab @@ -37,8 +36,8 @@ class PdfInvoiceTestCase(BaseTestCase): self.client.login(username="alice@example.org", password="password") r = self.client.get("/invoice/pdf/abc123/") - self.assertTrue(six.b("ABC123") in r.content) - self.assertTrue(six.b("alice@example.org") in r.content) + self.assertTrue(b"ABC123" in r.content) + self.assertTrue(b"alice@example.org" in r.content) @patch("hc.payments.models.braintree") def test_it_checks_customer_id(self, mock_braintree): @@ -64,4 +63,4 @@ class PdfInvoiceTestCase(BaseTestCase): self.client.login(username="alice@example.org", password="password") r = self.client.get("/invoice/pdf/abc123/") - self.assertTrue(six.b("Alice and Partners") in r.content) + self.assertTrue(b"Alice and Partners" in r.content) diff --git a/hc/payments/views.py b/hc/payments/views.py index 002e1299..7a5e9a37 100644 --- a/hc/payments/views.py +++ b/hc/payments/views.py @@ -1,3 +1,5 @@ +from io import BytesIO + from django.contrib import messages from django.contrib.auth.decorators import login_required from django.http import (HttpResponseBadRequest, HttpResponseForbidden, @@ -5,7 +7,6 @@ from django.http import (HttpResponseBadRequest, HttpResponseForbidden, from django.shortcuts import get_object_or_404, redirect, render from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_POST -import six from hc.api.models import Check from hc.lib import emails from hc.payments.forms import InvoiceEmailingForm @@ -215,7 +216,7 @@ def charge_webhook(request): if sub.send_invoices: filename = "MS-HC-%s.pdf" % tx.id.upper() - sink = six.BytesIO() + sink = BytesIO() PdfInvoice(sink).render(tx, sub.flattened_address()) ctx = {"tx": tx}