MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / get_payload

Method get_payload

tools/python-3.11.9-amd64/Lib/email/message.py:243–329  ·  view source on GitHub ↗

Return a reference to the payload. The payload will either be a list object or a string. If you mutate the list object, you modify the message's payload in place. Optional i returns that index into the payload. Optional decode is a flag indicating whether th

(self, i=None, decode=False)

Source from the content-addressed store, hash-verified

241 " non-multipart payload")
242
243 def get_payload(self, i=None, decode=False):
244 """Return a reference to the payload.
245
246 The payload will either be a list object or a string. If you mutate
247 the list object, you modify the message's payload in place. Optional
248 i returns that index into the payload.
249
250 Optional decode is a flag indicating whether the payload should be
251 decoded or not, according to the Content-Transfer-Encoding header
252 (default is False).
253
254 When True and the message is not a multipart, the payload will be
255 decoded if this header's value is `quoted-printable' or `base64'. If
256 some other encoding is used, or the header is missing, or if the
257 payload has bogus data (i.e. bogus base64 or uuencoded data), the
258 payload is returned as-is.
259
260 If the message is a multipart and the decode flag is True, then None
261 is returned.
262 """
263 # Here is the logic table for this code, based on the email5.0.0 code:
264 # i decode is_multipart result
265 # ------ ------ ------------ ------------------------------
266 # None True True None
267 # i True True None
268 # None False True _payload (a list)
269 # i False True _payload element i (a Message)
270 # i False False error (not a list)
271 # i True False error (not a list)
272 # None False False _payload
273 # None True False _payload decoded (bytes)
274 # Note that Barry planned to factor out the 'decode' case, but that
275 # isn't so easy now that we handle the 8 bit data, which needs to be
276 # converted in both the decode and non-decode path.
277 if self.is_multipart():
278 if decode:
279 return None
280 if i is None:
281 return self._payload
282 else:
283 return self._payload[i]
284 # For backward compatibility, Use isinstance and this error message
285 # instead of the more logical is_multipart test.
286 if i is not None and not isinstance(self._payload, list):
287 raise TypeError('Expected list, got %s' % type(self._payload))
288 payload = self._payload
289 # cte might be a Header, so for now stringify it.
290 cte = str(self.get('content-transfer-encoding', '')).lower()
291 # payload may be bytes here.
292 if not decode:
293 if isinstance(payload, str) and utils._has_surrogates(payload):
294 try:
295 bpayload = payload.encode('ascii', 'surrogateescape')
296 try:
297 payload = bpayload.decode(self.get_param('charset', 'ascii'), 'replace')
298 except LookupError:
299 payload = bpayload.decode('ascii', 'replace')
300 except UnicodeEncodeError:

Callers 15

_repair_headersMethod · 0.95
_repair_headersMethod · 0.95
walkFunction · 0.80
body_line_iteratorFunction · 0.80
_structureFunction · 0.80
encode_base64Function · 0.80
encode_quopriFunction · 0.80
encode_7or8bitFunction · 0.80
_find_bodyMethod · 0.80
iter_attachmentsMethod · 0.80
iter_partsMethod · 0.80
_handle_textMethod · 0.80

Calls 13

is_multipartMethod · 0.95
getMethod · 0.95
get_paramMethod · 0.95
decode_bFunction · 0.90
strFunction · 0.85
_decode_uuFunction · 0.85
splitlinesMethod · 0.80
handle_defectMethod · 0.80
typeClass · 0.50
lowerMethod · 0.45
encodeMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected