[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/CachingService - CachingService.py:1.3

Albertas Agejevas alga@codeworks.lt
Fri, 6 Dec 2002 13:04:01 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Services/CachingService
In directory cvs.zope.org:/tmp/cvs-serv32707/lib/python/Zope/App/OFS/Services/CachingService

Modified Files:
	CachingService.py 
Log Message:
Make CachingService an EventChannel.
On the way made LocalServiceSubscribable work when there is no next service.


=== Zope3/lib/python/Zope/App/OFS/Services/CachingService/CachingService.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/App/OFS/Services/CachingService/CachingService.py:1.2	Fri Dec  6 06:01:11 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/CachingService/CachingService.py	Fri Dec  6 13:03:31 2002
@@ -16,18 +16,17 @@
 $Id$
 """
 from types import TupleType
-
+from Zope.App.Caching.ICache import ICache
+from Zope.App.Caching.ICachingService import ICachingService
 from Zope.App.ComponentArchitecture.NextService import queryNextService
-from Zope.ContextWrapper import ContextMethod
-
-from Zope.App.OFS.Container.IContainer import IHomogenousContainer, IContainer
 from Zope.App.OFS.Container.BTreeContainer import BTreeContainer
-
-from Zope.Event.IEventChannel import IEventChannel
+from Zope.App.OFS.Container.IContainer import IHomogenousContainer, IContainer
+from Zope.App.OFS.Services.LocalEventService.ProtoServiceEventChannel \
+     import ProtoServiceEventChannel
+from Zope.ContextWrapper import ContextMethod
 from Zope.Event.EventChannel import EventChannel
-
-from Zope.App.Caching.ICachingService import ICachingService
-from Zope.App.Caching.ICache import ICache
+from Zope.Event.IEventChannel import IEventChannel
+from Zope.Event.IObjectEvent import IObjectModifiedEvent
 
 
 class ILocalCachingService(ICachingService, IContainer,
@@ -36,13 +35,19 @@
     """TTW manageable caching service"""
 
 
-class CachingService(BTreeContainer, EventChannel):
+class CachingService(BTreeContainer, ProtoServiceEventChannel):
+
+    __implements__ = ILocalCachingService, ProtoServiceEventChannel.__implements__
 
-    __implements__ = ILocalCachingService
+    _subscribeToServiceInterface = IObjectModifiedEvent
 
     def __init__(self):
         BTreeContainer.__init__(self)
-        EventChannel.__init__(self)
+        ProtoServiceEventChannel.__init__(self)
+
+    def __nonzero__(self):
+        # XXX otherwise 'if service:' in getService() fails when len(service) == 0
+        return 1
 
     def getCache(self, name):
         'See Zope.App.Caching.ICachingService.ICachingService'
@@ -71,3 +76,13 @@
         if ICache in interfaces:
             return 1
         return 0
+
+    def setObject(self, key, object):
+        "See Zope.App.OFS.Container.IContainer.IWriteContainer"
+        self.subscribe(object, IObjectModifiedEvent)
+        BTreeContainer.setObject(self, key, object)
+
+    def __delitem__(self, key):
+        "See Zope.App.OFS.Container.IContainer.IWriteContainer"
+        self.unsubscribe(self[key], IObjectModifiedEvent)
+        BTreeContainer.__delitem__(self, key)