| LEFT | RIGHT |
| 1 :mod:`email`: Parsing email messages | 1 :mod:`email`: Parsing email messages |
| 2 ------------------------------------ | 2 ------------------------------------ |
| 3 | 3 |
| 4 .. module:: email.parser | 4 .. module:: email.parser |
| 5 :synopsis: Parse flat text email messages to produce a message object structu
re. | 5 :synopsis: Parse flat text email messages to produce a message object structu
re. |
| 6 | 6 |
| 7 | 7 |
| 8 Message object structures can be created in one of two ways: they can be created | 8 Message object structures can be created in one of two ways: they can be created |
| 9 from whole cloth by instantiating :class:`~email.message.Message` objects and | 9 from whole cloth by instantiating :class:`~email.message.Message` objects and |
| 10 stringing them together via :meth:`attach` and :meth:`set_payload` calls, or the
y | 10 stringing them together via :meth:`attach` and :meth:`set_payload` calls, or the
y |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 Read all the data from the binary file-like object *fp*, parse the | 160 Read all the data from the binary file-like object *fp*, parse the |
| 161 resulting bytes, and return the message object. *fp* must support | 161 resulting bytes, and return the message object. *fp* must support |
| 162 both the :meth:`readline` and the :meth:`read` methods on file-like | 162 both the :meth:`readline` and the :meth:`read` methods on file-like |
| 163 objects. | 163 objects. |
| 164 | 164 |
| 165 The bytes contained in *fp* must be formatted as a block of :rfc:`2822` | 165 The bytes contained in *fp* must be formatted as a block of :rfc:`2822` |
| 166 style headers and header continuation lines, optionally preceded by a | 166 style headers and header continuation lines, optionally preceded by a |
| 167 envelope header. The header block is terminated either by the end of the | 167 envelope header. The header block is terminated either by the end of the |
| 168 data or by a blank line. Following the header block is the body of the | 168 data or by a blank line. Following the header block is the body of the |
| 169 message (which may contain MIME-encoded subparts, including subparts | 169 message (which may contain MIME-encoded subparts, including subparts |
| 170 with a :mailheader:`ContentTransferEncoding` of ``8bit``. | 170 with a :mailheader:`Content-Transfer-Encoding` of ``8bit``. |
| 171 | 171 |
| 172 Optional *headersonly* is a flag specifying whether to stop parsing after | 172 Optional *headersonly* is a flag specifying whether to stop parsing after |
| 173 reading the headers or not. The default is ``False``, meaning it parses | 173 reading the headers or not. The default is ``False``, meaning it parses |
| 174 the entire contents of the file. | 174 the entire contents of the file. |
| 175 | 175 |
| 176 .. method:: parsebytes(bytes, headersonly=False) | 176 .. method:: parsebytes(bytes, headersonly=False) |
| 177 | 177 |
| 178 Similar to the :meth:`parse` method, except it takes a byte string object | 178 Similar to the :meth:`parse` method, except it takes a byte string object |
| 179 instead of a file-like object. Calling this method on a byte string is | 179 instead of a file-like object. Calling this method on a byte string is |
| 180 exactly equivalent to wrapping *text* in a :class:`BytesIO` instance | 180 exactly equivalent to wrapping *text* in a :class:`BytesIO` instance |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 with the :class:`FeedParser`, they will have an instance of the | 255 with the :class:`FeedParser`, they will have an instance of the |
| 256 :class:`MultipartInvariantViolationDefect` class in their *defects* attribute | 256 :class:`MultipartInvariantViolationDefect` class in their *defects* attribute |
| 257 list. See :mod:`email.errors` for details. | 257 list. See :mod:`email.errors` for details. |
| 258 | 258 |
| 259 .. rubric:: Footnotes | 259 .. rubric:: Footnotes |
| 260 | 260 |
| 261 .. [#] As of email package version 3.0, introduced in Python 2.4, the classic | 261 .. [#] As of email package version 3.0, introduced in Python 2.4, the classic |
| 262 :class:`Parser` was re-implemented in terms of the :class:`FeedParser`, so th
e | 262 :class:`Parser` was re-implemented in terms of the :class:`FeedParser`, so th
e |
| 263 semantics and results are identical between the two parsers. | 263 semantics and results are identical between the two parsers. |
| 264 | 264 |
| LEFT | RIGHT |