[docs] Docs bug for email.message

Berker Peksağ berker.peksag at gmail.com
Fri Jun 17 15:57:53 EDT 2016


On Fri, Jun 17, 2016 at 6:28 PM, Aaron Burrow <burrows at preveil.com> wrote:
> From this link,
> https://docs.python.org/2/library/email.message.html#email.message.Message.__str__
>
> __str__()
>
>   Equivalent to as_string(unixfrom=True).
>
>
> Looking at the source for the Message class.
>
>
> class Message:
>
>     def __str__(self):
>
>         """Return the entire formatted message as a string.
>
>         This includes the headers, body, and envelope header.
>
>         """
>
>         return self.as_string()
>
>     def as_string(self, unixfrom=False, maxheaderlen=0):
>
>         """Return the entire formatted message as a string.
>
>         Optional `unixfrom' when True, means include the Unix From_ envelope
>
>         header.
>
>
>         This is a convenience method and may not generate the message
> exactly
>
>         as you intend.  For more flexibility, use the flatten() method of a
>
>         Generator instance.
>
>         """
>
>         from email.generator import Generator
>
>         fp = StringIO()
>
>         g = Generator(fp, mangle_from_=False, maxheaderlen=maxheaderlen)
>
>         g.flatten(self, unixfrom=unixfrom)
>
>         return fp.getvalue()
>
>
> __str__ is actually equivalent to Message.as_string(unixfrom=False)

Hi Aaron,

I think you are looking at Python 3 version of the code. The
documentation is correct:
https://hg.python.org/cpython/file/2.7/Lib/email/message.py#l122

--Berker


More information about the docs mailing list