Content-Length: 329444 | pFad | http://github.com/python/cpython/pull/136071/commits/2d2906d8704174a39596bd53f1093704c9cf8fbe

66 gh-134759: `UnboundLocalError` in `email.message.Message.get_payload` by skv0zsneg · Pull Request #136071 · python/cpython · GitHub
Skip to content

gh-134759: UnboundLocalError in email.message.Message.get_payload #136071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jul 12, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test for getting bytes payload with quoted-printable cte.
  • Loading branch information
skv0zsneg committed Jun 28, 2025
commit 2d2906d8704174a39596bd53f1093704c9cf8fbe
7 changes: 7 additions & 0 deletions Lib/test/test_email/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,13 @@ def test_get_body_malformed(self):
# AttributeError: 'str' object has no attribute 'is_attachment'
m.get_body()

def test_get_bytes_payload_with_quoted_printable_encoding(self):
payload = b'Some payload'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def test_get_bytes_payload_with_quoted_printable_encoding(self):
payload = b'Some payload'
def test_get_bytes_payload_with_quoted_printable_encoding(self):
# See https://github.com/python/cpython/issues/134759.
payload = b'Some payload'

This comment was marked as resolved.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use the following for only using public methods:

        payload = memoryview(b'Some payload')
        m = self._make_message()
        m.add_header('Content-Transfer-Encoding', 'quoted-printable')
        m.set_payload(payload)
        self.assertEqual(m.get_payload(decode=True), payload)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was trying to reproduce bug with "public" method .set_payload(). I'm achieved that by passing BytesIO(b"Some payload") buffer but was not sure about correct arg type of .set_payload() (typeshed want object only with the .decode() method), so came up to put bytes directly.

I'll change the way you suggest, no problem :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, decode() is not present on memoryview but it's a buffer-like protocol so I think it should be fine. However, this may be a side-effect of the current implementation :) (also, the current implementation only does duck typing, not true isinstance() checks when setting the payload)

m = self._make_message()
m.add_header('Content-Transfer-Encoding', 'quoted-printable')
m._payload = payload
self.assertEqual(m.get_payload(decode=True), payload)


class TestMIMEPart(TestEmailMessageBase, TestEmailBase):
# Doing the full test run here may seem a bit redundant, since the two
Expand Down








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/python/cpython/pull/136071/commits/2d2906d8704174a39596bd53f1093704c9cf8fbe

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy