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/Lib/email/generator.py

    r2 r391  
    1 # Copyright (C) 2001-2006 Python Software Foundation
    2 # Author: Barry Warsaw
     1# Copyright (C) 2001-2010 Python Software Foundation
    32# Contact: email-sig@python.org
    43
     
    158157                print >> self._fp, v
    159158            else:
    160                 # Header's got lots of smarts, so use it.
     159                # Header's got lots of smarts, so use it.  Note that this is
     160                # fundamentally broken though because we lose idempotency when
     161                # the header string is continued with tabs.  It will now be
     162                # continued with spaces.  This was reversedly broken before we
     163                # fixed bug 1974.  Either way, we lose.
    161164                print >> self._fp, Header(
    162                     v, maxlinelen=self._maxheaderlen,
    163                     header_name=h, continuation_ws='\t').encode()
     165                    v, maxlinelen=self._maxheaderlen, header_name=h).encode()
    164166        # A blank line always separates headers from body
    165167        print >> self._fp
     
    202204            g.flatten(part, unixfrom=False)
    203205            msgtexts.append(s.getvalue())
    204         # Now make sure the boundary we've selected doesn't appear in any of
    205         # the message texts.
    206         alltext = NL.join(msgtexts)
    207206        # BAW: What about boundaries that are wrapped in double-quotes?
    208         boundary = msg.get_boundary(failobj=_make_boundary(alltext))
    209         # If we had to calculate a new boundary because the body text
    210         # contained that string, set the new boundary.  We don't do it
    211         # unconditionally because, while set_boundary() preserves order, it
    212         # doesn't preserve newlines/continuations in headers.  This is no big
    213         # deal in practice, but turns out to be inconvenient for the unittest
    214         # suite.
    215         if msg.get_boundary() != boundary:
     207        boundary = msg.get_boundary()
     208        if not boundary:
     209            # Create a boundary that doesn't appear in any of the
     210            # message texts.
     211            alltext = NL.join(msgtexts)
     212            boundary = _make_boundary(alltext)
    216213            msg.set_boundary(boundary)
    217214        # If there's a preamble, write it out, with a trailing CRLF
    218215        if msg.preamble is not None:
    219             print >> self._fp, msg.preamble
     216            if self._mangle_from_:
     217                preamble = fcre.sub('>From ', msg.preamble)
     218            else:
     219                preamble = msg.preamble
     220            print >> self._fp, preamble
    220221        # dash-boundary transport-padding CRLF
    221222        print >> self._fp, '--' + boundary
     
    235236        if msg.epilogue is not None:
    236237            print >> self._fp
    237             self._fp.write(msg.epilogue)
     238            if self._mangle_from_:
     239                epilogue = fcre.sub('>From ', msg.epilogue)
     240            else:
     241                epilogue = msg.epilogue
     242            self._fp.write(epilogue)
    238243
    239244    def _handle_multipart_signed(self, msg):
     
    293298
    294299class DecodedGenerator(Generator):
    295     """Generator a text representation of a message.
     300    """Generates a text representation of a message.
    296301
    297302    Like the Generator base class, except that non-text parts are substituted
Note: See TracChangeset for help on using the changeset viewer.