Skip to content

Commit

Permalink
Merge pull request #31 from caktus/django-22-31
Browse files Browse the repository at this point in the history
Test against Django 2.2,3.0,3.1 and remove python2isms
  • Loading branch information
Vinod Kurup authored Dec 17, 2020
2 parents 66286fa + 8b3e8f0 commit 1504d3d
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 33 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ email backend such as `django-ses <https://github.com/hmarr/django-ses>`_.
Requirements
-------------------------------

- Python 2.7 or 3.5+
- Django >= 1.8 (supported versions)
- Python 3
- Django >= 2.2 (supported versions)


Installation
Expand Down
14 changes: 6 additions & 8 deletions bandit/backends/base.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
from __future__ import unicode_literals

import logging
import re
from email.utils import parseaddr

from django.conf import settings
from django.template.loader import render_to_string

logger = logging.getLogger("bandit.backends.base")
logger = logging.getLogger(__name__)


class HijackBackendMixin(object):
"""
This backend mixin intercepts outgoing messages, redirecting them to addresses in the
BANDIT_EMAIL setting.
Addresses which are not in ADMINS, SERVER_EMAIL, BANDIT_EMAIL or BANDIT_WHITELIST are
intercepted.
Addresses which are not in ADMINS, SERVER_EMAIL, BANDIT_EMAIL, BANDIT_WHITELIST, or
which do not match BANDIT_REGEX_WHITELIST are intercepted.
"""

def __init__(self, *args, **kwargs):
self.log_only = kwargs.pop("log_only", False)
self.log_level = kwargs.pop("log_level", logging.DEBUG)
super(HijackBackendMixin, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def send_messages(self, email_messages):
admins = getattr(settings, "ADMINS", ())
Expand Down Expand Up @@ -80,11 +78,11 @@ def is_approved(email):
# keep track of how many messages were only logged so we
# can report them as sent to the caller
logged_count += 1
sent_count = super(HijackBackendMixin, self).send_messages(to_send) or 0
sent_count = super().send_messages(to_send) or 0
return sent_count + logged_count


class LogOnlyBackendMixin(HijackBackendMixin):
def __init__(self, *args, **kwargs):
kwargs["log_only"] = True
super(LogOnlyBackendMixin, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
2 changes: 0 additions & 2 deletions bandit/backends/seacuke.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from seacucumber.backend import SESBackend

from bandit.backends.base import HijackBackendMixin, LogOnlyBackendMixin
Expand Down
2 changes: 0 additions & 2 deletions bandit/backends/smtp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.core.mail.backends.smtp import EmailBackend as SMTPBackend

from bandit.backends.base import HijackBackendMixin, LogOnlyBackendMixin
Expand Down
8 changes: 1 addition & 7 deletions bandit/tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from __future__ import unicode_literals

import asyncore
import platform
import smtpd
import threading
from email import message_from_string
Expand All @@ -22,8 +19,7 @@ class FakeSMTPServer(smtpd.SMTPServer, threading.Thread):

def __init__(self, *args, **kwargs):
threading.Thread.__init__(self)
if platform.python_version_tuple() >= ("3", "5"):
kwargs.setdefault("decode_data", True)
kwargs.setdefault("decode_data", True)
smtpd.SMTPServer.__init__(self, *args, **kwargs)
self._sink = []
self.active = False
Expand Down Expand Up @@ -91,12 +87,10 @@ def tearDownClass(cls):
cls.server.stop()

def setUp(self):
super(BaseBackendTestCase, self).setUp()
self.flush_mailbox()

def tearDown(self):
self.flush_mailbox()
super(BaseBackendTestCase, self).tearDown()

def get_connection(self):
raise NotImplementedError("Must define in subclass")
Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
. # <- install ourselves
caktus-sphinx-theme
coverage
django>=2.0,<2.1
django>=2.2,<3.0
flake8
pre-commit
sphinx
Expand Down
2 changes: 0 additions & 2 deletions docs/requirements.txt

This file was deleted.

8 changes: 6 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@
"Development Status :: 5 - Production/Stable",
"Environment :: Web Environment",
"Framework :: Django",
"Framework :: Django :: 2.2",
"Framework :: Django :: 3.0",
"Framework :: Django :: 3.1",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
"Topic :: Software Development :: Libraries :: Python Modules",
],
Expand Down
12 changes: 5 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[tox]
envlist = {py36}-{1.8,1.10,1.11},
{py36,py37,py38,py39}-{2.0}
envlist = {py36,py37,py38,py39}-{2.2,3.0,3.1}

[gh-actions]
python =
Expand All @@ -10,9 +9,8 @@ python =
3.9: py39

[testenv]
commands = python -Wmodule runtests.py
commands = python runtests.py
deps =
1.8: Django>=1.8,<1.9
1.10: Django>=1.10,<1.11
1.11: Django>=1.11,<2.0
2.0: Django>=2.0,<2.1
2.2: Django>=2.2,<3.0
3.0: Django>=3.0,<3.1
3.1: Django>=3.1,<3.2

0 comments on commit 1504d3d

Please sign in to comment.