[Python-checkins] python/dist/src/Lib/email Generator.py,1.22,1.23

bwarsaw at users.sourceforge.net bwarsaw at users.sourceforge.net
Sat May 8 23:35:19 EDT 2004


Update of /cvsroot/python/python/dist/src/Lib/email
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11939

Modified Files:
	Generator.py 
Log Message:
Update to Python 2.3, getting rid of backward compatiblity crud.  Get rid of a
bunch of module globals that aren't used.

__maxheaderlen -> _maxheaderlen

_handle_multipart(): This should be more RFC compliant now, and does match the
updated/fixed semantics for preamble and epilogue.


Index: Generator.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/email/Generator.py,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** Generator.py	19 Nov 2003 02:23:01 -0000	1.22
--- Generator.py	9 May 2004 03:35:17 -0000	1.23
***************
*** 1,4 ****
! # Copyright (C) 2001,2002 Python Software Foundation
! # Author: barry at zope.com (Barry Warsaw)
  
  """Classes to generate plain text from a message object tree.
--- 1,4 ----
! # Copyright (C) 2001-2004 Python Software Foundation
! # Author: barry at python.org (Barry Warsaw)
  
  """Classes to generate plain text from a message object tree.
***************
*** 8,44 ****
  import sys
  import time
- import locale
  import random
- 
- from types import ListType, StringType
  from cStringIO import StringIO
  
  from email.Header import Header
- from email.Parser import NLCRE
  
- try:
-     from email._compat22 import _isstring
- except SyntaxError:
-     from email._compat21 import _isstring
- 
- try:
-     True, False
- except NameError:
-     True = 1
-     False = 0
- 
- EMPTYSTRING = ''
- SEMISPACE = '; '
- BAR = '|'
  UNDERSCORE = '_'
  NL = '\n'
- NLTAB = '\n\t'
- SEMINLTAB = ';\n\t'
- SPACE8 = ' ' * 8
  
  fcre = re.compile(r'^From ', re.MULTILINE)
  
  def _is8bitstring(s):
!     if isinstance(s, StringType):
          try:
              unicode(s, 'us-ascii')
--- 8,23 ----
  import sys
  import time
  import random
  from cStringIO import StringIO
  
  from email.Header import Header
  
  UNDERSCORE = '_'
  NL = '\n'
  
  fcre = re.compile(r'^From ', re.MULTILINE)
  
  def _is8bitstring(s):
!     if isinstance(s, str):
          try:
              unicode(s, 'us-ascii')
***************
*** 78,82 ****
          self._fp = outfp
          self._mangle_from_ = mangle_from_
!         self.__maxheaderlen = maxheaderlen
  
      def write(self, s):
--- 57,61 ----
          self._fp = outfp
          self._mangle_from_ = mangle_from_
!         self._maxheaderlen = maxheaderlen
  
      def write(self, s):
***************
*** 107,111 ****
      def clone(self, fp):
          """Clone this generator with the exact same options."""
!         return self.__class__(fp, self._mangle_from_, self.__maxheaderlen)
  
      #
--- 86,90 ----
      def clone(self, fp):
          """Clone this generator with the exact same options."""
!         return self.__class__(fp, self._mangle_from_, self._maxheaderlen)
  
      #
***************
*** 163,167 ****
          for h, v in msg.items():
              print >> self._fp, '%s:' % h,
!             if self.__maxheaderlen == 0:
                  # Explicit no-wrapping
                  print >> self._fp, v
--- 142,146 ----
          for h, v in msg.items():
              print >> self._fp, '%s:' % h,
!             if self._maxheaderlen == 0:
                  # Explicit no-wrapping
                  print >> self._fp, v
***************
*** 180,184 ****
                  # Header's got lots of smarts, so use it.
                  print >> self._fp, Header(
!                     v, maxlinelen=self.__maxheaderlen,
                      header_name=h, continuation_ws='\t').encode()
          # A blank line always separates headers from body
--- 159,163 ----
                  # Header's got lots of smarts, so use it.
                  print >> self._fp, Header(
!                     v, maxlinelen=self._maxheaderlen,
                      header_name=h, continuation_ws='\t').encode()
          # A blank line always separates headers from body
***************
*** 196,200 ****
          if cset is not None:
              payload = cset.body_encode(payload)
!         if not _isstring(payload):
              raise TypeError, 'string payload expected: %s' % type(payload)
          if self._mangle_from_:
--- 175,179 ----
          if cset is not None:
              payload = cset.body_encode(payload)
!         if not isinstance(payload, basestring):
              raise TypeError, 'string payload expected: %s' % type(payload)
          if self._mangle_from_:
***************
*** 212,226 ****
          subparts = msg.get_payload()
          if subparts is None:
!             # Nothing has ever been attached
!             boundary = msg.get_boundary(failobj=_make_boundary())
!             print >> self._fp, '--' + boundary
!             print >> self._fp, '\n'
!             print >> self._fp, '--' + boundary + '--'
!             return
!         elif _isstring(subparts):
              # e.g. a non-strict parse of a message with no starting boundary.
              self._fp.write(subparts)
              return
!         elif not isinstance(subparts, ListType):
              # Scalar payload
              subparts = [subparts]
--- 191,200 ----
          subparts = msg.get_payload()
          if subparts is None:
!             subparts = []
!         elif isinstance(subparts, basestring):
              # e.g. a non-strict parse of a message with no starting boundary.
              self._fp.write(subparts)
              return
!         elif not isinstance(subparts, list):
              # Scalar payload
              subparts = [subparts]
***************
*** 243,268 ****
          if msg.get_boundary() <> boundary:
              msg.set_boundary(boundary)
!         # Write out any preamble
          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.
          print >> self._fp, '--' + boundary
!         # Join and write the individual parts
!         joiner = '\n--' + boundary + '\n'
!         self._fp.write(joiner.join(msgtexts))
!         print >> self._fp, '\n--' + boundary + '--',
!         # Write out any epilogue
          if msg.epilogue is not None:
!             if not msg.epilogue.startswith('\n'):
!                 print >> self._fp
              self._fp.write(msg.epilogue)
  
--- 217,240 ----
          if msg.get_boundary() <> boundary:
              msg.set_boundary(boundary)
!         # If there's a preamble, write it out, with a trailing CRLF
          if msg.preamble is not None:
!             print >> self._fp, msg.preamble
!         # dash-boundary transport-padding CRLF
          print >> self._fp, '--' + boundary
!         # body-part
!         if msgtexts:
!             self._fp.write(msgtexts.pop(0))
!         # *encapsulation
!         # --> delimiter transport-padding
!         # --> CRLF body-part
!         for body_part in msgtexts:
!             # delimiter transport-padding CRLF
!             print >> self._fp, '\n--' + boundary
!             # body-part
!             self._fp.write(body_part)
!         # close-delimiter transport-padding
!         self._fp.write('\n--' + boundary + '--')
          if msg.epilogue is not None:
!             print >> self._fp
              self._fp.write(msg.epilogue)
  




More information about the Python-checkins mailing list