]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
SF bug #453515: filecmp.dircmp case sensitivity bug
authorRaymond Hettinger <python@rcn.com>
Tue, 2 Sep 2003 05:47:17 +0000 (05:47 +0000)
committerRaymond Hettinger <python@rcn.com>
Tue, 2 Sep 2003 05:47:17 +0000 (05:47 +0000)
Lib/filecmp.py
Lib/test/test_filecmp.py
Misc/NEWS

index 321ae0cbc5f16ffc22fed90388bac6afa14bbe7d..089c6674969ae3d83a30f7378641052fe616058e 100644 (file)
@@ -12,7 +12,7 @@ Functions:
 import os
 import stat
 import warnings
-from itertools import ifilter, ifilterfalse
+from itertools import ifilter, ifilterfalse, imap, izip
 
 __all__ = ["cmp","dircmp","cmpfiles"]
 
@@ -135,11 +135,11 @@ class dircmp:
         self.right_list.sort()
 
     def phase1(self): # Compute common names
-        b = dict.fromkeys(self.right_list)
-        common = dict.fromkeys(ifilter(b.has_key, self.left_list))
-        self.left_only = list(ifilterfalse(common.has_key, self.left_list))
-        self.right_only = list(ifilterfalse(common.has_key, self.right_list))
-        self.common = common.keys()
+        a = dict(izip(imap(os.path.normcase, self.left_list), self.left_list))
+        b = dict(izip(imap(os.path.normcase, self.right_list), self.right_list))
+        self.common = map(a.__getitem__, ifilter(b.has_key, a))
+        self.left_only = map(a.__getitem__, ifilterfalse(b.has_key, a))
+        self.right_only = map(b.__getitem__, ifilterfalse(a.has_key, b))
 
     def phase2(self): # Distinguish files, directories, funnies
         self.common_dirs = []
index 0e5f297039c64c2418553458cf7c6a57942c287b..b433ecc9ef16a3ffd756604b7b0f4ee055624278 100644 (file)
@@ -49,7 +49,11 @@ class DirCompareTestCase(unittest.TestCase):
         data = 'Contents of file go here.\n'
         for dir in [self.dir, self.dir_same, self.dir_diff]:
             os.mkdir(dir)
-            output = open(os.path.join(dir, 'file'), 'w')
+            if dir is self.dir_same:
+                fn = 'FiLe'     # Verify case-insensitive comparison
+            else:
+                fn = 'file'
+            output = open(os.path.join(dir, fn), 'w')
             output.write(data)
             output.close()
 
@@ -93,7 +97,7 @@ class DirCompareTestCase(unittest.TestCase):
     def test_dircmp(self):
         # Check attributes for comparison of two identical directories
         d = filecmp.dircmp(self.dir, self.dir_same)
-        self.failUnless(d.left_list == d.right_list == ['file'])
+        self.assertEqual([d.left_list, d.right_list],[['file'], ['FiLe']])
         self.failUnless(d.common == ['file'])
         self.failUnless(d.left_only == d.right_only == [])
         self.failUnless(d.same_files == ['file'])
index a4397e61fe6b12e6016ded3768f991bcb28883fe..7a2abfdd17428aa8b914beb814051f7114c8e7c6 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -37,6 +37,9 @@ Extension modules
 Library
 -------
 
+- Bug #453515:  filecmp.dircmp() can now make case insensitive
+  filename comparisons.
+
 - Bug #798254:  doctest.py can now handle unbound methods.
 
 - Bug #797650:  textwrap.py now avoids an infinite loop when one of the