Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Doc/library/email.parser.rst

    r2 r391  
    1 :mod:`email`: Parsing email messages
    2 ------------------------------------
     1:mod:`email.parser`: Parsing email messages
     2-------------------------------------------
    33
    44.. module:: email.parser
     
    88Message object structures can be created in one of two ways: they can be created
    99from whole cloth by instantiating :class:`~email.message.Message` objects and
    10 stringing them together via :meth:`attach` and :meth:`set_payload` calls, or they
     10stringing them together via :meth:`~email.message.Message.attach` and
     11:meth:`~email.message.Message.set_payload` calls, or they
    1112can be created by parsing a flat text representation of the email message.
    1213
     
    1718non-MIME messages the payload of this root object will likely be a string
    1819containing the text of the message.  For MIME messages, the root object will
    19 return ``True`` from its :meth:`is_multipart` method, and the subparts can be
    20 accessed via the :meth:`get_payload` and :meth:`walk` methods.
     20return ``True`` from its :meth:`~email.message.Message.is_multipart` method, and
     21the subparts can be accessed via the :meth:`~email.message.Message.get_payload`
     22and :meth:`~email.message.Message.walk` methods.
    2123
    2224There are actually two parser interfaces available for use, the classic
     
    128130      Read all the data from the file-like object *fp*, parse the resulting
    129131      text, and return the root message object.  *fp* must support both the
    130       :meth:`readline` and the :meth:`read` methods on file-like objects.
     132      :meth:`~io.TextIOBase.readline` and the :meth:`~io.TextIOBase.read`
     133      methods on file-like objects.
    131134
    132135      The text contained in *fp* must be formatted as a block of :rfc:`2822`
     
    136139      message (which may contain MIME-encoded subparts).
    137140
    138       Optional *headersonly* is as with the :meth:`parse` method.
    139 
    140       .. versionchanged:: 2.2.2
    141          The *headersonly* flag was added.
    142 
    143 
    144    .. method:: parsestr(text[, headersonly])
    145 
    146       Similar to the :meth:`parse` method, except it takes a string object
    147       instead of a file-like object.  Calling this method on a string is exactly
    148       equivalent to wrapping *text* in a :class:`StringIO` instance first and
    149       calling :meth:`parse`.
    150 
    151141      Optional *headersonly* is a flag specifying whether to stop parsing after
    152142      reading the headers or not.  The default is ``False``, meaning it parses
     
    156146         The *headersonly* flag was added.
    157147
     148
     149   .. method:: parsestr(text[, headersonly])
     150
     151      Similar to the :meth:`parse` method, except it takes a string object
     152      instead of a file-like object.  Calling this method on a string is exactly
     153      equivalent to wrapping *text* in a :class:`~StringIO.StringIO` instance first and
     154      calling :meth:`parse`.
     155
     156      Optional *headersonly* is as with the :meth:`parse` method.
     157
     158      .. versionchanged:: 2.2.2
     159         The *headersonly* flag was added.
     160
    158161Since creating a message object structure from a string or a file object is such
    159162a common task, two functions are provided as a convenience.  They are available
     
    166169   Return a message object structure from a string.  This is exactly equivalent to
    167170   ``Parser().parsestr(s)``.  Optional *_class* and *strict* are interpreted as
    168    with the :class:`Parser` class constructor.
     171   with the :class:`~email.parser.Parser` class constructor.
    169172
    170173   .. versionchanged:: 2.2.2
     
    176179   Return a message object structure tree from an open file object.  This is
    177180   exactly equivalent to ``Parser().parse(fp)``.  Optional *_class* and *strict*
    178    are interpreted as with the :class:`Parser` class constructor.
     181   are interpreted as with the :class:`~email.parser.Parser` class constructor.
    179182
    180183   .. versionchanged:: 2.2.2
     
    194197* Most non-\ :mimetype:`multipart` type messages are parsed as a single message
    195198  object with a string payload.  These objects will return ``False`` for
    196   :meth:`is_multipart`.  Their :meth:`get_payload` method will return a string
    197   object.
     199  :meth:`~email.message.Message.is_multipart`.  Their
     200  :meth:`~email.message.Message.get_payload` method will return a string object.
    198201
    199202* All :mimetype:`multipart` type messages will be parsed as a container message
    200203  object with a list of sub-message objects for their payload.  The outer
    201   container message will return ``True`` for :meth:`is_multipart` and their
    202   :meth:`get_payload` method will return the list of :class:`~email.message.Message`
    203   subparts.
     204  container message will return ``True`` for
     205  :meth:`~email.message.Message.is_multipart` and their
     206  :meth:`~email.message.Message.get_payload` method will return the list of
     207  :class:`~email.message.Message` subparts.
    204208
    205209* Most messages with a content type of :mimetype:`message/\*` (e.g.
    206210  :mimetype:`message/delivery-status` and :mimetype:`message/rfc822`) will also be
    207211  parsed as container object containing a list payload of length 1.  Their
    208   :meth:`is_multipart` method will return ``True``.  The single element in the
    209   list payload will be a sub-message object.
     212  :meth:`~email.message.Message.is_multipart` method will return ``True``.
     213  The single element in the list payload will be a sub-message object.
    210214
    211215* Some non-standards compliant messages may not be internally consistent about
    212216  their :mimetype:`multipart`\ -edness.  Such messages may have a
    213217  :mailheader:`Content-Type` header of type :mimetype:`multipart`, but their
    214   :meth:`is_multipart` method may return ``False``.  If such messages were parsed
    215   with the :class:`FeedParser`, they will have an instance of the
    216   :class:`MultipartInvariantViolationDefect` class in their *defects* attribute
    217   list.  See :mod:`email.errors` for details.
     218  :meth:`~email.message.Message.is_multipart` method may return ``False``.
     219  If such messages were parsed with the :class:`~email.parser.FeedParser`,
     220  they will have an instance of the
     221  :class:`~email.errors.MultipartInvariantViolationDefect` class in their
     222  *defects* attribute list.  See :mod:`email.errors` for details.
    218223
    219224.. rubric:: Footnotes
    220225
    221226.. [#] As of email package version 3.0, introduced in Python 2.4, the classic
    222    :class:`Parser` was re-implemented in terms of the :class:`FeedParser`, so the
    223    semantics and results are identical between the two parsers.
    224 
     227   :class:`~email.parser.Parser` was re-implemented in terms of the
     228   :class:`~email.parser.FeedParser`, so the semantics and results are
     229   identical between the two parsers.
     230
Note: See TracChangeset for help on using the changeset viewer.