[Python-checkins] r84312 - in python/branches/release31-maint: Lib/email/_parseaddr.py Lib/email/test/test_email.py Misc/ACKS Misc/NEWS

r.david.murray python-checkins at python.org
Wed Aug 25 03:55:25 CEST 2010


Author: r.david.murray
Date: Wed Aug 25 03:55:24 2010
New Revision: 84312

Log:
Merged revisions 84310 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r84310 | r.david.murray | 2010-08-24 20:45:55 -0400 (Tue, 24 Aug 2010) | 8 lines
  
  #1194222: make parsedate always return RFC2822 four character years.
  
  Two character years are now converted to four character years using
  the Posix standard rule (<68 == 2000, >=68==1900).  This makes the
  parsed date RFC2822 compliant even if the input is not.
  
  Patch and test by Jeffrey Finkelstein.
........


Modified:
   python/branches/release31-maint/   (props changed)
   python/branches/release31-maint/Lib/email/_parseaddr.py
   python/branches/release31-maint/Lib/email/test/test_email.py
   python/branches/release31-maint/Misc/ACKS
   python/branches/release31-maint/Misc/NEWS

Modified: python/branches/release31-maint/Lib/email/_parseaddr.py
==============================================================================
--- python/branches/release31-maint/Lib/email/_parseaddr.py	(original)
+++ python/branches/release31-maint/Lib/email/_parseaddr.py	Wed Aug 25 03:55:24 2010
@@ -107,6 +107,18 @@
         tss = int(tss)
     except ValueError:
         return None
+    # Check for a yy specified in two-digit format, then convert it to the
+    # appropriate four-digit format, according to the POSIX standard. RFC 822
+    # calls for a two-digit yy, but RFC 2822 (which obsoletes RFC 822)
+    # mandates a 4-digit yy. For more information, see the documentation for
+    # the time module.
+    if yy < 100:
+        # The year is between 1969 and 1999 (inclusive).
+        if yy > 68:
+            yy += 1900
+        # The year is between 2000 and 2068 (inclusive).
+        else:
+            yy += 2000
     tzoffset = None
     tz = tz.upper()
     if tz in _timezones:

Modified: python/branches/release31-maint/Lib/email/test/test_email.py
==============================================================================
--- python/branches/release31-maint/Lib/email/test/test_email.py	(original)
+++ python/branches/release31-maint/Lib/email/test/test_email.py	Wed Aug 25 03:55:24 2010
@@ -2230,6 +2230,19 @@
         eq(time.localtime(t)[:6], timetup[:6])
         eq(int(time.strftime('%Y', timetup[:9])), 2003)
 
+    def test_parsedate_y2k(self):
+        """Test for parsing a date with a two-digit year.
+
+        Parsing a date with a two-digit year should return the correct
+        four-digit year. RFC822 allows two-digit years, but RFC2822 (which
+        obsoletes RFC822) requires four-digit years.
+
+        """
+        self.assertEqual(utils.parsedate_tz('25 Feb 03 13:47:26 -0800'),
+                         utils.parsedate_tz('25 Feb 2003 13:47:26 -0800'))
+        self.assertEqual(utils.parsedate_tz('25 Feb 71 13:47:26 -0800'),
+                         utils.parsedate_tz('25 Feb 1971 13:47:26 -0800'))
+
     def test_parseaddr_empty(self):
         self.assertEqual(utils.parseaddr('<>'), ('', ''))
         self.assertEqual(utils.formataddr(utils.parseaddr('<>')), '')

Modified: python/branches/release31-maint/Misc/ACKS
==============================================================================
--- python/branches/release31-maint/Misc/ACKS	(original)
+++ python/branches/release31-maint/Misc/ACKS	Wed Aug 25 03:55:24 2010
@@ -241,6 +241,7 @@
 Sebastian Fernandez
 Vincent Fiack
 Tomer Filiba
+Jeffrey Finkelstein
 Russell Finn
 Nils Fischbeck
 Frederik Fix

Modified: python/branches/release31-maint/Misc/NEWS
==============================================================================
--- python/branches/release31-maint/Misc/NEWS	(original)
+++ python/branches/release31-maint/Misc/NEWS	Wed Aug 25 03:55:24 2010
@@ -95,6 +95,9 @@
 Library
 -------
 
+- Issue #1194222: email.utils.parsedate now returns RFC2822 compliant four
+  character years even if the message contains RFC822 two character years.
+
 - Issue #8750: Fixed MutableSet's methods to correctly handle
   reflexive operations, namely x -= x and x ^= x.
 


More information about the Python-checkins mailing list