[Python-checkins] python/dist/src/Lib/email Parser.py,1.20.4.3,1.20.4.4

anthonybaxter@users.sourceforge.net anthonybaxter@users.sourceforge.net
Thu, 12 Jun 2003 02:14:21 -0700


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

Modified Files:
      Tag: anthony-parser-branch
	Parser.py 
Log Message:
preamble is None when missing, not ''. 
Handle a couple of bogus formatted messages - now parses my main testsuite.
Handle message/external-body.


Index: Parser.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/email/Parser.py,v
retrieving revision 1.20.4.3
retrieving revision 1.20.4.4
diff -C2 -d -r1.20.4.3 -r1.20.4.4
*** Parser.py	12 Jun 2003 07:16:40 -0000	1.20.4.3
--- Parser.py	12 Jun 2003 09:14:17 -0000	1.20.4.4
***************
*** 231,235 ****
                  container.set_payload(preamble)
                  return container
!             container.preamble = preamble
              while 1:
                  subobj = self._class()
--- 231,239 ----
                  container.set_payload(preamble)
                  return container
!             if preamble:
!                 container.preamble = preamble
!             else:
!                 # The module docs specify an empty preamble is None, not ''
!                 container.preamble = None
              while 1:
                  subobj = self._class()
***************
*** 251,255 ****
                  hassubparts = (subobj.get_content_maintype() in 
                                                  ( "message", "multipart" ))
-                 rfc822 = (subobj.get_content_type() == "message/rfc822")
                  if hassubparts:
                      subobj = self._parsemessage(subobj, fp)
--- 255,258 ----
***************
*** 267,276 ****
                  if trailer:
                      self._attach_trailer(subobj, trailer)
!                 if matchobj.group('end'):
                      # That was the last piece of data. Let our caller attach
                      # the epilogue to us. But before we do that, push the
                      # line ending of the match group back into the readline
                      # buffer, as it's part of the epilogue.
!                     fp.unreadline(matchobj.group('linesep'))
                      return container
  
--- 270,280 ----
                  if trailer:
                      self._attach_trailer(subobj, trailer)
!                 if matchobj is None or matchobj.group('end'):
                      # That was the last piece of data. Let our caller attach
                      # the epilogue to us. But before we do that, push the
                      # line ending of the match group back into the readline
                      # buffer, as it's part of the epilogue.
!                     if matchobj:
!                         fp.unreadline(matchobj.group('linesep'))
                      return container
  
***************
*** 282,286 ****
              ct = container.get_content_type()
              if ct == "message/rfc822":
-                 # Error.
                  submessage = self._class()
                  self._parseheaders(submessage, fp)
--- 286,289 ----
***************
*** 302,306 ****
                  return container
              else:
!                 raise ValueError, "%s not implemented yet"%(ct)
          else:
              # single body section. We let our caller set the payload.
--- 305,313 ----
                  return container
              else:
!                 # Other sort of message object (e.g. external-body)
!                 msg = self._class()
!                 self._parsemessage(msg, fp)
!                 container.attach(msg)
!                 return msg
          else:
              # single body section. We let our caller set the payload.