From 721df895f9ea9d8073c13fbd2f75a6fbdc75ffc7 Mon Sep 17 00:00:00 2001 From: Maria Mitropoulou <56678215+mmitropoulou@users.noreply.github.com> Date: Thu, 7 Sep 2023 08:47:42 +0300 Subject: [PATCH 1/3] Fix charset handling in MailSender #5096 (#5118) --- scrapy/mail.py | 7 +++---- tests/test_mail.py | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/scrapy/mail.py b/scrapy/mail.py index c11f3898d..237327451 100644 --- a/scrapy/mail.py +++ b/scrapy/mail.py @@ -96,10 +96,9 @@ class MailSender: rcpts.extend(cc) msg["Cc"] = COMMASPACE.join(cc) - if charset: - msg.set_charset(charset) - if attachs: + if charset: + msg.set_charset(charset) msg.attach(MIMEText(body, "plain", charset or "us-ascii")) for attach_name, mimetype, f in attachs: part = MIMEBase(*mimetype.split("/")) @@ -110,7 +109,7 @@ class MailSender: ) msg.attach(part) else: - msg.set_payload(body) + msg.set_payload(body, charset) if _callback: _callback(to=to, subject=subject, body=body, cc=cc, attach=attachs, msg=msg) diff --git a/tests/test_mail.py b/tests/test_mail.py index 504c78486..2535e58db 100644 --- a/tests/test_mail.py +++ b/tests/test_mail.py @@ -111,7 +111,7 @@ class MailSenderTest(unittest.TestCase): msg = self.catched_msg["msg"] self.assertEqual(msg["subject"], subject) - self.assertEqual(msg.get_payload(), body) + self.assertEqual(msg.get_payload(decode=True).decode("utf-8"), body) self.assertEqual(msg.get_charset(), Charset("utf-8")) self.assertEqual(msg.get("Content-Type"), 'text/plain; charset="utf-8"') From e26bf4f918befe0fe0625d240ea4a54294923a62 Mon Sep 17 00:00:00 2001 From: Andrey Rakhmatullin Date: Tue, 12 Sep 2023 18:18:25 +0400 Subject: [PATCH 2/3] Pin brotli for PyPy tests (#6045) --- tests/requirements.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/requirements.txt b/tests/requirements.txt index 37186f3a7..3ea7f3333 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -12,7 +12,9 @@ uvloop; platform_system != "Windows" and python_version < "3.12" # bpython requires greenlet which currently doesn't build on 3.12 bpython; python_version < "3.12" # optional for shell wrapper tests -brotli # optional for HTTP compress downloader middleware tests +brotli; implementation_name != 'pypy' # optional for HTTP compress downloader middleware tests +# 1.1.0 is broken on PyPy: https://github.com/google/brotli/issues/1072 +brotli==1.0.9; implementation_name == 'pypy' # optional for HTTP compress downloader middleware tests zstandard; implementation_name != 'pypy' # optional for HTTP compress downloader middleware tests ipython pywin32; sys_platform == "win32" From da39fbd2709edc737059c68c5f70da19b89bbaa2 Mon Sep 17 00:00:00 2001 From: Andrey Rakhmatullin Date: Tue, 12 Sep 2023 22:07:10 +0400 Subject: [PATCH 3/3] Update tool versions (#6046) --- .github/workflows/tests-ubuntu.yml | 6 +++--- .pre-commit-config.yaml | 6 +++--- tox.ini | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/tests-ubuntu.yml b/.github/workflows/tests-ubuntu.yml index c2b686628..5ff92a571 100644 --- a/.github/workflows/tests-ubuntu.yml +++ b/.github/workflows/tests-ubuntu.yml @@ -48,13 +48,13 @@ jobs: env: TOXENV: botocore - - python-version: "3.12.0-rc.1" + - python-version: "3.12.0-rc.2" env: TOXENV: py - - python-version: "3.12.0-rc.1" + - python-version: "3.12.0-rc.2" env: TOXENV: asyncio - - python-version: "3.12.0-rc.1" + - python-version: "3.12.0-rc.2" env: TOXENV: extra-deps diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5998ebef8..0cff5cc73 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,7 +9,7 @@ repos: hooks: - id: flake8 - repo: https://github.com/psf/black.git - rev: 23.7.0 + rev: 23.9.1 hooks: - id: black - repo: https://github.com/pycqa/isort @@ -17,8 +17,8 @@ repos: hooks: - id: isort - repo: https://github.com/adamchainz/blacken-docs - rev: 1.15.0 + rev: 1.16.0 hooks: - id: blacken-docs additional_dependencies: - - black==23.7.0 + - black==23.9.1 diff --git a/tox.ini b/tox.ini index 3ed8b6f63..9c2522a43 100644 --- a/tox.ini +++ b/tox.ini @@ -33,14 +33,14 @@ install_command = [testenv:typing] basepython = python3 deps = - mypy==1.4.1 + mypy==1.5.1 typing-extensions==4.7.1 types-attrs==19.1.0 types-lxml==2023.3.28 - types-Pillow==10.0.0.2 - types-Pygments==2.15.0.2 + types-Pillow==10.0.0.3 + types-Pygments==2.16.0.0 types-pyOpenSSL==23.2.0.2 - types-setuptools==68.0.0.3 + types-setuptools==68.2.0.0 # 2.1.2 fixes a typing bug: https://github.com/scrapy/w3lib/pull/211 w3lib >= 2.1.2 commands = @@ -65,7 +65,7 @@ commands = basepython = python3 deps = twine==4.0.2 - build==0.10.0 + build==1.0.3 commands = python -m build --sdist twine check dist/*