[Python-checkins] python/dist/src/Lib/email _parseaddr.py,1.1,1.2

bwarsaw@users.sourceforge.net bwarsaw@users.sourceforge.net
Mon, 30 Dec 2002 08:21:10 -0800


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

Modified Files:
	_parseaddr.py 
Log Message:
Port rfc822.py changes that didn't make it into this copy,
specifically that dots are allowed in obs-phrase.  This fixes parsing
of dots in realnames.


Index: _parseaddr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/email/_parseaddr.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** _parseaddr.py	5 Nov 2002 19:54:52 -0000	1.1
--- _parseaddr.py	30 Dec 2002 16:21:07 -0000	1.2
***************
*** 136,141 ****
      """Address parser class by Ben Escoto.
  
!     To understand what this class does, it helps to have a copy of
!     RFC-822 in front of you.
  
      Note: this class interface is deprecated and may be removed in the future.
--- 136,141 ----
      """Address parser class by Ben Escoto.
  
!     To understand what this class does, it helps to have a copy of RFC 2822 in
!     front of you.
  
      Note: this class interface is deprecated and may be removed in the future.
***************
*** 154,157 ****
--- 154,161 ----
          self.CR = '\r\n'
          self.atomends = self.specials + self.LWS + self.CR
+         # Note that RFC 2822 now specifies `.' as obs-phrase, meaning that it
+         # is obsolete syntax.  RFC 2822 requires that we recognize obsolete
+         # syntax, so allow dots in phrases.
+         self.phraseends = self.atomends.replace('.', '')
          self.field = field
          self.commentlist = []
***************
*** 171,178 ****
          Returns a list containing all of the addresses.
          """
!         ad = self.getaddress()
!         if ad:
!             return ad + self.getaddrlist()
!         else: return []
  
      def getaddress(self):
--- 175,186 ----
          Returns a list containing all of the addresses.
          """
!         result = []
!         while 1:
!             ad = self.getaddress()
!             if ad:
!                 result += ad
!             else:
!                 break
!         return result
  
      def getaddress(self):
***************
*** 258,262 ****
              elif self.field[self.pos] == ':':
                  self.pos = self.pos + 1
-                 expectaddrspec = 1
              else:
                  adlist = self.getaddrspec()
--- 266,269 ----
***************
*** 268,272 ****
  
      def getaddrspec(self):
!         """Parse an RFC-822 addr-spec."""
          aslist = []
  
--- 275,279 ----
  
      def getaddrspec(self):
!         """Parse an RFC 2822 addr-spec."""
          aslist = []
  
***************
*** 319,324 ****
          Parsing stops when one of these is encountered.
  
!         If `allowcomments' is non-zero, embedded RFC-822 comments
!         are allowed within the parsed fragment.
          """
          if self.field[self.pos] != beginchar:
--- 326,331 ----
          Parsing stops when one of these is encountered.
  
!         If `allowcomments' is non-zero, embedded RFC 2822 comments are allowed
!         within the parsed fragment.
          """
          if self.field[self.pos] != beginchar:
***************
*** 354,366 ****
  
      def getdomainliteral(self):
!         """Parse an RFC-822 domain-literal."""
          return '[%s]' % self.getdelimited('[', ']\r', 0)
  
!     def getatom(self):
!         """Parse an RFC-822 atom."""
          atomlist = ['']
  
          while self.pos < len(self.field):
!             if self.field[self.pos] in self.atomends:
                  break
              else: atomlist.append(self.field[self.pos])
--- 361,380 ----
  
      def getdomainliteral(self):
!         """Parse an RFC 2822 domain-literal."""
          return '[%s]' % self.getdelimited('[', ']\r', 0)
  
!     def getatom(self, atomends=None):
!         """Parse an RFC 2822 atom.
! 
!         Optional atomends specifies a different set of end token delimiters
!         (the default is to use self.atomends).  This is used e.g. in
!         getphraselist() since phrase endings must not include the `.' (which
!         is legal in phrases)."""
          atomlist = ['']
+         if atomends is None:
+             atomends = self.atomends
  
          while self.pos < len(self.field):
!             if self.field[self.pos] in atomends:
                  break
              else: atomlist.append(self.field[self.pos])
***************
*** 370,378 ****
  
      def getphraselist(self):
!         """Parse a sequence of RFC-822 phrases.
  
!         A phrase is a sequence of words, which are in turn either
!         RFC-822 atoms or quoted-strings.  Phrases are canonicalized
!         by squeezing all runs of continuous whitespace into one space.
          """
          plist = []
--- 384,392 ----
  
      def getphraselist(self):
!         """Parse a sequence of RFC 2822 phrases.
  
!         A phrase is a sequence of words, which are in turn either RFC 2822
!         atoms or quoted-strings.  Phrases are canonicalized by squeezing all
!         runs of continuous whitespace into one space.
          """
          plist = []
***************
*** 385,396 ****
              elif self.field[self.pos] == '(':
                  self.commentlist.append(self.getcomment())
!             elif self.field[self.pos] in self.atomends:
                  break
!             else: plist.append(self.getatom())
  
          return plist
  
  class AddressList(AddrlistClass):
!     """An AddressList encapsulates a list of parsed RFC822 addresses."""
      def __init__(self, field):
          AddrlistClass.__init__(self, field)
--- 399,410 ----
              elif self.field[self.pos] == '(':
                  self.commentlist.append(self.getcomment())
!             elif self.field[self.pos] in self.phraseends:
                  break
!             else: plist.append(self.getatom(self.phraseends))
  
          return plist
  
  class AddressList(AddrlistClass):
!     """An AddressList encapsulates a list of parsed RFC 2822 addresses."""
      def __init__(self, field):
          AddrlistClass.__init__(self, field)