[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/locking/ add an
ISized adapter for lock storages
Fred L. Drake, Jr.
fdrake at gmail.com
Tue Jul 26 11:37:20 EDT 2005
Log message for revision 37429:
add an ISized adapter for lock storages
Changed:
U Zope3/trunk/src/zope/app/locking/configure.zcml
U Zope3/trunk/src/zope/app/locking/storage.py
-=-
Modified: Zope3/trunk/src/zope/app/locking/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/locking/configure.zcml 2005-07-26 14:10:24 UTC (rev 37428)
+++ Zope3/trunk/src/zope/app/locking/configure.zcml 2005-07-26 15:37:18 UTC (rev 37429)
@@ -18,6 +18,18 @@
</configure>
<adapter
+ factory=".storage.Sized"
+ trusted="yes"
+ />
+
+ <class class=".storage.Sized">
+ <require
+ permission="zope.Public"
+ interface="zope.app.size.interfaces.ISized"
+ />
+ </class>
+
+ <adapter
for="*"
factory=".adapter.LockingPathAdapter"
name="locking"
Modified: Zope3/trunk/src/zope/app/locking/storage.py
===================================================================
--- Zope3/trunk/src/zope/app/locking/storage.py 2005-07-26 14:10:24 UTC (rev 37428)
+++ Zope3/trunk/src/zope/app/locking/storage.py 2005-07-26 15:37:18 UTC (rev 37429)
@@ -24,13 +24,17 @@
from BTrees.OOBTree import OOBTree
from BTrees.IOBTree import IOBTree
+import zope.component
import zope.interface
from zope.app.keyreference.interfaces import IKeyReference
from zope.app.locking.interfaces import ILockTracker
from zope.app.locking.interfaces import LockingError
+from zope.app.size.interfaces import ISized
+from zope.app.i18n import ZopeMessageIDFactory as _
+
timefunc = time.time
@@ -139,6 +143,43 @@
del self.timeouts[key]
+class Sized(object):
+
+ zope.interface.implements(ISized)
+ zope.component.adapts(ILockStorage)
+
+ def __init__(self, context):
+ import sys
+ print >>sys.__stderr__, "sized:", repr(context)
+ self.context = context
+
+ def sizeForSorting(self):
+ return ('item', self._get_size())
+
+ def sizeForDisplay(self):
+ import sys
+ print >>sys.__stderr__, "sizeForDisplay:", repr(self.context)
+ num_items = self._get_size()
+ print >>sys.__stderr__, "sizeForDisplay:", num_items, repr(self.context)
+ if num_items == 1:
+ return _('1 item')
+ size = _('${items} items')
+ size.mapping = {'items': str(num_items)}
+ return size
+
+ def _get_size(self):
+ # We only want to include active locks, so we'd like to simply
+ # call `cleanup()`, but we also don't want to cause the
+ # transaction to write, so we adjust the count instead.
+
+ nlocks = len(self.context.locks)
+ for key in self.context.timeouts.keys(max=int(timefunc())):
+ for keyref in self.context.timeouts[key]:
+ if self.context.locks.get(keyref, None) is not None:
+ nlocks -= 1
+ return nlocks
+
+
class PersistentLockStorage(persistent.Persistent, LockStorage):
"""LockStorage that isn't fickle."""
More information about the Zope3-Checkins
mailing list