[Python-checkins] python/dist/src/Lib _strptime.py,1.32,1.33

bcannon at users.sourceforge.net bcannon at users.sourceforge.net
Wed Oct 6 04:12:09 CEST 2004


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16270/Lib

Modified Files:
	_strptime.py 
Log Message:
Locale data that contains regex metacharacters are now properly escaped.

Closes bug #1039270.


Index: _strptime.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/_strptime.py,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- _strptime.py	4 May 2004 09:21:43 -0000	1.32
+++ _strptime.py	6 Oct 2004 02:11:36 -0000	1.33
@@ -15,6 +15,7 @@
 import calendar
 from re import compile as re_compile
 from re import IGNORECASE
+from re import escape as re_escape
 from datetime import date as datetime_date
 try:
     from thread import allocate_lock as _thread_allocate_lock
@@ -232,7 +233,7 @@
             return ''
         to_convert = to_convert[:]
         to_convert.sort(key=len, reverse=True)
-        regex = '|'.join(to_convert)
+        regex = '|'.join(re_escape(stuff) for stuff in to_convert)
         regex = '(?P<%s>%s' % (directive, regex)
         return '%s)' % regex
 
@@ -245,7 +246,8 @@
         """
         processed_format = ''
         # The sub() call escapes all characters that might be misconstrued
-        # as regex syntax.
+        # as regex syntax.  Cannot use re.escape since we have to deal with
+        # format directives (%m, etc.).
         regex_chars = re_compile(r"([\\.^$*+?\(\){}\[\]|])")
         format = regex_chars.sub(r"\\\1", format)
         whitespace_replacement = re_compile('\s+')



More information about the Python-checkins mailing list