[docs] Docs bug for email.message

Aaron Burrow burrows at preveil.com
Fri Jun 17 11:28:58 EDT 2016


>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)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20160617/1e5f13f1/attachment.html>


More information about the docs mailing list