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

Skip to content

Commit 6a45d3b

Browse files
committed
Markup and text fixes from Georg Brandl's review.
1 parent 1f056b2 commit 6a45d3b

2 files changed

Lines changed: 36 additions & 28 deletions

File tree

Doc/library/email.parser.rst

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,16 +211,19 @@ in the top-level :mod:`email` package namespace.
211211
``Parser().parsestr(s)``. *_class* and *policy* are interpreted as
212212
with the :class:`Parser` class constructor.
213213

214-
.. versionchanged:: removed *strict*, added *policy*
214+
.. versionchanged:: 3.3
215+
Removed the *strict* argument. Added the *policy* keyword.
215216

216-
.. function:: message_from_bytes(s, _class=email.message.Message, strict=None)
217+
.. function:: message_from_bytes(s, _class=email.message.Message, *, \
218+
policy=policy.default)
217219

218220
Return a message object structure from a byte string. This is exactly
219221
equivalent to ``BytesParser().parsebytes(s)``. Optional *_class* and
220222
*strict* are interpreted as with the :class:`Parser` class constructor.
221223

222224
.. versionadded:: 3.2
223-
.. versionchanged:: 3.3 removed *strict*, added *policy*
225+
.. versionchanged:: 3.3
226+
Removed the *strict* argument. Added the *policy* keyword.
224227

225228
.. function:: message_from_file(fp, _class=email.message.Message, *, \
226229
policy=policy.default)
@@ -229,7 +232,8 @@ in the top-level :mod:`email` package namespace.
229232
This is exactly equivalent to ``Parser().parse(fp)``. *_class*
230233
and *policy* are interpreted as with the :class:`Parser` class constructor.
231234

232-
.. versionchanged:: 3.3 removed *strict*, added *policy*
235+
.. versionchanged::
236+
Removed the *strict* argument. Added the *policy* keyword.
233237

234238
.. function:: message_from_binary_file(fp, _class=email.message.Message, *, \
235239
policy=policy.default)
@@ -240,7 +244,8 @@ in the top-level :mod:`email` package namespace.
240244
class constructor.
241245

242246
.. versionadded:: 3.2
243-
.. versionchanged:: 3.3 removed *strict*, added *policy*
247+
.. versionchanged:: 3.3
248+
Removed the *strict* argument. Added the *policy* keyword.
244249

245250
Here's an example of how you might use this at an interactive Python prompt::
246251

Doc/library/email.policy.rst

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
.. module:: email.policy
55
:synopsis: Controlling the parsing and generating of messages
66

7+
.. versionadded: 3.3
8+
79
810
The :mod:`email` package's prime focus is the handling of email messages as
911
described by the various email and MIME RFCs. However, the general format of
@@ -14,8 +16,8 @@ email. Some of these uses conform fairly closely to the main RFCs, some do
1416
not. And even when working with email, there are times when it is desirable to
1517
break strict compliance with the RFCs.
1618

17-
Policy objects are the mechanism used to provide the email package with the
18-
flexibility to handle all these disparate use cases,
19+
Policy objects give the email package the flexibility to handle all these
20+
disparate use cases.
1921

2022
A :class:`Policy` object encapsulates a set of attributes and methods that
2123
control the behavior of various components of the email package during use.
@@ -39,24 +41,23 @@ program will use the same :class:`Policy` for both input and output, the two
3941
can be different.
4042

4143
As an example, the following code could be used to read an email message from a
42-
file on disk and pass it to the system ``sendmail`` program on a ``unix``
43-
system::
44+
file on disk and pass it to the system ``sendmail`` program on a Unix system::
4445

4546
>>> from email import msg_from_binary_file
4647
>>> from email.generator import BytesGenerator
4748
>>> import email.policy
4849
>>> from subprocess import Popen, PIPE
4950
>>> with open('mymsg.txt', 'b') as f:
50-
>>> msg = msg_from_binary_file(f, policy=email.policy.mbox)
51+
... Msg = msg_from_binary_file(f, policy=email.policy.mbox)
5152
>>> p = Popen(['sendmail', msg['To'][0].address], stdin=PIPE)
52-
>>> g = BytesGenerator(p.stdin, email.policy.policy=SMTP)
53+
>>> g = BytesGenerator(p.stdin, policy=email.policy.SMTP)
5354
>>> g.flatten(msg)
5455
>>> p.stdin.close()
5556
>>> rc = p.wait()
5657

