Rev 2250: (John Arbash Meinel) hard-code the whitespace chars to avoid problems in some locales. in http://bzr.arbash-meinel.com/branches/bzr/jam-integration

John Arbash Meinel john at arbash-meinel.com
Thu Feb 1 14:50:01 GMT 2007


At http://bzr.arbash-meinel.com/branches/bzr/jam-integration

------------------------------------------------------------
revno: 2250
revision-id: john at arbash-meinel.com-20070201144953-d877vy9zbvxr5q98
parent: pqm at pqm.ubuntu.com-20070131184047-424584b0fabcee96
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: jam-integration
timestamp: Thu 2007-02-01 08:49:53 -0600
message:
  (John Arbash Meinel) hard-code the whitespace chars to avoid problems in some locales.
modified:
  bzrlib/osutils.py              osutils.py-20050309040759-eeaff12fbf77ac86
  bzrlib/tests/test_osutils.py   test_osutils.py-20051201224856-e48ee24c12182989
-------------- next part --------------
=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py	2007-01-04 23:36:44 +0000
+++ b/bzrlib/osutils.py	2007-02-01 14:49:53 +0000
@@ -40,7 +40,6 @@
 from shutil import (
     rmtree,
     )
-import string
 import tempfile
 from tempfile import (
     mkdtemp,
@@ -777,7 +776,15 @@
 
 def contains_whitespace(s):
     """True if there are any whitespace characters in s."""
-    for ch in string.whitespace:
+    # string.whitespace can include '\xa0' in certain locales, because it is
+    # considered "non-breaking-space" as part of ISO-8859-1. But it
+    # 1) Isn't a breaking whitespace
+    # 2) Isn't one of ' \t\r\n' which are characters we sometimes use as
+    #    separators
+    # 3) '\xa0' isn't unicode safe since it is >128.
+    # So we are following textwrap's example and hard-coding our own.
+    # We probably could ignore \v and \f, too.
+    for ch in u' \t\n\r\v\f':
         if ch in s:
             return True
     else:

=== modified file 'bzrlib/tests/test_osutils.py'
--- a/bzrlib/tests/test_osutils.py	2007-01-04 23:36:44 +0000
+++ b/bzrlib/tests/test_osutils.py	2007-02-01 14:49:53 +0000
@@ -38,6 +38,20 @@
 
 class TestOSUtils(TestCaseInTempDir):
 
+    def test_contains_whitespace(self):
+        self.failUnless(osutils.contains_whitespace(u' '))
+        self.failUnless(osutils.contains_whitespace(u'hello there'))
+        self.failUnless(osutils.contains_whitespace(u'hellothere\n'))
+        self.failUnless(osutils.contains_whitespace(u'hello\nthere'))
+        self.failUnless(osutils.contains_whitespace(u'hello\rthere'))
+        self.failUnless(osutils.contains_whitespace(u'hello\tthere'))
+
+        # \xa0 is "Non-breaking-space" which on some python locales thinks it
+        # is whitespace, but we do not.
+        self.failIf(osutils.contains_whitespace(u''))
+        self.failIf(osutils.contains_whitespace(u'hellothere'))
+        self.failIf(osutils.contains_whitespace(u'hello\xa0there'))
+
     def test_fancy_rename(self):
         # This should work everywhere
         def rename(a, b):



More information about the bazaar-commits mailing list