]> granicus.if.org Git - python/commitdiff
#1155362: allow hh:mm:ss-uuuu like we allow hh:mm:ss+uuuu in parsedate_tz
authorR. David Murray <rdmurray@bitdance.com>
Thu, 23 Dec 2010 20:35:46 +0000 (20:35 +0000)
committerR. David Murray <rdmurray@bitdance.com>
Thu, 23 Dec 2010 20:35:46 +0000 (20:35 +0000)
Original patch by Thomas Herve.

Lib/email/_parseaddr.py
Lib/email/test/test_email.py
Misc/NEWS

index 699d418b3feb8241003b4890270adfe4862dbfa7..41694f9b1acac5d6903cdbfcf692cb02df9eb994 100644 (file)
@@ -64,8 +64,10 @@ def parsedate_tz(data):
     if len(data) == 4:
         s = data[3]
         i = s.find('+')
+        if i == -1:
+            i = s.find('-')
         if i > 0:
-            data[3:] = [s[:i], s[i+1:]]
+            data[3:] = [s[:i], s[i:]]
         else:
             data.append('') # Dummy tz
     if len(data) < 5:
index a54c1a3447a89b0e674f0eda3f688019a4794f71..53c4042479322a1d04feb077ab549e47f7cb90c5 100644 (file)
@@ -2277,6 +2277,16 @@ class TestMiscellaneous(TestEmailBase):
         eq(utils.parsedate_tz('5 Feb 2003 13:47:26 -0800'),
            (2003, 2, 5, 13, 47, 26, 0, 1, -1, -28800))
 
+    def test_parsedate_no_space_before_positive_offset(self):
+        self.assertEqual(utils.parsedate_tz('Wed, 3 Apr 2002 14:58:26+0800'),
+           (2002, 4, 3, 14, 58, 26, 0, 1, -1, 28800))
+
+    def test_parsedate_no_space_before_negative_offset(self):
+        # Issue 1155362: we already handled '+' for this case.
+        self.assertEqual(utils.parsedate_tz('Wed, 3 Apr 2002 14:58:26-0800'),
+           (2002, 4, 3, 14, 58, 26, 0, 1, -1, -28800))
+
+
     def test_parsedate_acceptable_to_time_functions(self):
         eq = self.assertEqual
         timetup = utils.parsedate('5 Feb 2003 13:47:26 -0800')
index 9462981d9d193335259f26c0905a12ec0943b880..faf5554880a92600e7147464594b2be42f5659aa 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -11,6 +11,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #1155362: email.utils.parsedate_tz now handles a missing space before
+  the '-' of a timezone field as well as before a '+'.
+
 - Issue #4871: The zipfile module now gives a more useful error message if
   an attempt is made to use a string to specify the archive password.