5758
Some email package methods accept a *policy* keyword argument, allowing the
58-
policy to be overridden for that method. For example, the following code use
59-
the :meth:`email.message.Message.as_string` method to the *msg* object from the
59+
policy to be overridden for that method. For example, the following code uses
60+
the :meth:`email.message.Message.as_string` method of the *msg* object from the
6061
previous example and re-write it to a file using the native line separators for
6162
the platform on which it is running::
6263

@@ -106,26 +107,28 @@ added matters. To illustrate::
106107
.. attribute:: linesep
107108

108109
The string to be used to terminate lines in serialized output. The
109-
default is '\\n' because that's the internal end-of-line discipline used
110-
by Python, though '\\r\\n' is required by the RFCs. See `Policy
110+
default is ``\n`` because that's the internal end-of-line discipline used
111+
by Python, though ``\r\n`` is required by the RFCs. See `Policy
111112
Instances`_ for policies that use an RFC conformant linesep. Setting it
112113
to :attr:`os.linesep` may also be useful.
113114

114115
.. attribute:: must_be_7bit
115116

116-
If :const:`True`, data output by a bytes generator is limited to ASCII
117+
If ``True``, data output by a bytes generator is limited to ASCII
117118
characters. If :const:`False` (the default), then bytes with the high
118119
bit set are preserved and/or allowed in certain contexts (for example,
119120
where possible a content transfer encoding of ``8bit`` will be used).
120-
String generators act as if ``must_be_7bit`` is `True` regardless of the
121-
policy in effect, since a string cannot represent non-ASCII bytes.
121+
String generators act as if ``must_be_7bit`` is ``True`` regardless of
122+
the policy in effect, since a string cannot represent non-ASCII bytes.
122123

123124
.. attribute:: raise_on_defect
124125

125126
If :const:`True`, any defects encountered will be raised as errors. If
126127
:const:`False` (the default), defects will be passed to the
127128
:meth:`register_defect` method.
128129

130+
:mod:`Policy` object also have the following methods:
131+
129132
.. method:: handle_defect(obj, defect)
130133

131134
*obj* is the object on which to register the defect. *defect* should be
@@ -145,35 +148,35 @@ added matters. To illustrate::
145148
handling of defects. The default implementation calls the ``append``
146149
method of the ``defects`` attribute of *obj*.
147150

148-
.. method:: clone(obj, *kw):
151+
.. method:: clone(obj, *kw)
149152

150153
Return a new :class:`Policy` instance whose attributes have the same
151154
values as the current instance, except where those attributes are
152155
given new values by the keyword arguments.
153156

154157

155158
Policy Instances
156-
................
159+
^^^^^^^^^^^^^^^^
157160

158161
The following instances of :class:`Policy` provide defaults suitable for
159162
specific common application domains.
160163

161164
.. data:: default
162165

163-
An instance of :class:`Policy` with all defaults unchanged.
166+
An instance of :class:`Policy` with all defaults unchanged.
164167

165168
.. data:: SMTP
166169

167-
Output serialized from a message will conform to the email and SMTP
168-
RFCs. The only changed attribute is :attr:`linesep`, which is set to
169-
``\r\n``.
170+
Output serialized from a message will conform to the email and SMTP
171+
RFCs. The only changed attribute is :attr:`linesep`, which is set to
172+
``\r\n``.
170173

171174
.. data:: HTTP
172175

173-
Suitable for use when serializing headers for use in HTTP traffic.
174-
:attr:`linesep` is set to ``\r\n``, and :attr:`max_line_length` is set to
175-
:const:`None` (unlimited).
176+
Suitable for use when serializing headers for use in HTTP traffic.
177+
:attr:`linesep` is set to ``\r\n``, and :attr:`max_line_length` is set to
178+
:const:`None` (unlimited).
176179

177180
.. data:: strict
178181

179-
:attr:`raise_on_defect` is set to :const:`True`.
182+
:attr:`raise_on_defect` is set to :const:`True`.

0 commit comments

Comments
 (0)