[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/PathIndex - PathIndex.py:1.25.4.6

Chris McDonough chrism@zope.com
Fri, 3 Jan 2003 01:34:01 -0500


Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/PathIndex
In directory cvs.zope.org:/tmp/cvs-serv27194/PluginIndexes/PathIndex

Modified Files:
      Tag: chrism-install-branch
	PathIndex.py 
Log Message:
Merging chrism-install-branch with HEAD (hopefully for one of the last
times).



=== Zope/lib/python/Products/PluginIndexes/PathIndex/PathIndex.py 1.25.4.5 => 1.25.4.6 ===
--- Zope/lib/python/Products/PluginIndexes/PathIndex/PathIndex.py:1.25.4.5	Sun Nov 24 19:14:55 2002
+++ Zope/lib/python/Products/PluginIndexes/PathIndex/PathIndex.py	Fri Jan  3 01:32:59 2003
@@ -23,6 +23,7 @@
 from BTrees.OOBTree import OOBTree
 from BTrees.IIBTree import IISet, intersection, union
 from OFS.SimpleItem import SimpleItem
+from zLOG import LOG, ERROR
 from types import StringType, ListType, TupleType
 import re, warnings
 
@@ -43,7 +44,7 @@
 
     """
 
-    __implements__ = (PluggableIndex.PluggableIndexInterface,)
+    __implements__ = (PluggableIndex.UniqueValueIndex,)
 
     meta_type="PathIndex"
 
@@ -141,21 +142,30 @@
         """ hook for (Z)Catalog """
 
         if not self._unindex.has_key(documentId):
+            LOG(self.__class__.__name__, ERROR,
+                'Attempt to unindex nonexistent document'
+                ' with id %s' % documentId)
             return
-
+        
         path = self._unindex[documentId]
         comps = path.split('/')
 
         for level in range(len(comps[1:])):
             comp = comps[level+1]
 
-            self._index[comp][level].remove(documentId)
+            try:
+                self._index[comp][level].remove(documentId)
+
+                if len(self._index[comp][level])==0:
+                    del self._index[comp][level]
 
-            if len(self._index[comp][level])==0:
-                del self._index[comp][level]
+                if len(self._index[comp])==0:
+                    del self._index[comp]
+            except KeyError:
+                LOG(self.__class__.__name__, ERROR,
+                    'Attempt to unindex document'
+                    ' with id %s failed' % documentId)
 
-            if len(self._index[comp])==0:
-                del self._index[comp]
 
         del self._unindex[documentId]
 
@@ -209,14 +219,13 @@
 
             results = []
             for i in range(len(comps)):
-
                 comp = comps[i]
 
                 if not self._index.has_key(comp): return IISet()
                 if not self._index[comp].has_key(level+i): return IISet()
 
                 results.append( self._index[comp][level+i] )
-
+            
             res = results[0]
 
             for i in range(1,len(results)):
@@ -319,6 +328,12 @@
         else:
             return IISet(), (self.id,)
 
+    def hasUniqueValuesFor(self, name):
+        """has unique values for column name"""
+        if name == self.id:
+            return 1
+        else:
+            return 0
 
     def uniqueValues(self,name=None,withLength=0):
         """ needed to be consistent with the interface """