[Python-checkins] python/dist/src/Lib/email Generator.py,1.10,1.11

bwarsaw@users.sourceforge.net bwarsaw@users.sourceforge.net
Mon, 08 Jul 2002 19:43:49 -0700


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

Modified Files:
	Generator.py 
Log Message:
clone(): A new method for creating a clone of this generator (for
recursive generation).

_dispatch(): If the message object doesn't have a Content-Type:
header, check its default type instead of assuming it's text/plain.
This makes for correct generation of message/rfc822 containers.

_handle_multipart(): We can get rid of the isdigest kludge.  Just
print the message as normal and everything will work out correctly.

_handle_mulitpart_digest(): We don't need this anymore either.


Index: Generator.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/email/Generator.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** Generator.py	28 Jun 2002 23:41:42 -0000	1.10
--- Generator.py	9 Jul 2002 02:43:47 -0000	1.11
***************
*** 84,87 ****
--- 84,91 ----
      __call__ = flatten
  
+     def clone(self, fp):
+         """Clone this generator with the exact same options."""
+         return self.__class__(fp, self._mangle_from_, self.__maxheaderlen)
+ 
      #
      # Protected interface - undocumented ;/
***************
*** 122,137 ****
          ctype = msg.get_type()
          if ctype is None:
!             # No Content-Type: header so try the default handler
!             self._writeBody(msg)
!         else:
!             # We do have a Content-Type: header.
!             specific = UNDERSCORE.join(ctype.split('/')).replace('-', '_')
!             meth = getattr(self, '_handle_' + specific, None)
              if meth is None:
!                 generic = msg.get_main_type().replace('-', '_')
!                 meth = getattr(self, '_handle_' + generic, None)
!                 if meth is None:
!                     meth = self._writeBody
!             meth(msg)
  
      #
--- 126,143 ----
          ctype = msg.get_type()
          if ctype is None:
!             # No Content-Type: header so use the default type, which must be
!             # either text/plain or message/rfc822.
!             ctype = msg.get_default_type()
!             assert ctype in ('text/plain', 'message/rfc822')
!         # We do have a Content-Type: header.
!         main, sub = ctype.split('/')
!         specific = UNDERSCORE.join((main, sub)).replace('-', '_')
!         meth = getattr(self, '_handle_' + specific, None)
!         if meth is None:
!             generic = main.replace('-', '_')
!             meth = getattr(self, '_handle_' + generic, None)
              if meth is None:
!                 meth = self._writeBody
!         meth(msg)
  
      #
***************
*** 197,201 ****
      _writeBody = _handle_text
  
!     def _handle_multipart(self, msg, isdigest=0):
          # The trick here is to write out each part separately, merge them all
          # together, and then make sure that the boundary we've chosen isn't
--- 203,207 ----
      _writeBody = _handle_text
  
!     def _handle_multipart(self, msg):
          # The trick here is to write out each part separately, merge them all
          # together, and then make sure that the boundary we've chosen isn't
***************
*** 204,208 ****
          subparts = msg.get_payload()
          if subparts is None:
!             # Nothing has every been attached
              boundary = msg.get_boundary(failobj=_make_boundary())
              print >> self._fp, '--' + boundary
--- 210,214 ----
          subparts = msg.get_payload()
          if subparts is None:
!             # Nothing has ever been attached
              boundary = msg.get_boundary(failobj=_make_boundary())
              print >> self._fp, '--' + boundary
***************
*** 215,219 ****
          for part in subparts:
              s = StringIO()
!             g = self.__class__(s, self._mangle_from_, self.__maxheaderlen)
              g.flatten(part, unixfrom=0)
              msgtexts.append(s.getvalue())
--- 221,225 ----
          for part in subparts:
              s = StringIO()
!             g = self.clone(s)
              g.flatten(part, unixfrom=0)
              msgtexts.append(s.getvalue())
***************
*** 237,248 ****
          # newline.
          print >> self._fp, '--' + boundary
-         if isdigest:
-             print >> self._fp
          # Join and write the individual parts
          joiner = '\n--' + boundary + '\n'
-         if isdigest:
-             # multipart/digest types effectively add an extra newline between
-             # the boundary and the body part.
-             joiner += '\n'
          self._fp.write(joiner.join(msgtexts))
          print >> self._fp, '\n--' + boundary + '--',
--- 243,248 ----
***************
*** 253,259 ****
              self._fp.write(msg.epilogue)
  
-     def _handle_multipart_digest(self, msg):
-         self._handle_multipart(msg, isdigest=1)
- 
      def _handle_message_delivery_status(self, msg):
          # We can't just write the headers directly to self's file object
--- 253,256 ----
***************
*** 263,267 ****
          for part in msg.get_payload():
              s = StringIO()
!             g = self.__class__(s, self._mangle_from_, self.__maxheaderlen)
              g.flatten(part, unixfrom=0)
              text = s.getvalue()
--- 260,264 ----
          for part in msg.get_payload():
              s = StringIO()
!             g = self.clone(s)
              g.flatten(part, unixfrom=0)
              text = s.getvalue()
***************
*** 279,287 ****
      def _handle_message(self, msg):
          s = StringIO()
!         g = self.__class__(s, self._mangle_from_, self.__maxheaderlen)
          # The payload of a message/rfc822 part should be a multipart sequence
          # of length 1.  The zeroth element of the list should be the Message
!         # object for the subpart.Extract that object, stringify it, and write
!         # that out.
          g.flatten(msg.get_payload(0), unixfrom=0)
          self._fp.write(s.getvalue())
--- 276,284 ----
      def _handle_message(self, msg):
          s = StringIO()
!         g = self.clone(s)
          # The payload of a message/rfc822 part should be a multipart sequence
          # of length 1.  The zeroth element of the list should be the Message
!         # object for the subpart.  Extract that object, stringify it, and
!         # write it out.
          g.flatten(msg.get_payload(0), unixfrom=0)
          self._fp.write(s.getvalue())