Commit 4593245a authored by Chris McDonough's avatar Chris McDonough

Committing zcatatalog keyerror fixes to trunk.

parent 9033fe63
...@@ -385,24 +385,28 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -385,24 +385,28 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
Note, the uid must be the same as when the object was Note, the uid must be the same as when the object was
catalogued, otherwise it will not get removed from the catalog catalogued, otherwise it will not get removed from the catalog
This method should not raise an exception if the uid cannot
be found in the catalog.
""" """
try: data = self.data
rid = self.uids[uid] uids = self.uids
paths = self.paths
indexes = self.indexes
rid = uids.get(uid, None)
for x in self.indexes.values(): if rid is not None:
for x in indexes.values():
x = x.__of__(self) x = x.__of__(self)
if hasattr(x, 'unindex_object'): if hasattr(x, 'unindex_object'):
try: x.unindex_object(rid)
x.unindex_object(rid) # this should never raise an exception
except KeyError: for btree in (data, paths):
pass #fugedaboudit try:
del btree[rid]
del self.data[rid] except KeyError:
del self.uids[uid] pass
del self.paths[rid] del uids[uid]
except:
pass
def clear(self): def clear(self):
""" clear catalog """ """ clear catalog """
......
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
############################################################################## ##############################################################################
"""Simple column indices""" """Simple column indices"""
__version__='$Revision: 1.11 $'[11:-2] __version__='$Revision: 1.12 $'[11:-2]
from Globals import Persistent from Globals import Persistent
from Acquisition import Implicit from Acquisition import Implicit
...@@ -186,15 +186,18 @@ class UnIndex(Persistent, Implicit): ...@@ -186,15 +186,18 @@ class UnIndex(Persistent, Implicit):
def unindex_object(self, i): def unindex_object(self, i):
""" Unindex the object with integer id 'i' """ """ Unindex the object with integer id 'i' and don't
raise an exception if we fail """
index = self._index index = self._index
unindex = self._unindex unindex = self._unindex
k = unindex[i] k = unindex.get(i, None)
if k is None: if k is None:
return None return None
set = index.get(k) set = index.get(k, None)
if set is not None: set.remove(i) if set is not None:
try: set.remove(i)
except: pass
del unindex[i] del unindex[i]
self._index = index self._index = index
......
...@@ -43,16 +43,17 @@ class UnKeywordIndex(UnIndex): ...@@ -43,16 +43,17 @@ class UnKeywordIndex(UnIndex):
def unindex_object(self, i): def unindex_object(self, i):
""" Unindex the object with integer id 'i' """ """ carefully unindex the object with integer id 'i' and do not
fail if it does not exist """
index = self._index index = self._index
unindex = self._unindex unindex = self._unindex
kws = unindex[i] kws = unindex.get(i, None)
if kws is None: if kws is None:
return None return None
for kw in kws: for kw in kws:
set = index.get(kw) set = index.get(kw, None)
if set is not None: set.remove(i) if set is not None: set.remove(i)
del unindex[i] del unindex[i]
......
...@@ -92,7 +92,7 @@ is no longer known. ...@@ -92,7 +92,7 @@ is no longer known.
""" """
__version__='$Revision: 1.23 $'[11:-2] __version__='$Revision: 1.24 $'[11:-2]
from Globals import Persistent from Globals import Persistent
import BTree, IIBTree, IOBTree, OIBTree import BTree, IIBTree, IOBTree, OIBTree
...@@ -316,18 +316,23 @@ class UnTextIndex(Persistent, Implicit): ...@@ -316,18 +316,23 @@ class UnTextIndex(Persistent, Implicit):
def unindex_object(self, i, tt=type(()) ): def unindex_object(self, i, tt=type(()) ):
""" unindex object 'obj' with iteger id 'i' from the text index """ """ carefully unindex document with integer id 'i' from the text
index and do not fail if it does not exist """
index = self._index index = self._index
for n in self._unindex[i]: unindex = self._unindex
v = index[n] val = unindex.get(i, None)
if type(v) is tt: if val is not None:
del index[n] for n in val:
else: v = index.get(n, None)
del index[n][i] if type(v) is tt:
del index[n]
del self._unindex[i] elif v is not None:
try:
self._index = index del index[n][i]
except (KeyError, IndexError, TypeError):
pass
del unindex[i]
self._index = index
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment