mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
#18324: set_payload now correctly handles binary input.
This also backs out the previous fixes for for #14360, #1717, and #16564. Those bugs were actually caused by the fact that set_payload didn't decode to str, thus rendering the model inconsistent. This fix does mean the data processed by the encoder functions goes through an extra encode/decode cycle, but it means the model is always consistent. Future API updates will provide a better way to encode payloads, which will bypass this minor de-optimization. Tests by Vajrasky Kok.
This commit is contained in:
parent
0b169125ca
commit
00ae435dee
4 changed files with 45 additions and 16 deletions
|
@ -275,6 +275,8 @@ class Message:
|
|||
Optional charset sets the message's default character set. See
|
||||
set_charset() for details.
|
||||
"""
|
||||
if isinstance(payload, bytes):
|
||||
payload = payload.decode('ascii', 'surrogateescape')
|
||||
self._payload = payload
|
||||
if charset is not None:
|
||||
self.set_charset(charset)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue