From 52f70074dc68228c7a8672ed4e6929a5df309540 Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Tue, 21 May 2024 20:53:22 +0200 Subject: [PATCH] remove Python2 crumbs (#32) --- muttdown/config.py | 4 +--- muttdown/main.py | 11 +++-------- setup.py | 1 - tests/test_basic.py | 5 +---- 4 files changed, 5 insertions(+), 16 deletions(-) diff --git a/muttdown/config.py b/muttdown/config.py index 5af64b3..ded1a44 100644 --- a/muttdown/config.py +++ b/muttdown/config.py @@ -2,7 +2,6 @@ import os.path from subprocess import check_output -import six import yaml # largely copied from my earlier work in fakemtpd @@ -43,8 +42,7 @@ def __str__(self): return "%s(%r)" % (self.__class__.__name__, self.message) -@six.add_metaclass(_ParamsAsProps) -class Config(object): +class Config(metaclass=_ParamsAsProps): _parameters = { "smtp_host": "127.0.0.1", "smtp_port": 25, diff --git a/muttdown/main.py b/muttdown/main.py index bb047f9..8ecd331 100644 --- a/muttdown/main.py +++ b/muttdown/main.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import argparse import email import email.iterators @@ -13,7 +11,6 @@ import markdown import pynliner -import six from . import __version__, config @@ -31,7 +28,7 @@ def convert_one(part, config, charset): text = part.get_payload(decode=True) if part.get_charset(): charset = get_charset_from_message_fragment(part) - if not isinstance(text, six.text_type): + if not isinstance(text, str): # decode=True only decodes the base64/uuencoded nature, and # will always return bytes; gotta decode it if charset is not None: @@ -214,8 +211,7 @@ def main(argv=None): proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, shell=False) msg = rebuilt.as_string() - if sys.version_info > (3, 0): - msg = msg.encode("utf-8") + msg = msg.encode("utf-8") proc.stdin.write(msg) proc.stdin.close() proc.wait() @@ -223,8 +219,7 @@ def main(argv=None): else: conn = smtp_connection(c) msg = rebuilt.as_string() - if sys.version_info > (3, 0): - msg = msg.encode("utf-8") + msg = msg.encode("utf-8") conn.sendmail(args.envelope_from, args.addresses, msg) conn.quit() return 0 diff --git a/setup.py b/setup.py index 5af6a5f..7e638b1 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,6 @@ "Markdown>=3.0,<4.0", "PyYAML>=3.0", "pynliner==0.8.0", - "six", ], entry_points={ "console_scripts": [ diff --git a/tests/test_basic.py b/tests/test_basic.py index 45cfbea..bcf4692 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -303,10 +303,7 @@ def test_main_passthru(tempdir, mocker): def test_raw_unicode(basic_config): raw_message = b"Date: Fri, 1 Mar 2019 17:54:06 -0800\nFrom: Test \nTo: Test \nSubject: Re: Fwd: Important: 2019 =?utf-8?Q?Securit?=\n =?utf-8?B?eSBVcGRhdGUg4oCU?=\nReferences: \n \nMIME-Version: 1.0\nContent-Type: text/plain; charset=utf-8\nContent-Disposition: inline\nContent-Transfer-Encoding: 8bit\nUser-Agent: Mutt/1.11.3 (2019-02-01)\n\nThis is a test\n\n\nOn Fri, Mar 01, 2019 at 03:08:35PM -0800, Test Wrote:\n> :)\n> \n> \n> \xc3\x98 Text\n> \n> \xc2\xb7 text\n-- \nend\n" # noqa - if sys.version_info > (3, 0): - mail = email.message_from_string(raw_message.decode("utf-8")) - else: - mail = email.message_from_string(raw_message) + mail = email.message_from_string(raw_message.decode("utf-8")) converted = process_message(mail, basic_config) assert converted["From"] == "Test " assert "Ø" in converted.get_payload()