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

Skip to content

Commit fb1a7bc

Browse files
committed
#18600: In 3.3, as_string does not accept a policy keyword.
Also, document the policy keyword that was added to Message in 3.3.
1 parent 2532635 commit fb1a7bc

2 files changed

Lines changed: 8 additions & 12 deletions

File tree

Doc/library/email.message.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,15 @@ parameters, and for recursively walking over the object tree.
3131
Here are the methods of the :class:`Message` class:
3232

3333

34-
.. class:: Message()
34+
.. class:: Message(policy=compat32)
3535

36-
The constructor takes no arguments.
36+
The *policy* argument determiens the :mod:`~email.policy` that will be used
37+
to update the message model. The default value, :class:`compat32
38+
<email.policy.Compat32>` maintains backward compatibility with the
39+
Python 3.2 version of the email package. For more information see the
40+
:mod:`~email.policy` documentation.
41+
42+
.. versionchanged:: 3.3 The *policy* keyword argument was added.
3743

3844

3945
.. method:: as_string(unixfrom=False, maxheaderlen=0)

Doc/library/email.policy.rst

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,6 @@ correct line separator characters when creating the binary string to feed into
9797
``sendmail's`` ``stdin``, where the default policy would use ``\n`` line
9898
separators.
9999

100-
Some email package methods accept a *policy* keyword argument, allowing the
101-
policy to be overridden for that method. For example, the following code uses
102-
the :meth:`~email.message.Message.as_string` method of the *msg* object from
103-
the previous example and writes the message to a file using the native line
104-
separators for the platform on which it is running::
105-
106-
>>> import os
107-
>>> with open('converted.txt', 'wb') as f:
108-
... f.write(msg.as_string(policy=msg.policy.clone(linesep=os.linesep)))
109-
110100
Policy objects can also be combined using the addition operator, producing a
111101
policy object whose settings are a combination of the non-default values of the
112102
summed objects::

0 commit comments

Comments
 (0)