MCPcopy Index your code
hub / github.com/python/cpython / set_payload

Method set_payload

Lib/email/message.py:343–361  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

341 return payload
342
343 def set_payload(self, payload, charset=None):
344 """Set the payload to the given value.
345
346 Optional charset sets the message's default character set. See
347 set_charset() for details.
348 """
349 if hasattr(payload, 'encode'):
350 if charset is None:
351 self._payload = payload
352 return
353 if not isinstance(charset, Charset):
354 charset = Charset(charset)
355 payload = payload.encode(charset.output_charset, 'surrogateescape')
356 if hasattr(payload, 'decode'):
357 self._payload = payload.decode('ascii', 'surrogateescape')
358 else:
359 self._payload = payload
360 if charset is not None:
361 self.set_charset(charset)
362
363 def set_charset(self, charset):
364 """Set the charset of the payload to a given character set.

Calls 4

set_charsetMethod · 0.95
CharsetClass · 0.85
encodeMethod · 0.45
decodeMethod · 0.45