[Python-checkins] python/dist/src/Lib/test test_strftime.py, 1.27, 1.27.16.1

bcannon at users.sourceforge.net bcannon at users.sourceforge.net
Sat Mar 20 18:13:52 EST 2004


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

Modified Files:
      Tag: release23-maint
	test_strftime.py 
Log Message:
Fix test_strftime.py to escape locale time values that have characters that
might be mistaken for regex syntax.
Fixes bug #883604 .


Index: test_strftime.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_strftime.py,v
retrieving revision 1.27
retrieving revision 1.27.16.1
diff -C2 -d -r1.27 -r1.27.16.1
*** test_strftime.py	23 Jul 2002 19:04:03 -0000	1.27
--- test_strftime.py	20 Mar 2004 23:13:49 -0000	1.27.16.1
***************
*** 29,32 ****
--- 29,42 ----
              strftest(now + (i + j*100)*23*3603)
  
+ def escapestr(text, ampm):
+     """Escape text to deal with possible locale values that have regex
+     syntax while allowing regex syntax used for the comparison."""
+     new_text = re.escape(text)
+     new_text = new_text.replace(re.escape(ampm), ampm)
+     new_text = new_text.replace("\%", "%")
+     new_text = new_text.replace("\:", ":")
+     new_text = new_text.replace("\?", "?")
+     return new_text
+ 
  def strftest(now):
      if verbose:
***************
*** 51,54 ****
--- 61,66 ----
      else: clock12 = 12
  
+     # Make sure any characters that could be taken as regex syntax is
+     # escaped in escapestr()
      expectations = (
          ('%a', calendar.day_abbr[now[6]], 'abbreviated weekday name'),
***************
*** 111,115 ****
              print "Standard '%s' format gave error:" % e[0], error
              continue
!         if re.match(e[1], result): continue
          if not result or result[0] == '%':
              print "Does not support standard '%s' format (%s)" % (e[0], e[2])
--- 123,127 ----
              print "Standard '%s' format gave error:" % e[0], error
              continue
!         if re.match(escapestr(e[1], ampm), result): continue
          if not result or result[0] == '%':
              print "Does not support standard '%s' format (%s)" % (e[0], e[2])
***************
*** 126,130 ****
                        (e[0], e[2], str(result))
              continue
!         if re.match(e[1], result):
              if verbose:
                  print "Supports nonstandard '%s' format (%s)" % (e[0], e[2])
--- 138,142 ----
                        (e[0], e[2], str(result))
              continue
!         if re.match(escapestr(e[1], ampm), result):
              if verbose:
                  print "Supports nonstandard '%s' format (%s)" % (e[0], e[2])




More information about the Python-checkins mailing list