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

Skip to content

Commit e252446

Browse files
committed
#21300: Clean up the docs for the email "policy" arguments.
1 parent 3d139d8 commit e252446

3 files changed

Lines changed: 37 additions & 23 deletions

File tree

Doc/library/email.generator.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ formatted string representation of a message object. For more detail, see
112112
:mod:`email.message`.
113113

114114
.. class:: BytesGenerator(outfp, mangle_from_=True, maxheaderlen=78, *, \
115-
policy=policy.default)
115+
policy=None)
116116

117117
The constructor for the :class:`BytesGenerator` class takes a binary
118118
:term:`file-like object` called *outfp* for an argument. *outfp* must
@@ -134,9 +134,11 @@ formatted string representation of a message object. For more detail, see
134134
wrapping. The default is 78, as recommended (but not required) by
135135
:rfc:`2822`.
136136

137+
137138
The *policy* keyword specifies a :mod:`~email.policy` object that controls a
138-
number of aspects of the generator's operation. The default policy
139-
maintains backward compatibility.
139+
number of aspects of the generator's operation. If no *policy* is specified,
140+
then the *policy* attached to the message object passed to :attr:`flatten`
141+
is used.
140142

141143
.. versionchanged:: 3.3 Added the *policy* keyword.
142144

@@ -174,7 +176,7 @@ formatted string representation of a message object. For more detail, see
174176

175177
Optional *linesep* specifies the line separator character used to
176178
terminate lines in the output. If specified it overrides the value
177-
specified by the ``Generator``\ 's ``policy``.
179+
specified by the ``Generator``\ or *msg*\ 's ``policy``.
178180

179181
.. method:: clone(fp)
180182

Doc/library/email.parser.rst

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,18 @@ list of defects that it can find.
6060
Here is the API for the :class:`FeedParser`:
6161

6262

63-
.. class:: FeedParser(_factory=email.message.Message, *, policy=policy.default)
63+
.. class:: FeedParser(_factory=email.message.Message, *, policy=policy.compat32)
6464

6565
Create a :class:`FeedParser` instance. Optional *_factory* is a no-argument
6666
callable that will be called whenever a new message object is needed. It
6767
defaults to the :class:`email.message.Message` class.
6868

69-
The *policy* keyword specifies a :mod:`~email.policy` object that controls a
70-
number of aspects of the parser's operation. The default policy maintains
71-
backward compatibility.
69+
If *policy* is specified (it must be an instance of a :mod:`~email.policy`
70+
class) use the rules it specifies to udpate the representation of the
71+
message. If *policy* is not set, use the :class:`compat32
72+
<email.policy.Compat32>` policy, which maintains backward compatibility with
73+
the Python 3.2 version of the email package. For more information see the
74+
:mod:`~email.policy` documentation.
7275

7376
.. versionchanged:: 3.3 Added the *policy* keyword.
7477

@@ -113,17 +116,20 @@ have the same API as the :class:`Parser` and :class:`BytesParser` classes.
113116
The BytesHeaderParser class.
114117

115118

116-
.. class:: Parser(_class=email.message.Message, *, policy=policy.default)
119+
.. class:: Parser(_class=email.message.Message, *, policy=policy.compat32)
117120

118121
The constructor for the :class:`Parser` class takes an optional argument
119122
*_class*. This must be a callable factory (such as a function or a class), and
120123
it is used whenever a sub-message object needs to be created. It defaults to
121124
:class:`~email.message.Message` (see :mod:`email.message`). The factory will
122125
be called without arguments.
123126

124-
The *policy* keyword specifies a :mod:`~email.policy` object that controls a
125-
number of aspects of the parser's operation. The default policy maintains
126-
backward compatibility.
127+
If *policy* is specified (it must be an instance of a :mod:`~email.policy`
128+
class) use the rules it specifies to udpate the representation of the
129+
message. If *policy* is not set, use the :class:`compat32
130+
<email.policy.Compat32>` policy, which maintains backward compatibility with
131+
the Python 3.2 version of the email package. For more information see the
132+
:mod:`~email.policy` documentation.
127133

