From 9851d2a5ec0ce64644f333c28250cee4ec1cd461 Mon Sep 17 00:00:00 2001 From: Matt Molyneaux Date: Wed, 1 Jan 2020 19:36:36 +0000 Subject: [PATCH] Remove use of super(klass, self) and class klass(object) Neither are required for Python 3 --- salmon/bounce.py | 4 ++-- salmon/confirm.py | 4 ++-- salmon/encoding.py | 10 ++++------ salmon/mail.py | 4 ++-- salmon/queue.py | 2 +- salmon/routing.py | 12 ++++++------ salmon/server.py | 4 ++-- salmon/testing.py | 2 +- tests/bounce_tests.py | 4 ++-- tests/command_tests.py | 12 ++++++------ tests/confirm_tests.py | 4 ++-- tests/integration_tests.py | 2 +- tests/routing_tests.py | 2 +- tests/utils_tests.py | 2 +- 14 files changed, 33 insertions(+), 35 deletions(-) diff --git a/salmon/bounce.py b/salmon/bounce.py index 03a9a10..adba147 100644 --- a/salmon/bounce.py +++ b/salmon/bounce.py @@ -157,7 +157,7 @@ def detect(msg): return BounceAnalyzer(results, score / BOUNCE_MAX) -class BounceAnalyzer(object): +class BounceAnalyzer: """ BounceAnalyzer collects up the score and the headers and gives more meaningful interaction with them. You can keep it simple and just use @@ -265,7 +265,7 @@ def error_for_humans(self): return "No status codes found in bounce message." -class bounce_to(object): +class bounce_to: """ Used to route bounce messages to a handler for either soft or hard bounces. Set the soft/hard parameters to the function that represents the handler. diff --git a/salmon/confirm.py b/salmon/confirm.py index 5df7115..4cc7401 100644 --- a/salmon/confirm.py +++ b/salmon/confirm.py @@ -19,7 +19,7 @@ from salmon import queue, view -class ConfirmationStorage(object): +class ConfirmationStorage: """ This is the basic confirmation storage. For simple testing purposes you can just use the default hash db parameter. If you do a deployment @@ -82,7 +82,7 @@ def store(self, target, from_address, expected_secret, pending_message_id): pending_message_id) -class ConfirmationEngine(object): +class ConfirmationEngine: """ The confirmation engine is what does the work of sending a confirmation, and verifying that it was confirmed properly. In order to use it you diff --git a/salmon/encoding.py b/salmon/encoding.py index 3ad06c9..67c38b4 100644 --- a/salmon/encoding.py +++ b/salmon/encoding.py @@ -101,7 +101,7 @@ class EncodingError(Exception): pass -class ContentEncoding(object): +class ContentEncoding: """ Wrapper various content encoding headers @@ -163,7 +163,7 @@ def keys(self): return CONTENT_ENCODING_KEYS -class MailBase(object): +class MailBase: """ MailBase is used as the basis of salmon.mail and contains the basics of encoding an email. You actually can do all your email processing with this @@ -286,11 +286,9 @@ class MIMEPart(Message): encode what you ask it. """ def __init__(self, type_, **params): - self.mimetype = type_ + super().__init__() - # classes from email.* are all old-style in Python, so don't replace - # this with super() - Message.__init__(self) + self.mimetype = type_ self.add_header('Content-Type', type_, **params) diff --git a/salmon/mail.py b/salmon/mail.py index d5185e7..5af9fc5 100644 --- a/salmon/mail.py +++ b/salmon/mail.py @@ -43,7 +43,7 @@ def _decode_header_randomness(addr): raise encoding.EncodingError("Address must be a string or a list not: %r", type(addr)) -class MailRequest(object): +class MailRequest: """ This is what is given to your message handlers. The information you get out of this is *ALWAYS* in Python str and should be usable by any API. @@ -159,7 +159,7 @@ def original(self): return self.Data -class MailResponse(object): +class MailResponse: """ You are given MailResponse objects from the salmon.view methods, and whenever you want to generate an email to send to someone. It has diff --git a/salmon/queue.py b/salmon/queue.py index 9dd9dee..6d497b3 100644 --- a/salmon/queue.py +++ b/salmon/queue.py @@ -50,7 +50,7 @@ def __init__(self, msg, data): self.data = data -class Queue(object): +class Queue: """ Provides a simplified API for dealing with 'queues' in Salmon. It currently just supports Maildir queues since those are the diff --git a/salmon/routing.py b/salmon/routing.py index 197ad9f..9bf6bae 100644 --- a/salmon/routing.py +++ b/salmon/routing.py @@ -64,7 +64,7 @@ def DEFAULT_STATE_KEY(mod, msg): return mod -class StateStorage(object): +class StateStorage: """ The base storage class you need to implement for a custom storage system. @@ -149,7 +149,7 @@ def get(self, key, sender): """ with self.lock: self.states = shelve.open(self.database_path) - value = super(ShelveStorage, self).get(key.encode('ascii'), sender) + value = super().get(key.encode('ascii'), sender) self.states.close() return value @@ -159,7 +159,7 @@ def set(self, key, sender, state): """ with self.lock: self.states = shelve.open(self.database_path) - super(ShelveStorage, self).set(key.encode('ascii'), sender, state) + super().set(key.encode('ascii'), sender, state) self.states.close() def clear(self): @@ -169,11 +169,11 @@ def clear(self): """ with self.lock: self.states = shelve.open(self.database_path) - super(ShelveStorage, self).clear() + super().clear() self.states.close() -class RoutingBase(object): +class RoutingBase: """ The self is a globally accessible class that is actually more like a glorified module. It is used mostly internally by the salmon.routing @@ -439,7 +439,7 @@ def reload(self): Router = RoutingBase() -class route(object): +class route: """ The @route decorator is attached to state handlers to configure them in the Router so they handle messages for them. The way this works is, rather than diff --git a/salmon/server.py b/salmon/server.py index 7492b19..0ff3e5e 100644 --- a/salmon/server.py +++ b/salmon/server.py @@ -59,7 +59,7 @@ def error_for_code(self, code): return " ".join([primary, secondary, combined]).strip() -class Relay(object): +class Relay: """ Used to talk to your "relay server" or smart host, this is probably the most important class in the handlers next to the salmon.routing.Router. @@ -287,7 +287,7 @@ def close(self): logging.error(trace) -class QueueReceiver(object): +class QueueReceiver: """ Rather than listen on a socket this will watch a queue directory and process messages it receives from that. It works in almost the exact diff --git a/salmon/testing.py b/salmon/testing.py index dacad56..19c55e0 100644 --- a/salmon/testing.py +++ b/salmon/testing.py @@ -64,7 +64,7 @@ def delivered(pattern, to_queue=None): return False -class TestConversation(object): +class TestConversation: """ Used to easily do conversations with an email server such that you send a message and then expect certain responses. diff --git a/tests/bounce_tests.py b/tests/bounce_tests.py index 2abb6fc..d2297d8 100644 --- a/tests/bounce_tests.py +++ b/tests/bounce_tests.py @@ -7,12 +7,12 @@ class BounceTestCase(SalmonTestCase): def setUp(self): - super(BounceTestCase, self).setUp() + super().setUp() Router.load(["tests.handlers.bounce_filtered_mod"]) Router.reload() def tearDown(self): - super(BounceTestCase, self).tearDown() + super().tearDown() Router.HANDLERS.clear() Router.reload() diff --git a/tests/command_tests.py b/tests/command_tests.py index b0ac376..99e00e2 100644 --- a/tests/command_tests.py +++ b/tests/command_tests.py @@ -19,7 +19,7 @@ def make_fake_pid_file(): class CliRunner(testing.CliRunner): def invoke(self, *args, **kwargs): kwargs.setdefault("catch_exceptions", False) - return super(CliRunner, self).invoke(*args, **kwargs) + return super().invoke(*args, **kwargs) class CommandTestCase(SalmonTestCase): @@ -166,7 +166,7 @@ def test_non_daemon(self, settings_mock, daemon_mock): class CleanseCommandTestCase(SalmonTestCase): def setUp(self): - super(CleanseCommandTestCase, self).setUp() + super().setUp() queue.Queue("run/queue").clear() def test_cleanse_command(self): @@ -211,7 +211,7 @@ def test_encoding_error(self, from_message): class GenCommandTestCase(SalmonTestCase): def setUp(self): - super(GenCommandTestCase, self).setUp() + super().setUp() tmp_dir = mkdtemp() self.project = os.path.join(tmp_dir, 'testproject') @@ -245,7 +245,7 @@ def test_force(self): class StopCommandTestCase(SalmonTestCase): def setUp(self): - super(StopCommandTestCase, self).setUp() + super().setUp() patcher = patch("os.kill") patcher.start() self.addCleanup(patcher.stop) @@ -290,7 +290,7 @@ def test_stop_force_oserror(self): class RoutesCommandTestCase(SalmonTestCase): def setUp(self): - super(RoutesCommandTestCase, self).setUp() + super().setUp() if "salmon.handlers.log" in sys.modules: del sys.modules["salmon.handlers.log"] routing.Router.clear_routes() @@ -358,7 +358,7 @@ def test_no_test(self): class BlastCommandTestCase(SalmonTestCase): def setUp(self): - super(BlastCommandTestCase, self).setUp() + super().setUp() queue.Queue("run/queue").clear() @patch("salmon.server.smtplib.SMTP") diff --git a/tests/confirm_tests.py b/tests/confirm_tests.py index c0f6b5f..0570d30 100644 --- a/tests/confirm_tests.py +++ b/tests/confirm_tests.py @@ -11,13 +11,13 @@ class ConfirmationTestCase(SalmonTestCase): def setUp(self): - super(ConfirmationTestCase, self).setUp() + super().setUp() self.storage = ConfirmationStorage() self.engine = ConfirmationEngine('run/confirm', self.storage) view.LOADER = jinja2.Environment(loader=jinja2.FileSystemLoader('tests/data/templates')) def tearDown(self): - super(ConfirmationTestCase, self).tearDown() + super().tearDown() view.LOADER = None def test_ConfirmationStorage(self): diff --git a/tests/integration_tests.py b/tests/integration_tests.py index 8a4f52b..97ea22f 100644 --- a/tests/integration_tests.py +++ b/tests/integration_tests.py @@ -40,7 +40,7 @@ def tearDownClass(cls): rmtree(os.path.join(cls._cwd, path), ignore_errors=True) def setUp(self): - super(IntegrationTestCase, self).setUp() + super().setUp() # re-create destoryed queues queue.Queue(os.path.join(self._cwd, server_settings.UNDELIVERABLE_QUEUE)).clear() queue.Queue(os.path.join(self._cwd, server_settings.QUEUE_PATH)).clear() diff --git a/tests/routing_tests.py b/tests/routing_tests.py index d2c06e6..07a37f3 100644 --- a/tests/routing_tests.py +++ b/tests/routing_tests.py @@ -103,7 +103,7 @@ def test_StateStorage_clear_raises(self): s.clear() def test_route___get___raises(self): - class BadRoute(object): + class BadRoute: @route("test") def wont_work(message, **kw): diff --git a/tests/utils_tests.py b/tests/utils_tests.py index d834c30..401488d 100644 --- a/tests/utils_tests.py +++ b/tests/utils_tests.py @@ -11,7 +11,7 @@ class UtilsTestCase(SalmonTestCase): def tearDown(self): - super(UtilsTestCase, self).tearDown() + super().tearDown() self.clear_settings() def clear_settings(self):