Set the payload to the given value. Optional charset sets the message's default character set. See set_charset() for details.
(self, payload, charset=None)
| 329 | return payload |
| 330 | |
| 331 | def set_payload(self, payload, charset=None): |
| 332 | """Set the payload to the given value. |
| 333 | |
| 334 | Optional charset sets the message's default character set. See |
| 335 | set_charset() for details. |
| 336 | """ |
| 337 | if hasattr(payload, 'encode'): |
| 338 | if charset is None: |
| 339 | self._payload = payload |
| 340 | return |
| 341 | if not isinstance(charset, Charset): |
| 342 | charset = Charset(charset) |
| 343 | payload = payload.encode(charset.output_charset, 'surrogateescape') |
| 344 | if hasattr(payload, 'decode'): |
| 345 | self._payload = payload.decode('ascii', 'surrogateescape') |
| 346 | else: |
| 347 | self._payload = payload |
| 348 | if charset is not None: |
| 349 | self.set_charset(charset) |
| 350 | |
| 351 | def set_charset(self, charset): |
| 352 | """Set the charset of the payload to a given character set. |
no test coverage detected