[Checkins] SVN: zope.app.container/trunk/ new bootstrap, store length in btree containers, version bump to 3.5

Bernd Dorn bernd.dorn at lovelysystems.com
Fri Jun 29 05:20:15 EDT 2007


Log message for revision 77225:
  new bootstrap, store length in btree containers, version bump to 3.5

Changed:
  U   zope.app.container/trunk/CHANGES.txt
  U   zope.app.container/trunk/bootstrap.py
  U   zope.app.container/trunk/setup.py
  U   zope.app.container/trunk/src/zope/app/container/btree.py
  U   zope.app.container/trunk/src/zope/app/container/tests/test_btree.py

-=-
Modified: zope.app.container/trunk/CHANGES.txt
===================================================================
--- zope.app.container/trunk/CHANGES.txt	2007-06-29 07:00:26 UTC (rev 77224)
+++ zope.app.container/trunk/CHANGES.txt	2007-06-29 09:20:13 UTC (rev 77225)
@@ -1,2 +1,11 @@
-zope.app.apidoc Package Changelog
-=================================
+Changes for zope.app.container
+==============================
+
+Version 3.5.0a1
+===============
+
+- updated bootstrap to current version
+
+- Store length of BTreeContainer in its own Length object for faster
+  __len__ implementation of huge containers.
+

Modified: zope.app.container/trunk/bootstrap.py
===================================================================
--- zope.app.container/trunk/bootstrap.py	2007-06-29 07:00:26 UTC (rev 77224)
+++ zope.app.container/trunk/bootstrap.py	2007-06-29 09:20:13 UTC (rev 77225)
@@ -24,12 +24,15 @@
 
 tmpeggs = tempfile.mkdtemp()
 
-ez = {}
-exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
-                     ).read() in ez
-ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+try:
+    import pkg_resources
+except ImportError:
+    ez = {}
+    exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+                         ).read() in ez
+    ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
 
-import pkg_resources
+    import pkg_resources
 
 cmd = 'from setuptools.command.easy_install import main; main()'
 if sys.platform == 'win32':
@@ -50,3 +53,4 @@
 import zc.buildout.buildout
 zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
 shutil.rmtree(tmpeggs)
+

Modified: zope.app.container/trunk/setup.py
===================================================================
--- zope.app.container/trunk/setup.py	2007-06-29 07:00:26 UTC (rev 77224)
+++ zope.app.container/trunk/setup.py	2007-06-29 09:20:13 UTC (rev 77225)
@@ -21,7 +21,7 @@
 from setuptools import setup, find_packages, Extension
 
 setup(name='zope.app.container',
-      version = '3.4.0b1',
+      version = '3.5.0a1',
       url='http://svn.zope.org/zope.app.container',
       license='ZPL 2.1',
       description='Zope container',

Modified: zope.app.container/trunk/src/zope/app/container/btree.py
===================================================================
--- zope.app.container/trunk/src/zope/app/container/btree.py	2007-06-29 07:00:26 UTC (rev 77224)
+++ zope.app.container/trunk/src/zope/app/container/btree.py	2007-06-29 09:20:13 UTC (rev 77225)
@@ -24,7 +24,10 @@
 
 from persistent import Persistent
 from BTrees.OOBTree import OOBTree
+from BTrees.Length import Length
+
 from zope.app.container.sample import SampleContainer
+from zope.cachedescriptors.property import Lazy
 
 class BTreeContainer(SampleContainer, Persistent):
 
@@ -36,6 +39,10 @@
     # operations on the BTree itself.  It would probably be clearer to
     # just delegate those methods directly to the btree.
 
+    def __init__(self):
+        super(BTreeContainer, self).__init__()
+        self.__len = Length()
+
     def _newContainerData(self):
         """Construct an item-data container
 
@@ -63,5 +70,32 @@
         '''
         return key in self._SampleContainer__data
 
+    @Lazy
+    def _BTreeContainer__len(self):
+        import logging
+        log = logging.getLogger('zope.app.container.btree')
+        l=Length()
+        ol = super(BTreeContainer, self).__len__()
+        if ol>0:
+            l.change(ol)
+        self._p_changed=True
+        log.info("Storing length of %r" % self)
+        return l
+
+    def __len__(self):
+        #import pdb;pdb.set_trace()
+        return self.__len()
+
+    def __setitem__(self, key, value):
+        # make sure our lazy property gets set
+        l = self.__len
+        super(BTreeContainer, self).__setitem__(key, value)
+        l.change(1)
+
+    def __delitem__(self, key):
+        # make sure our lazy property gets set
+        l = self.__len
+        super(BTreeContainer, self).__delitem__(key)
+        l.change(-1)
+
     has_key = __contains__
-        

Modified: zope.app.container/trunk/src/zope/app/container/tests/test_btree.py
===================================================================
--- zope.app.container/trunk/src/zope/app/container/tests/test_btree.py	2007-06-29 07:00:26 UTC (rev 77224)
+++ zope.app.container/trunk/src/zope/app/container/tests/test_btree.py	2007-06-29 09:20:13 UTC (rev 77225)
@@ -19,17 +19,32 @@
 from zope.testing.doctestunit import DocTestSuite
 from zope.app.testing import placelesssetup
 from test_icontainer import TestSampleContainer
+from zope.app.container.btree import BTreeContainer
 
 class TestBTreeContainer(TestSampleContainer, TestCase):
 
     def makeTestObject(self):
-        from zope.app.container.btree import BTreeContainer
         return BTreeContainer()
 
+class TestBTreeLength(TestCase):
 
+    def testStoredLength(self):
+        #This is lazy for backward compatibility. If the len is not
+        #stored already we set it to the length of the underlying
+        #btree.
+        bc = BTreeContainer()
+        self.assertEqual(bc.__dict__['_BTreeContainer__len'](), 0)
+        del bc.__dict__['_BTreeContainer__len']
+        self.failIf(bc.__dict__.has_key('_BTreeContainer__len'))
+        bc['1'] = 1
+        self.assertEqual(len(bc), 1)
+        self.assertEqual(bc.__dict__['_BTreeContainer__len'](), 1)
+
+
 def test_suite():
     return TestSuite((
         makeSuite(TestBTreeContainer),
+        makeSuite(TestBTreeLength),
         DocTestSuite('zope.app.container.btree',
                      setUp=placelesssetup.setUp,
                      tearDown=placelesssetup.tearDown),



More information about the Checkins mailing list