[Checkins] SVN: zc.catalog/trunk/s add support for BTree families
Fred L. Drake, Jr.
fdrake at gmail.com
Fri Apr 27 10:59:53 EDT 2007
Log message for revision 74859:
add support for BTree families
Changed:
U zc.catalog/trunk/setup.py
U zc.catalog/trunk/src/zc/catalog/extentcatalog.py
U zc.catalog/trunk/src/zc/catalog/extentcatalog.txt
U zc.catalog/trunk/src/zc/catalog/tests.py
-=-
Modified: zc.catalog/trunk/setup.py
===================================================================
--- zc.catalog/trunk/setup.py 2007-04-27 14:25:49 UTC (rev 74858)
+++ zc.catalog/trunk/setup.py 2007-04-27 14:59:52 UTC (rev 74859)
@@ -26,10 +26,10 @@
install_requires=['setuptools',
'zope.component',
'zope.testing',
- 'ZODB3',
+ 'ZODB3 >=3.8.0a1.dev-r74856', # required BTrees.family*
'zope.schema',
'zope.interface',
- 'zope.app.catalog',
+ 'zope.app.catalog >=3.4.0a2',
'pytz',
'zope.security',
'zope.publisher',
Modified: zc.catalog/trunk/src/zc/catalog/extentcatalog.py
===================================================================
--- zc.catalog/trunk/src/zc/catalog/extentcatalog.py 2007-04-27 14:25:49 UTC (rev 74858)
+++ zc.catalog/trunk/src/zc/catalog/extentcatalog.py 2007-04-27 14:59:52 UTC (rev 74859)
@@ -17,7 +17,7 @@
"""
import sys
-import BTrees.IFBTree
+import BTrees
import persistent
from zope import interface, component
from zope.app.catalog import catalog
@@ -34,12 +34,14 @@
class Extent(persistent.Persistent):
interface.implements(interfaces.IExtent)
__parent__ = None
+ family = BTrees.family32
- def __init__(self):
- self.set = zope.component.queryUtility(
- IFactory, name="IFTreeSet",
- default=BTrees.IFBTree.IFTreeSet)()
+ def __init__(self, family=None):
+ if family is not None:
+ self.family = family
+ self.set = self.family.IF.TreeSet()
+ # Deprecated.
@property
def BTreeAPI(self):
return sys.modules[self.set.__class__.__module__]
@@ -57,7 +59,7 @@
__ror__ = __or__
def union(self, other, self_weight=1, other_weight=1):
- return self.BTreeAPI.weightedUnion(
+ return self.family.IF.weightedUnion(
self.set, other, self_weight, other_weight)[1]
def __and__(self, other):
@@ -67,7 +69,7 @@
__rand__ = __and__
def intersection(self, other, self_weight=1, other_weight=1):
- return self.BTreeAPI.weightedIntersection(
+ return self.family.IF.weightedIntersection(
self.set, other, self_weight, other_weight)[1]
def __sub__(self, other):
@@ -75,14 +77,14 @@
return self.difference(other)
def difference(self, other):
- return self.BTreeAPI.difference(self.set, other)
+ return self.family.IF.difference(self.set, other)
def __rsub__(self, other):
"set - extent"
return self.rdifference(other)
def rdifference(self, other):
- return self.BTreeAPI.difference(other, self.set)
+ return self.family.IF.difference(other, self.set)
def __iter__(self):
return iter(self.set)
@@ -106,8 +108,8 @@
class FilterExtent(Extent):
interface.implements(interfaces.IFilterExtent)
- def __init__(self, filter):
- super(FilterExtent, self).__init__()
+ def __init__(self, filter, family=None):
+ super(FilterExtent, self).__init__(family=family)
self.filter = filter
def add(self, uid, obj):
@@ -122,11 +124,18 @@
class Catalog(catalog.Catalog):
interface.implements(interfaces.IExtentCatalog)
-
+
def __init__(self, extent):
+ """Construct a catalog based on an extent.
+
+ Note that the `family` keyword parameter of the base class
+ constructor is not supported here; the family of the extent is
+ used.
+
+ """
if extent.__parent__ is not None:
raise ValueError("extent's __parent__ must be None")
- super(Catalog, self).__init__()
+ super(Catalog, self).__init__(family=extent.family)
self.extent = extent
extent.__parent__ = self # inform extent of catalog
Modified: zc.catalog/trunk/src/zc/catalog/extentcatalog.txt
===================================================================
--- zc.catalog/trunk/src/zc/catalog/extentcatalog.txt 2007-04-27 14:25:49 UTC (rev 74858)
+++ zc.catalog/trunk/src/zc/catalog/extentcatalog.txt 2007-04-27 14:59:52 UTC (rev 74859)
@@ -19,9 +19,7 @@
>>> root = makeRoot()
>>> intid = zope.component.getUtility(
... zope.app.intid.interfaces.IIntIds, context=root)
- >>> TreeSet = component.queryUtility(zope.component.interfaces.IFactory,
- ... name="IFTreeSet",
- ... default=BTrees.IFBTree.IFTreeSet)
+ >>> TreeSet = btrees_family.IF.TreeSet
>>> from zope.app.container.interfaces import IContained
>>> class DummyIndex(persistent.Persistent):
@@ -43,7 +41,7 @@
... self.__parent__ = parent
...
- >>> extent = extentcatalog.Extent()
+ >>> extent = extentcatalog.Extent(family=btrees_family)
>>> verify.verifyObject(interfaces.IExtent, extent)
True
>>> root['catalog'] = catalog = extentcatalog.Catalog(extent)
@@ -125,7 +123,7 @@
can be spelled "data - extent". Unions and intersections are
weighted.
- >>> extent = extentcatalog.Extent()
+ >>> extent = extentcatalog.Extent(family=btrees_family)
>>> for i in range(1, 100, 2):
... extent.add(i, None)
...
@@ -179,7 +177,7 @@
... # True ignore attribute
... return uid % 2 and not getattr(ob, 'ignore', False)
...
- >>> extent = extentcatalog.FilterExtent(filter)
+ >>> extent = extentcatalog.FilterExtent(filter, family=btrees_family)
>>> verify.verifyObject(interfaces.IFilterExtent, extent)
True
>>> root['catalog1'] = catalog = extentcatalog.Catalog(extent)
@@ -310,7 +308,7 @@
>>> def accept_any(extent, uid, ob):
... return True
- >>> extent = PopulatingExtent(accept_any)
+ >>> extent = PopulatingExtent(accept_any, family=btrees_family)
>>> catalog = extentcatalog.Catalog(extent)
>>> index = DummyIndex()
>>> catalog['index'] = index
@@ -373,7 +371,7 @@
When we have fresh catalog and extent (not yet populated), we see that
`updateIndexes()` will cause the extent to be populated::
- >>> extent = PopulatingExtent(accept_any)
+ >>> extent = PopulatingExtent(accept_any, family=btrees_family)
>>> root['catalog3'] = catalog = extentcatalog.Catalog(extent)
>>> index1 = DummyIndex()
>>> index2 = DummyIndex()
@@ -448,7 +446,7 @@
... zope.component.persistentregistry.PersistentComponents())
... site_manager.__bases__ = (zope.component.getGlobalSiteManager(),)
... site_manager.registerUtility(
- ... zope.app.intid.IntIds(),
+ ... zope.app.intid.IntIds(family=btrees_family),
... provided=zope.app.intid.interfaces.IIntIds)
... setSiteManager(site_manager)
... transaction.commit()
Modified: zc.catalog/trunk/src/zc/catalog/tests.py
===================================================================
--- zc.catalog/trunk/src/zc/catalog/tests.py 2007-04-27 14:25:49 UTC (rev 74858)
+++ zc.catalog/trunk/src/zc/catalog/tests.py 2007-04-27 14:59:52 UTC (rev 74859)
@@ -31,64 +31,62 @@
import BTrees.LFBTree
-def modSetUp(test):
+def setUp32bit(test):
zope.component.testing.setUp(test)
+ test.globs["btrees_family"] = BTrees.family32
+
+def modSetUp32bit(test):
+ setUp32bit(test)
module.setUp(test, 'zc.catalog.doctest_test')
-def modTearDown(test):
- module.tearDown(test)
- zope.component.testing.tearDown(test)
-
-
def setUp64bit(test):
zope.component.testing.setUp(test)
- zope.component.provideUtility(
- zope.component.factory.Factory(BTrees.LOBTree.LOBTree),
- name='IOBTree')
- zope.component.provideUtility(
- zope.component.factory.Factory(BTrees.OLBTree.OLBTree),
- name='OIBTree')
- zope.component.provideUtility(
- zope.component.factory.Factory(BTrees.LFBTree.LFTreeSet),
- name='IFTreeSet')
+ test.globs["btrees_family"] = BTrees.family64
-
-def tearDown64bit(test):
- zope.component.testing.tearDown(test)
-
-
def modSetUp64bit(test):
setUp64bit(test)
module.setUp(test, 'zc.catalog.doctest_test')
+def tearDown(test):
+ zope.component.testing.tearDown(test)
+def modTearDown(test):
+ module.tearDown(test)
+ zope.component.testing.tearDown(test)
+
+
def test_suite():
tests = unittest.TestSuite((
# 32 bits
doctest.DocFileSuite(
- 'extentcatalog.txt', setUp=modSetUp, tearDown=modTearDown,
+ 'extentcatalog.txt', setUp=modSetUp32bit, tearDown=modTearDown,
optionflags=doctest.INTERPRET_FOOTNOTES),
doctest.DocFileSuite(
- 'setindex.txt', optionflags=doctest.INTERPRET_FOOTNOTES),
- doctest.DocFileSuite('valueindex.txt'),
- doctest.DocFileSuite('normalizedindex.txt'),
- doctest.DocFileSuite('globber.txt'),
- doctest.DocFileSuite('callablewrapper.txt'),
+ 'setindex.txt', setUp=setUp32bit, tearDown=tearDown,
+ optionflags=doctest.INTERPRET_FOOTNOTES),
+ doctest.DocFileSuite(
+ 'valueindex.txt', setUp=setUp32bit, tearDown=tearDown),
+ doctest.DocFileSuite(
+ 'normalizedindex.txt', setUp=setUp32bit, tearDown=tearDown),
+ doctest.DocFileSuite(
+ 'globber.txt', setUp=setUp32bit, tearDown=tearDown),
+ doctest.DocFileSuite(
+ 'callablewrapper.txt', setUp=setUp32bit, tearDown=tearDown),
# 64 bits
doctest.DocFileSuite(
- 'extentcatalog.txt', setUp=modSetUp64bit, tearDown=tearDown64bit,
+ 'extentcatalog.txt', setUp=modSetUp64bit, tearDown=modTearDown,
optionflags=doctest.INTERPRET_FOOTNOTES),
doctest.DocFileSuite('setindex.txt', setUp=setUp64bit,
- tearDown=tearDown64bit),
+ tearDown=tearDown),
doctest.DocFileSuite('valueindex.txt', setUp=setUp64bit,
- tearDown=tearDown64bit),
+ tearDown=tearDown),
doctest.DocFileSuite('normalizedindex.txt', setUp=setUp64bit,
- tearDown=tearDown64bit),
+ tearDown=tearDown),
doctest.DocFileSuite('globber.txt', setUp=setUp64bit,
- tearDown=tearDown64bit),
+ tearDown=tearDown),
doctest.DocFileSuite('callablewrapper.txt', setUp=setUp64bit,
- tearDown=tearDown64bit),
+ tearDown=tearDown),
))
import zc.catalog.stemmer
if not zc.catalog.stemmer.broken:
More information about the Checkins
mailing list