From 738e91817fe7f31d35ae0b7b33648669b6f93f5b Mon Sep 17 00:00:00 2001 From: Alexandr Artemyev Date: Wed, 12 Jun 2024 23:59:20 +0500 Subject: [PATCH] Upgrade --- .github/workflows/test.yml | 20 +++++++------------ post_office/__init__.py | 6 +----- post_office/admin.py | 3 +-- post_office/backends.py | 1 - post_office/lockfile.py | 2 +- post_office/mail.py | 4 +--- .../0002_add_i18n_and_backend_alias.py | 2 +- .../migrations/0005_auto_20170515_0013.py | 2 +- post_office/migrations/0010_message_id.py | 2 +- post_office/template/__init__.py | 2 +- post_office/templatetags/post_office.py | 6 +++--- post_office/tests/test_html_email.py | 4 ++-- post_office/tests/test_mail.py | 9 +++++---- post_office/tests/test_models.py | 1 - post_office/tests/test_utils.py | 10 +++++----- setup.py | 12 ++++++----- 16 files changed, 37 insertions(+), 49 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f1633292..5390963f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,9 +2,7 @@ name: Test on: push: - branches: [ master ] pull_request: - branches: [ master ] permissions: contents: read @@ -16,15 +14,12 @@ jobs: name: Python${{ matrix.python-version }}/Django${{ matrix.django-version }} strategy: matrix: - python-version: ["3.8", "3.10"] - django-version: ["3.2", "4.0", "4.1", "4.2"] - # exclude: - # - python-version: 3.7 - # django-version: 4.0 - # - python-version: 3.7 - # django-version: 4.1 - # - python-version: 3.8 - # django-version: 4.2 + python-version: ["3.9", "3.10", "3.11", "3.12"] + django-version: ["4.2", "5.0"] + exclude: + - python-version: "3.9" + django-version: "5.0" + steps: - uses: actions/checkout@v3 @@ -37,8 +32,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install pytz - pip install "Django==${{ matrix.django-version }}.*" + pip install "Django~=${{ matrix.django-version }}.0" - name: Run Test run: | diff --git a/post_office/__init__.py b/post_office/__init__.py index 28f31ab2..c131d547 100644 --- a/post_office/__init__.py +++ b/post_office/__init__.py @@ -1,11 +1,7 @@ -import django from ast import literal_eval from os.path import dirname, join -with open(join(dirname(__file__), 'version.txt'), 'r') as fh: +with open(join(dirname(__file__), "version.txt")) as fh: VERSION = literal_eval(fh.read()) from .backends import EmailBackend - -if django.VERSION < (3, 2): # pragma: no cover - default_app_config = 'post_office.apps.PostOfficeConfig' diff --git a/post_office/admin.py b/post_office/admin.py index f2d478d4..86bd9c8b 100644 --- a/post_office/admin.py +++ b/post_office/admin.py @@ -17,13 +17,12 @@ from django.utils.translation import gettext_lazy as _ from .fields import CommaSeparatedEmailField -from .mail import send from .models import STATUS, Attachment, Email, EmailTemplate, Log from .sanitizer import clean_html def get_message_preview(instance): - return ('{0}...'.format(instance.message[:25]) if len(instance.message) > 25 + return (f'{instance.message[:25]}...' if len(instance.message) > 25 else instance.message) diff --git a/post_office/backends.py b/post_office/backends.py index 00bfb3df..94f2be1d 100644 --- a/post_office/backends.py +++ b/post_office/backends.py @@ -2,7 +2,6 @@ from email.mime.base import MIMEBase from django.core.files.base import ContentFile from django.core.mail.backends.base import BaseEmailBackend -import quopri from .settings import get_default_priority class EmailBackend(BaseEmailBackend): diff --git a/post_office/lockfile.py b/post_office/lockfile.py index ec95baee..25dae5ec 100644 --- a/post_office/lockfile.py +++ b/post_office/lockfile.py @@ -44,7 +44,7 @@ def __init__(self, lock_filename, timeout=None, force=False): def get_lock_pid(self): try: return int(open(self.lock_filename).read()) - except IOError: + except OSError: # If we can't read symbolic link, there are two possibilities: # 1. The symbolic link is dead (point to non existing file) # 2. Symbolic link is not there diff --git a/post_office/mail.py b/post_office/mail.py index 3a9a95a1..e48abafc 100644 --- a/post_office/mail.py +++ b/post_office/mail.py @@ -1,4 +1,3 @@ -import sys from django.conf import settings from django.core.exceptions import ValidationError @@ -7,8 +6,7 @@ from django.template import Context, Template from django.utils import timezone from email.utils import make_msgid -from multiprocessing import Pool, TimeoutError -from multiprocessing.context import TimeoutError as ContextTimeoutError +from multiprocessing import Pool from multiprocessing.dummy import Pool as ThreadPool from .connections import connections diff --git a/post_office/migrations/0002_add_i18n_and_backend_alias.py b/post_office/migrations/0002_add_i18n_and_backend_alias.py index 32fc4a10..79a7f5d2 100644 --- a/post_office/migrations/0002_add_i18n_and_backend_alias.py +++ b/post_office/migrations/0002_add_i18n_and_backend_alias.py @@ -81,6 +81,6 @@ class Migration(migrations.Migration): ), migrations.AlterUniqueTogether( name='emailtemplate', - unique_together=set([('language', 'default_template')]), + unique_together={('language', 'default_template')}, ), ] diff --git a/post_office/migrations/0005_auto_20170515_0013.py b/post_office/migrations/0005_auto_20170515_0013.py index bbcf1628..70b343a2 100644 --- a/post_office/migrations/0005_auto_20170515_0013.py +++ b/post_office/migrations/0005_auto_20170515_0013.py @@ -11,6 +11,6 @@ class Migration(migrations.Migration): operations = [ migrations.AlterUniqueTogether( name='emailtemplate', - unique_together=set([('name', 'language', 'default_template')]), + unique_together={('name', 'language', 'default_template')}, ), ] diff --git a/post_office/migrations/0010_message_id.py b/post_office/migrations/0010_message_id.py index c2546aed..cb5d8928 100644 --- a/post_office/migrations/0010_message_id.py +++ b/post_office/migrations/0010_message_id.py @@ -14,7 +14,7 @@ def forwards(apps, schema_editor): if email.status in [STATUS.queued, STATUS.requeued]: # create a unique Message-ID for all emails which have not been send yet randint1, randint2 = random.getrandbits(64), random.getrandbits(16) - email.message_id = '<{}.{}.{}@{}>'.format(email.id, randint1, randint2, msg_id_fqdn) + email.message_id = f'<{email.id}.{randint1}.{randint2}@{msg_id_fqdn}>' email.save() diff --git a/post_office/template/__init__.py b/post_office/template/__init__.py index 02fa5054..a8cb0d5e 100644 --- a/post_office/template/__init__.py +++ b/post_office/template/__init__.py @@ -14,5 +14,5 @@ def render_to_string(template_name, context=None, request=None, using=None): template = get_template(template_name, using=using) try: return template.render(context, request), template.template._attached_images - except Exception as a: + except Exception: return template.render(context, request) diff --git a/post_office/templatetags/post_office.py b/post_office/templatetags/post_office.py index e56c8a3c..3b75c9df 100644 --- a/post_office/templatetags/post_office.py +++ b/post_office/templatetags/post_office.py @@ -23,7 +23,7 @@ def inline_image(context, file): try: absfilename = finders.find(file) if absfilename is None: - raise FileNotFoundError("No such file: {}".format(file)) + raise FileNotFoundError(f"No such file: {file}") except Exception: if settings.DEBUG: raise @@ -33,6 +33,6 @@ def inline_image(context, file): image = MIMEImage(raw_data) md5sum = hashlib.md5(raw_data).hexdigest() image.add_header('Content-Disposition', 'inline', filename=md5sum) - image.add_header('Content-ID', '<{}>'.format(md5sum)) + image.add_header('Content-ID', f'<{md5sum}>') context.template._attached_images.append(image) - return 'cid:{}'.format(md5sum) + return f'cid:{md5sum}' diff --git a/post_office/tests/test_html_email.py b/post_office/tests/test_html_email.py index eeeb86d1..13334350 100644 --- a/post_office/tests/test_html_email.py +++ b/post_office/tests/test_html_email.py @@ -13,7 +13,7 @@ from post_office.models import Email, EmailTemplate, STATUS from post_office.template import render_to_string from post_office.template.backends.post_office import PostOfficeTemplates -from post_office.mail import create, send, send_queued +from post_office.mail import send, send_queued class HTMLMailTest(TestCase): @@ -165,7 +165,7 @@ def test_email_change_view(self): try: import bleach self.assertContains(response, "

Testing image attachments

") - self.assertContains(response, '= 2.3'] @@ -47,25 +47,27 @@ def run_tests(self): zip_safe=False, include_package_data=True, package_data={'': ['README.rst']}, + python_requires='>=3.9', install_requires=[ 'bleach[css]', - 'django>=3.2', - 'pytz', + 'django>=4.2', ], classifiers=[ 'Development Status :: 5 - Production/Stable', 'Environment :: Web Environment', 'Framework :: Django', + 'Framework :: Django :: 4.2', + 'Framework :: Django :: 5.0', 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3 :: Only', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', 'Topic :: Communications :: Email', 'Topic :: Internet :: WWW/HTTP', 'Topic :: Software Development :: Libraries :: Python Modules',