[Zope3-checkins] CVS: Zope3/src/zope/app/services - cache.py:1.8 configuration.py:1.22 connection.py:1.10 service.py:1.17 utility.py:1.4
Guido van Rossum
guido@python.org
Mon, 28 Apr 2003 11:21:09 -0400
Update of /cvs-repository/Zope3/src/zope/app/services
In directory cvs.zope.org:/tmp/cvs-serv10913
Modified Files:
cache.py configuration.py connection.py service.py utility.py
Log Message:
Instead of copying and pasting essentially the same code into ever more
configuration implementations, add the {add,remove}Usage call to the
{afterAdd,beforeDelete}Hook methods in ComponentConfiguration.
=== Zope3/src/zope/app/services/cache.py 1.7 => 1.8 ===
--- Zope3/src/zope/app/services/cache.py:1.7 Thu Apr 24 17:01:26 2003
+++ Zope3/src/zope/app/services/cache.py Mon Apr 28 11:21:08 2003
@@ -120,17 +120,3 @@
def getInterface(self):
return ICache
-
- def afterAddHook(self, configuration, container):
- super(CacheConfiguration, self).afterAddHook(configuration,
- container)
- component = configuration.getComponent()
- adapter = getAdapter(component, IUseConfiguration)
- adapter.addUsage(getPath(configuration))
-
- def beforeDeleteHook(self, configuration, container):
- component = configuration.getComponent()
- adapter = getAdapter(component, IUseConfiguration)
- adapter.removeUsage(getPath(configuration))
- super(CacheConfiguration, self).beforeDeleteHook(configuration,
- container)
=== Zope3/src/zope/app/services/configuration.py 1.21 => 1.22 ===
--- Zope3/src/zope/app/services/configuration.py:1.21 Tue Apr 8 08:21:38 2003
+++ Zope3/src/zope/app/services/configuration.py Mon Apr 28 11:21:08 2003
@@ -44,7 +44,7 @@
from zope.app.interfaces.services.configuration import Registered, Active
from zope.app.traversing import getRoot, getPath, traverse
from zope.app.traversing import canonicalPath
-from zope.component import getAdapter
+from zope.component import getAdapter, queryAdapter
from zope.component import getService, queryService, getServiceManager
from zope.proxy.context import ContextMethod, ContextWrapper
from zope.proxy.context import ContextDescriptor
@@ -389,6 +389,10 @@
dependents = getAdapter(component, IDependable)
objectpath = getPath(configuration)
dependents.addDependent(objectpath)
+ # Also update usage, if supported
+ adapter = queryAdapter(component, IUseConfiguration)
+ if adapter is not None:
+ adapter.addUsage(getPath(configuration))
def beforeDeleteHook(self, configuration, container):
"See IDeleteNotifiable"
@@ -398,7 +402,10 @@
dependents = getAdapter(component, IDependable)
objectpath = getPath(configuration)
dependents.removeDependent(objectpath)
-
+ # Also update usage, if supported
+ adapter = queryAdapter(component, IUseConfiguration)
+ if adapter is not None:
+ adapter.removeUsage(getPath(configuration))
class NamedComponentConfiguration(NamedConfiguration, ComponentConfiguration):
"""Configurations for named components.
=== Zope3/src/zope/app/services/connection.py 1.9 => 1.10 ===
--- Zope3/src/zope/app/services/connection.py:1.9 Wed Apr 23 17:03:37 2003
+++ Zope3/src/zope/app/services/connection.py Mon Apr 28 11:21:08 2003
@@ -92,25 +92,3 @@
def getInterface(self):
return IZopeDatabaseAdapter
-
- def afterAddHook(self, configuration, container):
- """Hook method will call after an object is added to container.
-
- Defined in IAddNotifiable.
- """
- super(ConnectionConfiguration, self).afterAddHook(configuration,
- container)
- utility = configuration.getComponent()
- adapter = getAdapter(utility, IUseConfiguration)
- adapter.addUsage(getPath(configuration))
-
- def beforeDeleteHook(self, configuration, container):
- """Hook method will call before object is removed from container.
-
- Defined in IDeleteNotifiable.
- """
- utility = configuration.getComponent()
- adapter = getAdapter(utility, IUseConfiguration)
- adapter.removeUsage(getPath(configuration))
- super(ConnectionConfiguration, self).beforeDeleteHook(configuration,
- container)
=== Zope3/src/zope/app/services/service.py 1.16 => 1.17 ===
--- Zope3/src/zope/app/services/service.py:1.16 Mon Mar 24 06:09:39 2003
+++ Zope3/src/zope/app/services/service.py Mon Apr 28 11:21:08 2003
@@ -341,19 +341,3 @@
def usageSummary(self):
return self.name + " Service"
-
- def afterAddHook(self, configuration, container):
- NamedComponentConfiguration.afterAddHook(self,
- configuration,
- container)
- service = configuration.getComponent()
- adapter = getAdapter(service, IUseConfiguration)
- adapter.addUsage(getPath(configuration))
-
- def beforeDeleteHook(self, configuration, container):
- service = configuration.getComponent()
- adapter = getAdapter(service, IUseConfiguration)
- adapter.removeUsage(getPath(configuration))
- NamedComponentConfiguration.beforeDeleteHook(self,
- configuration,
- container)
=== Zope3/src/zope/app/services/utility.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/services/utility.py:1.3 Thu Apr 3 17:05:34 2003
+++ Zope3/src/zope/app/services/utility.py Mon Apr 28 11:21:08 2003
@@ -130,30 +130,5 @@
# ComponentConfiguration calls this when you specify a
# permission; it needs the interface to create a security
# proxy for the interface with the given permission.
+ # XXX Smells like a dead chicken to me.
return self.interface
-
- # The following hooks are called only if we implement
- # IAddNotifiable and IDeleteNotifiable.
-
- def afterAddHook(self, configuration, container):
- """Hook method will call after an object is added to container.
-
- Defined in IAddNotifiable.
- """
- super(UtilityConfiguration, self).afterAddHook(configuration,
- container)
- utility = configuration.getComponent()
- adapter = getAdapter(utility, IUseConfiguration)
- adapter.addUsage(getPath(configuration))
-
- def beforeDeleteHook(self, configuration, container):
- """Hook method will call before object is removed from container.
-
- Defined in IDeleteNotifiable.
- """
- utility = configuration.getComponent()
- adapter = getAdapter(utility, IUseConfiguration)
- adapter.removeUsage(getPath(configuration))
- super(UtilityConfiguration, self).beforeDeleteHook(configuration,
- container)
-