[Zope3-checkins] CVS: Zope3/src/zope/app/services - configuration.py:1.6.4.1
Tim Peters
tim.one@comcast.net
Mon, 24 Feb 2003 15:33:29 -0500
Update of /cvs-repository/Zope3/src/zope/app/services
In directory cvs.zope.org:/tmp/cvs-serv31957/src/zope/app/services
Modified Files:
Tag: use-config-branch
configuration.py
Log Message:
New interface IUseConfiguration and new adapter UseConfiguration, for
a project that will become clearer later.
=== Zope3/src/zope/app/services/configuration.py 1.6 => 1.6.4.1 ===
--- Zope3/src/zope/app/services/configuration.py:1.6 Thu Jan 16 07:00:00 2003
+++ Zope3/src/zope/app/services/configuration.py Mon Feb 24 15:32:58 2003
@@ -21,6 +21,7 @@
from zope.app.interfaces.services.configuration import IConfigurationRegistry
from zope.app.interfaces.services.configuration \
import INamedComponentConfiguration, INameConfigurable
+from zope.app.interfaces.services.configuration import IUseConfiguration
from zope.app.interfaces.services.configuration \
import INameComponentConfigurable, INamedConfiguration, IConfiguration
from zope.component import getService, queryService
@@ -39,6 +40,7 @@
from zope.app.traversing import getPhysicalRoot
from zope.app.interfaces.services.configuration \
import Unregistered, Registered, Active
+from zope.app.interfaces.annotation import IAnnotations
class ConfigurationStatusProperty:
@@ -272,7 +274,7 @@
try:
objectpath = getPhysicalPathString(configuration)
except: # XXX
- objectpath = str(configuration)
+ objectpath = str(configuration)
raise DependencyError("Can't delete active configuration (%s)"
% objectpath)
elif objectstatus == Registered:
@@ -416,3 +418,29 @@
return configuration.getComponent()
return default
queryActiveComponent = ContextMethod(queryActiveComponent)
+
+
+USE_CONFIG_KEY = 'zope.app.services.UseConfiguration'
+
+class UseConfiguration:
+ """An adapter."""
+
+ __implements__ = IUseConfiguration
+
+ def __init__(self, context):
+ self.context = context
+
+ def addUsage(self, location):
+ annotations = getAdapter(self.context, IAnnotations)
+ annotations[USE_CONFIG_KEY] = (annotations.get(USE_CONFIG_KEY, ()) +
+ (location, ))
+
+ def removeUsage(self, location):
+ annotations = getAdapter(self.context, IAnnotations)
+ locs = [loc for loc in annotations.get(USE_CONFIG_KEY, ())
+ if loc != location]
+ annotations[USE_CONFIG_KEY] = tuple(locs)
+
+ def usages(self):
+ annotations = getAdapter(self.context, IAnnotations)
+ return annotations.get(USE_CONFIG_KEY, ())