[Zope-Checkins] CVS: Products/ZCatalog - Catalog.py:1.111.2.6.6.1
Andreas Jung
andreas at andreas-jung.com
Sat Oct 9 08:05:31 EDT 2004
Update of /cvs-repository/Products/ZCatalog
In directory cvs.zope.org:/tmp/cvs-serv23889
Modified Files:
Tag: ajung-catalog__len__-migration-branch
Catalog.py
Log Message:
=== Products/ZCatalog/Catalog.py 1.111.2.6 => 1.111.2.6.6.1 ===
--- Products/ZCatalog/Catalog.py:1.111.2.6 Tue May 18 10:48:48 2004
+++ Products/ZCatalog/Catalog.py Sat Oct 9 08:05:30 2004
@@ -76,7 +76,6 @@
# object unique identifier to the rid, and self.paths is a
# mapping of the rid to the unique identifier.
- self.__len__=BTrees.Length.Length()
self.clear()
if brains is not None:
@@ -91,51 +90,23 @@
self.uids = OIBTree() # mapping of uid to rid
self.paths = IOBTree() # mapping of rid to uid
- # convert old-style Catalog object to new in-place
- try: self.__len__.set(0)
- except AttributeError: self.__len__=BTrees.Length.Length()
+ self._length = BTrees.Length.Length()
for index in self.indexes.keys():
self.getIndex(index).clear()
- def _convertBTrees(self, threshold=200):
-
- from BTrees.convert import convert
-
- if type(self.data) is not IOBTree:
- data=self.data
- self.data=IOBTree()
- convert(data, self.data, threshold)
-
- self.__len__=BTrees.Length.Length(len(data))
-
- uids=self.uids
- self.uids=OIBTree()
- convert(uids, self.uids, threshold)
-
- paths=self.paths
- self.paths=IOBTree()
- convert(paths, self.paths, threshold)
-
-
- for index in self.indexes.values():
- if hasattr(index, '__of__'): index=index.__of__(self)
- index._convertBTrees(threshold)
-
def __len__(self):
- # NOTE, this is never called for new catalogs, since
- # each instance overrides this.
- return len(self.data)
+ return self._length()
def updateBrains(self):
self.useBrains(self._v_brains)
- def __getitem__(self, index, ttype=type(())):
+ def __getitem__(self, index):
"""
Returns instances of self._v_brains, or whatever is passed
into self.useBrains.
"""
- if type(index) is ttype:
+ if isinstance(index, TupleType):
# then it contains a score...
normalized_score, score, key = index
r=self._v_result_class(self.data[key]).__of__(self.aq_parent)
@@ -359,8 +330,7 @@
if index is None: # we are inserting new data
index = self.updateMetadata(object, uid)
- try: self.__len__.change(1)
- except AttributeError: pass # No managed length (old-style)
+ self._length.change(1)
self.uids[uid] = index
self.paths[index] = uid
@@ -412,8 +382,8 @@
del data[rid]
del paths[rid]
del uids[uid]
- try: self.__len__.change(-1)
- except AttributeError: pass # No managed length
+ self._length.change(-1)
+
else:
LOG('Catalog', ERROR, ('uncatalogObject unsuccessfully '
'attempted to uncatalog an object '
More information about the Zope-Checkins
mailing list