Skip to content

Commit

Permalink
Merge pull request #169 from pinax/remove-six
Browse files Browse the repository at this point in the history
Removed vestigal support for Python 2.7
  • Loading branch information
spookylukey authored Jul 17, 2023
2 parents 1824bf8 + 53de705 commit 51d73f1
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 42 deletions.
2 changes: 1 addition & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ For an example of a custom error handler::
connection = None # i.e. ask for a new connection
status = 'deferred'
else:
six.reraise(*sys.exc_info())
raise exc

return connection, status

Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ python_requires = >=3.7
install_requires =
Django >= 1.11
lockfile >= 0.8
six

[options.packages.find]
where = src
Expand Down
26 changes: 4 additions & 22 deletions src/mailer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import warnings

import six

__version__ = '2.2'


Expand All @@ -26,11 +24,7 @@ def get_priority(priority):

def send_mail(subject, message, from_email, recipient_list, priority=None,
fail_silently=False, auth_user=None, auth_password=None):
if six.PY2:
# Only runs Django 1.11
from django.utils.encoding import force_unicode as force_str
else:
from django.utils.encoding import force_str
from django.utils.encoding import force_str
from mailer.models import make_message

priority = get_priority(priority)
Expand All @@ -52,11 +46,7 @@ def send_html_mail(subject, message, message_html, from_email, recipient_list,
"""
Function to queue HTML e-mails
"""
if six.PY2:
# Only runs Django 1.11
from django.utils.encoding import force_unicode as force_str
else:
from django.utils.encoding import force_str
from django.utils.encoding import force_str
from django.core.mail import EmailMultiAlternatives
from mailer.models import make_message

Expand Down Expand Up @@ -95,11 +85,7 @@ def send_mass_mail(datatuple, fail_silently=False, auth_user=None,

def mail_admins(subject, message, fail_silently=False, connection=None, priority=None):
from django.conf import settings
if six.PY2:
# Only runs Django 1.11
from django.utils.encoding import force_unicode as force_str
else:
from django.utils.encoding import force_str
from django.utils.encoding import force_str

return send_mail(settings.EMAIL_SUBJECT_PREFIX + force_str(subject),
message,
Expand All @@ -109,11 +95,7 @@ def mail_admins(subject, message, fail_silently=False, connection=None, priority

def mail_managers(subject, message, fail_silently=False, connection=None, priority=None):
from django.conf import settings
if six.PY2:
# Only runs Django 1.11
from django.utils.encoding import force_unicode as force_str
else:
from django.utils.encoding import force_str
from django.utils.encoding import force_str

return send_mail(settings.EMAIL_SUBJECT_PREFIX + force_str(subject),
message,
Expand Down
4 changes: 1 addition & 3 deletions src/mailer/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
import contextlib
import logging
import smtplib
import sys
import time
from socket import error as socket_error

import lockfile
import six
from django import VERSION as DJANGO_VERSION
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
Expand Down Expand Up @@ -145,7 +143,7 @@ def handle_delivery_exception(connection, message, exc):

# The idea is (1) to be backwards compatible with existing behavior
# and (2) not have delivery errors go unnoticed
six.reraise(*sys.exc_info())
raise exc


def acquire_lock():
Expand Down
13 changes: 1 addition & 12 deletions src/mailer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,13 @@
import pickle
import datetime

import six

from django.conf import settings

try:
from django.utils.encoding import python_2_unicode_compatible
except ImportError:
def python_2_unicode_compatible(c):
return c
from django.utils.timezone import now as datetime_now
from django.core.mail import EmailMessage
from django.db import models
if six.PY2:
from django.utils.translation import ugettext_lazy as _
else:
from django.utils.translation import gettext_lazy as _
from django.utils.translation import gettext_lazy as _


PRIORITY_HIGH = 1
Expand Down Expand Up @@ -128,7 +119,6 @@ def db_to_email(data):
return None


@python_2_unicode_compatible
class Message(BigAutoModel):
"""
The email stored for later sending.
Expand Down Expand Up @@ -288,7 +278,6 @@ def purge_old_entries(self, days, result_codes=None):
return count


@python_2_unicode_compatible
class MessageLog(BigAutoModel):
"""
A log entry which stores the result (and optionally a log message) for an
Expand Down
5 changes: 2 additions & 3 deletions tests/test_mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from django.test import TestCase
from django.utils.timezone import now as datetime_now
from mock import Mock, patch
import six

import mailer
from mailer import engine
Expand Down Expand Up @@ -653,7 +652,7 @@ def test_message_str(self):

msg = Message.objects.get()
self.assertEqual(
six.text_type(msg),
str(msg),
'On {0}, "Subject Msg 中" to [email protected]'.format(msg.when_added),
)
msg.message_data = None
Expand All @@ -668,7 +667,7 @@ def test_message_log_str(self):

log = MessageLog.objects.get()
self.assertEqual(
six.text_type(log),
str(log),
'On {0}, "Subject Log 中" to [email protected]'.format(log.when_attempted),
)

Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ commands =
test: coverage run ./runtests.py
flake: flake8 --statistics --benchmark
checkmanifest: check-manifest
allowlist_externals = flake8
deps =
coverage
-r requirements-test.txt
Expand Down

0 comments on commit 51d73f1

Please sign in to comment.