[Python-checkins] python/dist/src/Lib/email Generator.py,1.17,1.18

bwarsaw@users.sourceforge.net bwarsaw@users.sourceforge.net
Wed, 05 Mar 2003 21:22:05 -0800


Update of /cvsroot/python/python/dist/src/Lib/email
In directory sc8-pr-cvs1:/tmp/cvs-serv933

Modified Files:
	Generator.py 
Log Message:
Merge of the folding-reimpl-branch.  Specific changes,

_handle_multipart(): Ensure that if the preamble exists but does not
end in a newline, a newline is still added.  Without this, the
boundary separator will end up on the preamble line, breaking the MIME
structure.

_make_boundary(): Handle differences in the decimal point character
based on the locale.


Index: Generator.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/email/Generator.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** Generator.py	14 Oct 2002 15:09:30 -0000	1.17
--- Generator.py	6 Mar 2003 05:22:02 -0000	1.18
***************
*** 5,10 ****
  """
  
- import time
  import re
  import random
  
--- 5,11 ----
  """
  
  import re
+ import time
+ import locale
  import random
  
***************
*** 13,16 ****
--- 14,18 ----
  
  from email.Header import Header
+ from email.Parser import NLCRE
  
  try:
***************
*** 259,262 ****
--- 261,272 ----
          if msg.preamble is not None:
              self._fp.write(msg.preamble)
+             # If preamble is the empty string, the length of the split will be
+             # 1, but the last element will be the empty string.  If it's
+             # anything else but does not end in a line separator, the length
+             # will be > 1 and not end in an empty string.  We need to
+             # guarantee a newline after the preamble, but don't add too many.
+             plines = NLCRE.split(msg.preamble)
+             if plines <> [''] and plines[-1] <> '':
+                 self._fp.write('\n')
          # First boundary is a bit different; it doesn't have a leading extra
          # newline.
***************
*** 365,369 ****
      # Craft a random boundary.  If text is given, ensure that the chosen
      # boundary doesn't appear in the text.
!     boundary = ('=' * 15) + repr(random.random()).split('.')[1] + '=='
      if text is None:
          return boundary
--- 375,380 ----
      # Craft a random boundary.  If text is given, ensure that the chosen
      # boundary doesn't appear in the text.
!     dp = locale.localeconv().get('decimal_point', '.')
!     boundary = ('=' * 15) + repr(random.random()).split(dp)[1] + '=='
      if text is None:
          return boundary