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

Method body_encode

tools/python-3.11.9-amd64/Lib/email/charset.py:370–399  ·  view source on GitHub ↗

Body-encode a string by converting it first to bytes. The type of encoding (base64 or quoted-printable) will be based on self.body_encoding. If body_encoding is None, we assume the output charset is a 7bit encoding, so re-encoding the decoded string using the a

(self, string)

Source from the content-addressed store, hash-verified

368 return None
369
370 def body_encode(self, string):
371 """Body-encode a string by converting it first to bytes.
372
373 The type of encoding (base64 or quoted-printable) will be based on
374 self.body_encoding. If body_encoding is None, we assume the
375 output charset is a 7bit encoding, so re-encoding the decoded
376 string using the ascii codec produces the correct string version
377 of the content.
378 """
379 if not string:
380 return string
381 if self.body_encoding is BASE64:
382 if isinstance(string, str):
383 string = string.encode(self.output_charset)
384 return email.base64mime.body_encode(string)
385 elif self.body_encoding is QP:
386 # quopromime.body_encode takes a string, but operates on it as if
387 # it were a list of byte codes. For a (minimal) history on why
388 # this is so, see changeset 0cf700464177. To correctly encode a
389 # character set, then, we must turn it into pseudo bytes via the
390 # latin1 charset, which will encode any byte as a single code point
391 # between 0 and 255, which is what body_encode is expecting.
392 if isinstance(string, str):
393 string = string.encode(self.output_charset)
394 string = string.decode('latin1')
395 return email.quoprimime.body_encode(string)
396 else:
397 if isinstance(string, str):
398 string = string.encode(self.output_charset).decode('ascii')
399 return string

Callers 2

set_charsetMethod · 0.95
_encode_textFunction · 0.80

Calls 2

encodeMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected