-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
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
Changes from 5 commits
46be53f
2d2906d
771288d
8ccd326
2271433
e156408
e09adad
125a69a
14bc4e8
1789c2d
af9dae0
9db7b01
6235701
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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' | ||||||||||||
|
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.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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)
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix ``UnboundLocalError`` in ``email.message.Message.get_payload``. Patch by Kliment Lamonov. | ||
skv0zsneg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.