128134
.. versionchanged:: 3.3
129135
Removed the *strict* argument that was deprecated in 2.4. Added the
@@ -159,15 +165,18 @@ have the same API as the :class:`Parser` and :class:`BytesParser` classes.
159165
Optional *headersonly* is as with the :meth:`parse` method.
160166

161167

162-
.. class:: BytesParser(_class=email.message.Message, *, policy=policy.default)
168+
.. class:: BytesParser(_class=email.message.Message, *, policy=policy.compat32)
163169

164170
This class is exactly parallel to :class:`Parser`, but handles bytes input.
165171
The *_class* and *strict* arguments are interpreted in the same way as for
166172
the :class:`Parser` constructor.
167173

168-
The *policy* keyword specifies a :mod:`~email.policy` object that
169-
controls a number of aspects of the parser's operation. The default
170-
policy maintains backward compatibility.
174+
If *policy* is specified (it must be an instance of a :mod:`~email.policy`
175+
class) use the rules it specifies to udpate the representation of the
176+
message. If *policy* is not set, use the :class:`compat32
177+
<email.policy.Compat32>` policy, which maintains backward compatibility with
178+
the Python 3.2 version of the email package. For more information see the
179+
:mod:`~email.policy` documentation.
171180

172181
.. versionchanged:: 3.3
173182
Removed the *strict* argument. Added the *policy* keyword.
@@ -209,7 +218,7 @@ in the top-level :mod:`email` package namespace.
209218
.. currentmodule:: email
210219

211220
.. function:: message_from_string(s, _class=email.message.Message, *, \
212-
policy=policy.default)
221+
policy=policy.compat32)
213222

214223
Return a message object structure from a string. This is exactly equivalent to
215224
``Parser().parsestr(s)``. *_class* and *policy* are interpreted as
@@ -219,7 +228,7 @@ in the top-level :mod:`email` package namespace.
219228
Removed the *strict* argument. Added the *policy* keyword.
220229

221230
.. function:: message_from_bytes(s, _class=email.message.Message, *, \
222-
policy=policy.default)
231+
policy=policy.compat32)
223232

224233
Return a message object structure from a byte string. This is exactly
225234
equivalent to ``BytesParser().parsebytes(s)``. Optional *_class* and
@@ -231,7 +240,7 @@ in the top-level :mod:`email` package namespace.
231240
Removed the *strict* argument. Added the *policy* keyword.
232241

233242
.. function:: message_from_file(fp, _class=email.message.Message, *, \
234-
policy=policy.default)
243+
policy=policy.compat32)
235244

236245
Return a message object structure tree from an open :term:`file object`.
237246
This is exactly equivalent to ``Parser().parse(fp)``. *_class*
@@ -242,7 +251,7 @@ in the top-level :mod:`email` package namespace.
242251
Removed the *strict* argument. Added the *policy* keyword.
243252

244253
.. function:: message_from_binary_file(fp, _class=email.message.Message, *, \
245-
policy=policy.default)
254+
policy=policy.compat32)
246255

247256
Return a message object structure tree from an open binary :term:`file
248257
object`. This is exactly equivalent to ``BytesParser().parse(fp)``.

Lib/email/generator.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ def __init__(self, outfp, mangle_from_=True, maxheaderlen=None, *,
5151
by RFC 2822.
5252
5353
The policy keyword specifies a policy object that controls a number of
54-
aspects of the generator's operation. The default policy maintains
55-
backward compatibility.
54+
aspects of the generator's operation. If no policy is specified,
55+
the policy associated with the Message object passed to the
56+
flatten method is used.
5657
5758
"""
5859
self._fp = outfp
@@ -76,7 +77,9 @@ def flatten(self, msg, unixfrom=False, linesep=None):
7677
Note that for subobjects, no From_ line is printed.
7778
7879
linesep specifies the characters used to indicate a new line in
79-
the output. The default value is determined by the policy.
80+
the output. The default value is determined by the policy specified
81+
when the Generator instance was created or, if none was specified,
82+
from the policy associated with the msg.
8083
8184
"""
8285
# We use the _XXX constants for operating on data that comes directly

0 commit comments

Comments
 (0)