[Python-checkins] python/dist/src/Lib/test test_locale.py,1.8,1.9

perky at users.sourceforge.net perky at users.sourceforge.net
Wed Aug 4 08:33:54 CEST 2004


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

Modified Files:
	test_locale.py 
Log Message:
Add a workaround for a problem that UTF-8 strings can be corrupted
or broken by basic ctype functions in 4.4BSD descendants.  This
will be fixed in their future development branches but they'll keep
the POSIX-incompatibility for their backward-compatiblities in near
future.


Index: test_locale.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_locale.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** test_locale.py	19 Dec 2003 01:16:03 -0000	1.8
--- test_locale.py	4 Aug 2004 06:33:51 -0000	1.9
***************
*** 48,49 ****
--- 48,84 ----
  finally:
      locale.setlocale(locale.LC_NUMERIC, oldlocale)
+ 
+ 
+ # Test BSD Rune locale's bug for isctype functions.
+ def teststrop(s, method, output):
+     if verbose:
+         print "%s.%s() =? %s ..." % (repr(s), method, repr(output)),
+     result = getattr(s, method)()
+     if result != output:
+         if verbose:
+             print "no"
+         print "%s.%s() == %s != %s" % (repr(s), method, repr(result),
+                                        repr(output))
+     elif verbose:
+         print "yes"
+ 
+ try:
+     oldlocale = locale.setlocale(locale.LC_CTYPE)
+     locale.setlocale(locale.LC_CTYPE, 'en_US.UTF-8')
+ except locale.Error:
+     pass
+ else:
+     try:
+         teststrop('\x20', 'isspace', True)
+         teststrop('\xa0', 'isspace', False)
+         teststrop('\xa1', 'isspace', False)
+         teststrop('\xc0', 'isalpha', False)
+         teststrop('\xc0', 'isalnum', False)
+         teststrop('\xc0', 'isupper', False)
+         teststrop('\xc0', 'islower', False)
+         teststrop('\xec\xa0\xbc', 'split', ['\xec\xa0\xbc'])
+         teststrop('\xed\x95\xa0', 'strip', '\xed\x95\xa0')
+         teststrop('\xcc\x85', 'lower', '\xcc\x85')
+         teststrop('\xed\x95\xa0', 'upper', '\xed\x95\xa0')
+     finally:
+         locale.setlocale(locale.LC_CTYPE, oldlocale)



More information about the Python-checkins mailing list