[Python-checkins] r55753 - in python/branches/release25-maint: Lib/_strptime.py Lib/test/test_strptime.py Misc/NEWS

brett.cannon python-checkins at python.org
Mon Jun 4 02:14:07 CEST 2007


Author: brett.cannon
Date: Mon Jun  4 02:14:06 2007
New Revision: 55753

Modified:
   python/branches/release25-maint/Lib/_strptime.py
   python/branches/release25-maint/Lib/test/test_strptime.py
   python/branches/release25-maint/Misc/NEWS
Log:
Backport of r55752: make time.strptime() behave better when whitespace is in
the format arguments.


Modified: python/branches/release25-maint/Lib/_strptime.py
==============================================================================
--- python/branches/release25-maint/Lib/_strptime.py	(original)
+++ python/branches/release25-maint/Lib/_strptime.py	Mon Jun  4 02:14:06 2007
@@ -253,7 +253,7 @@
         regex_chars = re_compile(r"([\\.^$*+?\(\){}\[\]|])")
         format = regex_chars.sub(r"\\\1", format)
         whitespace_replacement = re_compile('\s+')
-        format = whitespace_replacement.sub('\s*', format)
+        format = whitespace_replacement.sub('\s+', format)
         while '%' in format:
             directive_index = format.index('%')+1
             processed_format = "%s%s%s" % (processed_format,

Modified: python/branches/release25-maint/Lib/test/test_strptime.py
==============================================================================
--- python/branches/release25-maint/Lib/test/test_strptime.py	(original)
+++ python/branches/release25-maint/Lib/test/test_strptime.py	Mon Jun  4 02:14:06 2007
@@ -190,6 +190,15 @@
                         "locale data that contains regex metacharacters is not"
                         " properly escaped")
 
+    def test_whitespace_substitution(self):
+        # When pattern contains whitespace, make sure it is taken into account
+        # so as to not allow to subpatterns to end up next to each other and
+        # "steal" characters from each other.
+        pattern = self.time_re.pattern('%j %H')
+        self.failUnless(not re.match(pattern, "180"))
+        self.failUnless(re.match(pattern, "18 0"))
+
+
 class StrptimeTests(unittest.TestCase):
     """Tests for _strptime.strptime."""
 

Modified: python/branches/release25-maint/Misc/NEWS
==============================================================================
--- python/branches/release25-maint/Misc/NEWS	(original)
+++ python/branches/release25-maint/Misc/NEWS	Mon Jun  4 02:14:06 2007
@@ -12,6 +12,9 @@
 Library
 -------
 
+- Bug #1730389: Have time.strptime() match spaces in a format argument with
+  ``\s+`` instead of ``\s*``.
+
 - SF 1668596/1720897: distutils now copies data files
   even if package_dir is empty.
 


More information about the Python-checkins mailing list