Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 729c5e2

Browse files
committed
Merge #11216: document all possible set_charset execution paths.
2 parents f228e5b + e3d09ff commit 729c5e2

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

Doc/library/email.message.rst

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,22 @@ Here are the methods of the :class:`Message` class:
139139
string naming a character set, or ``None``. If it is a string, it will
140140
be converted to a :class:`~email.charset.Charset` instance. If *charset*
141141
is ``None``, the ``charset`` parameter will be removed from the
142-
:mailheader:`Content-Type` header. Anything else will generate a
143-
:exc:`TypeError`.
144-
145-
The message will be assumed to be of type :mimetype:`text/\*` encoded with
146-
*charset.input_charset*. It will be converted to *charset.output_charset*
147-
and encoded properly, if needed, when generating the plain text
148-
representation of the message. MIME headers (:mailheader:`MIME-Version`,
149-
:mailheader:`Content-Type`, :mailheader:`Content-Transfer-Encoding`) will
150-
be added as needed.
142+
:mailheader:`Content-Type` header (the message will not be otherwise
143+
modified). Anything else will generate a :exc:`TypeError`.
144+
145+
If there is no existing :mailheader:`MIME-Version` header one will be
146+
added. If there is no existing :mailheader:`Content-Type` header, one
147+
will be added with a value of :mimetype:`text/plain`. Whether the
148+
:mailheader:`Content-Type` header already exists or not, its ``charset``
149+
parameter will be set to *charset.output_charset*. If
150+
*charset.input_charset* and *charset.output_charset* differ, the payload
151+
will be re-encoded to the *output_charset*. If there is no existing
152+
:mailheader:`Content-Transfer-Encoding` header, then the payload will be
153+
transfer-encoded, if needed, using the specified
154+
:class:`~email.charset.Charset`, and a header with the appropriate value
155+
will be added. If a :mailheader:`Content-Transfer-Encoding` header
156+
already exists, the payload is assumed to already be correctly encoded
157+
using that :mailheader:`Content-Transfer-Encoding` and is not modified.
151158

152159
.. method:: get_charset()
153160

0 commit comments

Comments
 (0)