[Checkins] SVN: zope.bforest/trunk/src/zope/bforest/ period ->
periodic
Gary Poster
gary at zope.com
Tue Sep 12 16:00:32 EDT 2006
Log message for revision 70134:
period -> periodic
Changed:
D zope.bforest/trunk/src/zope/bforest/period.py
D zope.bforest/trunk/src/zope/bforest/period.txt
A zope.bforest/trunk/src/zope/bforest/periodic.py
A zope.bforest/trunk/src/zope/bforest/periodic.txt
U zope.bforest/trunk/src/zope/bforest/tests.py
-=-
Deleted: zope.bforest/trunk/src/zope/bforest/period.py
===================================================================
--- zope.bforest/trunk/src/zope/bforest/period.py 2006-09-12 18:23:20 UTC (rev 70133)
+++ zope.bforest/trunk/src/zope/bforest/period.py 2006-09-12 20:00:31 UTC (rev 70134)
@@ -1,60 +0,0 @@
-import datetime
-from BTrees import IOBTree, OOBTree, OIBTree, IIBTree
-from zope.bforest import bforest, utils
-
-def mutating(name):
- def mutate(self, *args, **kwargs):
- if (datetime.datetime.now(utils.UTC) -
- self.last_rotation) >= self._inner_period:
- self.rotateBucket()
- return getattr(super(Abstract, self), name)(*args, **kwargs)
- return mutate
-
-class Abstract(bforest.AbstractBForest):
- def __init__(self, period, d=None, count=2):
- super(Abstract, self).__init__(d, count)
- self.period = period
- self.last_rotation = datetime.datetime.now(utils.UTC)
-
- _inner_period = _period = None
- def period(self, value):
- self._period = value
- self._inner_period = self._period / len(self.buckets)
- period = property(
- lambda self: self._period, period)
-
- def copy(self):
- # this makes an exact copy, including the individual state of each
- # bucket. If you want a dict, cast it to a dict, or if you want
- # another one of these but with all of the keys in the first bucket,
- # call obj.__class__(obj)
- copy = self.__class__(self.period, count=len(self.buckets))
- for i in range(len(self.buckets)):
- copy.buckets[i].update(self.buckets[i])
- return copy
-
- def rotateBucket(self):
- super(Abstract, self).rotateBucket()
- self.last_rotation = datetime.datetime.now(utils.UTC)
-
- __setitem__ = mutating('__setitem__')
- __delitem__ = mutating('__delitem__')
- pop = mutating('pop')
- popitem = mutating('popitem')
- update = mutating('update')
-
-class IOBForest(Abstract):
- _treemodule = IOBTree
- _treeclass = IOBTree.IOBTree
-
-class OIBForest(Abstract):
- _treemodule = OIBTree
- _treeclass = OIBTree.OIBTree
-
-class OOBForest(Abstract):
- _treemodule = OOBTree
- _treeclass = OOBTree.OOBTree
-
-class IIBForest(Abstract):
- _treemodule = IIBTree
- _treeclass = IIBTree.IIBTree
Deleted: zope.bforest/trunk/src/zope/bforest/period.txt
===================================================================
--- zope.bforest/trunk/src/zope/bforest/period.txt 2006-09-12 18:23:20 UTC (rev 70133)
+++ zope.bforest/trunk/src/zope/bforest/period.txt 2006-09-12 20:00:31 UTC (rev 70134)
@@ -1,87 +0,0 @@
-The bforests in the period module have simple policies for automatic
-tree rotation based on time. Each take one additional argument beyond
-the usual bforest initialization: period. This is effectively the
-minimum amount of time a given value will be kept in the bforest.
-
-For example, consider a period bforest with three trees and a period of three
-hours.
-
-As with normal bforests, period bforests come in four flavors:
-Integer-Integer (IIBForest), Integer-Object (IOBForest), Object-Integer
-(OIBForest), and Object-Object (OOBForest). The examples here will deal
-with them in the abstract: we will create classes from the imaginary and
-representative BForest class, and generate keys from KeyGenerator and
-values from ValueGenerator. From the examples you should be able to
-extrapolate usage of all four types.
-
-We will also imagine that we control the time with a function called setNow.
-
- >>> import datetime
- >>> from zope.bforest import utils
- >>> setNow(datetime.datetime(2006, 9, 11, 22, 51, tzinfo=utils.UTC))
- >>> d = BForest(datetime.timedelta(hours=3), count=3)
- >>> d.last_rotation
- datetime.datetime(2006, 9, 11, 22, 51, tzinfo=<UTC>)
-
-Now let's put in some keys and advance time.
-
- >>> first_hour = {KeyGenerator(): ValueGenerator()}
- >>> d.update(first_hour)
- >>> setNow(datetime.datetime.now(utils.UTC) + datetime.timedelta(hours=1))
- >>> second_hour = {KeyGenerator(): ValueGenerator()}
- >>> d.update(second_hour)
- >>> setNow(datetime.datetime.now(utils.UTC) + datetime.timedelta(hours=1))
- >>> third_hour = {KeyGenerator(): ValueGenerator()}
- >>> d.update(third_hour)
- >>> current = first_hour.copy()
- >>> current.update(second_hour)
- >>> current.update(third_hour)
- >>> d == current
- True
- >>> setNow(datetime.datetime.now(utils.UTC) + datetime.timedelta(hours=1))
- >>> d == current
- True
- >>> fourth_hour = {KeyGenerator(): ValueGenerator()}
- >>> d.update(fourth_hour)
- >>> current.update(fourth_hour)
- >>> del current[first_hour.keys()[0]]
- >>> d == current
- True
-
-Updating isn't the only way to rotate the trees though. Basically
-any non-clear mutating operation will cause a rotation: __setitem__,
-update, __delitem__, pop, and popitem. We've seen update; here are examples
-of the rest.
-
- >>> setNow(datetime.datetime.now(utils.UTC) + datetime.timedelta(hours=1))
- >>> fifth_hour = {KeyGenerator(): ValueGenerator()}
- >>> d[fifth_hour.keys()[0]] = fifth_hour.values()[0] # __setitem__
- >>> current.update(fifth_hour)
- >>> del current[second_hour.keys()[0]]
- >>> d == current
- True
- >>> setNow(datetime.datetime.now(utils.UTC) + datetime.timedelta(hours=1))
- >>> del d[fifth_hour.keys()[0]] # __delitem__
- >>> d == fourth_hour
- True
- >>> sixth_hour = {KeyGenerator(): ValueGenerator()}
- >>> d[sixth_hour.keys()[0]] = sixth_hour.values()[0]
- >>> setNow(datetime.datetime.now(utils.UTC) + datetime.timedelta(hours=1))
- >>> d.pop(sixth_hour.keys()[0]) == sixth_hour.values()[0] # pop
- True
- >>> d == {}
- True
- >>> seventh_hour = {KeyGenerator(): ValueGenerator()}
- >>> d[seventh_hour.keys()[0]] = seventh_hour.values()[0]
- >>> setNow(datetime.datetime.now(utils.UTC) + datetime.timedelta(hours=1))
- >>> d.rotateBucket()
- >>> setNow(datetime.datetime.now(utils.UTC) + datetime.timedelta(hours=1))
- >>> ninth_hour = {KeyGenerator(): ValueGenerator()}
- >>> d[ninth_hour.keys()[0]] = ninth_hour.values()[0]
- >>> setNow(datetime.datetime.now(utils.UTC) + datetime.timedelta(hours=1))
- >>> out = dict((d.popitem(),))
- >>> out == ninth_hour
- True
- >>> d == {}
- True
-
Copied: zope.bforest/trunk/src/zope/bforest/periodic.py (from rev 70133, zope.bforest/trunk/src/zope/bforest/period.py)
Copied: zope.bforest/trunk/src/zope/bforest/periodic.txt (from rev 70133, zope.bforest/trunk/src/zope/bforest/period.txt)
===================================================================
--- zope.bforest/trunk/src/zope/bforest/period.txt 2006-09-12 18:23:20 UTC (rev 70133)
+++ zope.bforest/trunk/src/zope/bforest/periodic.txt 2006-09-12 20:00:31 UTC (rev 70134)
@@ -0,0 +1,87 @@
+The bforests in the periodic module have simple policies for automatic
+tree rotation based on time. Each take one additional argument beyond
+the usual bforest initialization: period. This is effectively the
+minimum amount of time a given value will be kept in the bforest.
+
+For example, consider a periodic bforest with three trees and a period of three
+hours.
+
+As with normal bforests, periodic bforests come in four flavors:
+Integer-Integer (IIBForest), Integer-Object (IOBForest), Object-Integer
+(OIBForest), and Object-Object (OOBForest). The examples here will deal
+with them in the abstract: we will create classes from the imaginary and
+representative BForest class, and generate keys from KeyGenerator and
+values from ValueGenerator. From the examples you should be able to
+extrapolate usage of all four types.
+
+We will also imagine that we control the time with a function called setNow.
+
+ >>> import datetime
+ >>> from zope.bforest import utils
+ >>> setNow(datetime.datetime(2006, 9, 11, 22, 51, tzinfo=utils.UTC))
+ >>> d = BForest(datetime.timedelta(hours=3), count=3)
+ >>> d.last_rotation
+ datetime.datetime(2006, 9, 11, 22, 51, tzinfo=<UTC>)
+
+Now let's put in some keys and advance time.
+
+ >>> first_hour = {KeyGenerator(): ValueGenerator()}
+ >>> d.update(first_hour)
+ >>> setNow(datetime.datetime.now(utils.UTC) + datetime.timedelta(hours=1))
+ >>> second_hour = {KeyGenerator(): ValueGenerator()}
+ >>> d.update(second_hour)
+ >>> setNow(datetime.datetime.now(utils.UTC) + datetime.timedelta(hours=1))
+ >>> third_hour = {KeyGenerator(): ValueGenerator()}
+ >>> d.update(third_hour)
+ >>> current = first_hour.copy()
+ >>> current.update(second_hour)
+ >>> current.update(third_hour)
+ >>> d == current
+ True
+ >>> setNow(datetime.datetime.now(utils.UTC) + datetime.timedelta(hours=1))
+ >>> d == current
+ True
+ >>> fourth_hour = {KeyGenerator(): ValueGenerator()}
+ >>> d.update(fourth_hour)
+ >>> current.update(fourth_hour)
+ >>> del current[first_hour.keys()[0]]
+ >>> d == current
+ True
+
+Updating isn't the only way to rotate the trees though. Basically
+any non-clear mutating operation will cause a rotation: __setitem__,
+update, __delitem__, pop, and popitem. We've seen update; here are examples
+of the rest.
+
+ >>> setNow(datetime.datetime.now(utils.UTC) + datetime.timedelta(hours=1))
+ >>> fifth_hour = {KeyGenerator(): ValueGenerator()}
+ >>> d[fifth_hour.keys()[0]] = fifth_hour.values()[0] # __setitem__
+ >>> current.update(fifth_hour)
+ >>> del current[second_hour.keys()[0]]
+ >>> d == current
+ True
+ >>> setNow(datetime.datetime.now(utils.UTC) + datetime.timedelta(hours=1))
+ >>> del d[fifth_hour.keys()[0]] # __delitem__
+ >>> d == fourth_hour
+ True
+ >>> sixth_hour = {KeyGenerator(): ValueGenerator()}
+ >>> d[sixth_hour.keys()[0]] = sixth_hour.values()[0]
+ >>> setNow(datetime.datetime.now(utils.UTC) + datetime.timedelta(hours=1))
+ >>> d.pop(sixth_hour.keys()[0]) == sixth_hour.values()[0] # pop
+ True
+ >>> d == {}
+ True
+ >>> seventh_hour = {KeyGenerator(): ValueGenerator()}
+ >>> d[seventh_hour.keys()[0]] = seventh_hour.values()[0]
+ >>> setNow(datetime.datetime.now(utils.UTC) + datetime.timedelta(hours=1))
+ >>> d.rotateBucket()
+ >>> setNow(datetime.datetime.now(utils.UTC) + datetime.timedelta(hours=1))
+ >>> ninth_hour = {KeyGenerator(): ValueGenerator()}
+ >>> d[ninth_hour.keys()[0]] = ninth_hour.values()[0]
+ >>> setNow(datetime.datetime.now(utils.UTC) + datetime.timedelta(hours=1))
+ >>> out = dict((d.popitem(),))
+ >>> out == ninth_hour
+ True
+ >>> d == {}
+ True
+
Modified: zope.bforest/trunk/src/zope/bforest/tests.py
===================================================================
--- zope.bforest/trunk/src/zope/bforest/tests.py 2006-09-12 18:23:20 UTC (rev 70133)
+++ zope.bforest/trunk/src/zope/bforest/tests.py 2006-09-12 20:00:31 UTC (rev 70134)
@@ -18,7 +18,7 @@
import unittest
import datetime
from zope import bforest
-from zope.bforest import period
+from zope.bforest import periodic
from zope.testing import doctest
def StringGenerator(src='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'):
@@ -100,29 +100,29 @@
'ValueGenerator': strgen}))
suite.addTest(
doctest.DocFileSuite(
- 'period.txt',
- globs={'BForest': period.IOBForest,
+ 'periodic.txt',
+ globs={'BForest': periodic.IOBForest,
'KeyGenerator': numgen,
'ValueGenerator': strgen},
setUp=setUp, tearDown=tearDown))
suite.addTest(
doctest.DocFileSuite(
- 'period.txt',
- globs={'BForest': period.OIBForest,
+ 'periodic.txt',
+ globs={'BForest': periodic.OIBForest,
'KeyGenerator': strgen,
'ValueGenerator': numgen},
setUp=setUp, tearDown=tearDown))
suite.addTest(
doctest.DocFileSuite(
- 'period.txt',
- globs={'BForest': period.IIBForest,
+ 'periodic.txt',
+ globs={'BForest': periodic.IIBForest,
'KeyGenerator': numgen,
'ValueGenerator': numgen},
setUp=setUp, tearDown=tearDown))
suite.addTest(
doctest.DocFileSuite(
- 'period.txt',
- globs={'BForest': period.OOBForest,
+ 'periodic.txt',
+ globs={'BForest': periodic.OOBForest,
'KeyGenerator': strgen,
'ValueGenerator': strgen},
setUp=setUp, tearDown=tearDown))
More information about the Checkins
mailing list