[Zope3-checkins] CVS: Zope3/src/zope/fssync - metadata.py:1.2

Guido van Rossum guido@python.org
Tue, 13 May 2003 12:15:21 -0400


Update of /cvs-repository/Zope3/src/zope/fssync
In directory cvs.zope.org:/tmp/cvs-serv19636

Modified Files:
	metadata.py 
Log Message:
Get rid of silliness with passing in case_insensitive.

Deal with multiple case-insensitive matches by raising KeyError	--
better fail than ignore the problem.


=== Zope3/src/zope/fssync/metadata.py 1.1 => 1.2 ===
--- Zope3/src/zope/fssync/metadata.py:1.1	Mon May 12 16:19:38 2003
+++ Zope3/src/zope/fssync/metadata.py	Tue May 13 12:15:21 2003
@@ -30,17 +30,12 @@
 
 from zope.xmlpickle import loads, dumps
 
-class Metadata(object):
+case_insensitive = (normcase("ABC") == normcase("abc"))
 
-    def __init__(self, case_insensitive=None):
-        """Constructor.
+class Metadata(object):
 
-        The case_insensitive can be passed as an argument for testing;
-        by default, it is set by observing the behavior of normcase().
-        """
-        if case_insensitive is None:
-            case_insensitive = (normcase("ABC") == normcase("abc"))
-        self.case_insensitive = case_insensitive
+    def __init__(self):
+        """Constructor."""
         self.cache = {} # Keyed by normcase(dirname(realpath(file)))
         self.originals = {} # Original copy as read from file
 
@@ -65,14 +60,15 @@
         entries = self._getentries(dir)
         if base in entries:
             return entries[base]
-        if self.case_insensitive:
+        if case_insensitive:
             # Look for a case-insensitive match -- expensive!
             # XXX There's no test case for this code!
-            # XXX What if there are multiple matches?
             nbase = normcase(base)
-            for b in entries:
-                if normcase(b) == nbase:
-                    return entries[b]
+            matches = [b for b in entries if normcase(b) == nbase]
+            if matches:
+                if len(matches) > 1:
+                    raise KeyError("multiple entries match %r" % nbase)
+                return entries[matches[0]]
         # Create a new entry
         entries[base] = entry = {}
         return entry