[Zope3-checkins] CVS: Zope3/src/zope/app/services - configuration.py:1.17 configure.zcml:1.24 folder.py:1.5 pagefolder.py:1.2
Jim Fulton
jim@zope.com
Sun, 23 Mar 2003 14:25:16 -0500
Update of /cvs-repository/Zope3/src/zope/app/services
In directory cvs.zope.org:/tmp/cvs-serv23262/src/zope/app/services
Modified Files:
configuration.py configure.zcml folder.py pagefolder.py
Log Message:
Refactored support for managing configuration managers by factoring
into separate interfaces and classes so that both site-management
folders and page folders can provide the same bahavior.
=== Zope3/src/zope/app/services/configuration.py 1.16 => 1.17 ===
--- Zope3/src/zope/app/services/configuration.py:1.16 Fri Mar 21 16:05:58 2003
+++ Zope3/src/zope/app/services/configuration.py Sun Mar 23 14:24:46 2003
@@ -35,6 +35,8 @@
from zope.app.interfaces.services.configuration \
import INamedComponentConfiguration, IComponentConfiguration
from zope.app.interfaces.services.configuration import IUseConfiguration
+from zope.app.interfaces.services.configuration \
+ import NoConfigurationManagerError
from zope.app.interfaces.services.configuration import Unregistered
from zope.app.interfaces.services.configuration import Registered, Active
@@ -608,6 +610,44 @@
for k, v in self._data:
del container[k]
+
+class ConfigurationManagerContainer(object):
+ """Mix-in to implement IConfigurationManagerContainer
+ """
+
+ def __init__(self):
+ super(ConfigurationManagerContainer, self).__init__()
+ self.setObject('configure', ConfigurationManager())
+
+ def __delitem__(self, name):
+ """Delete an item, but not if it's the last configuration manager
+ """
+
+ item = self[name]
+ if IConfigurationManager.isImplementedBy(item):
+ # Check to make sure it's not the last one
+ if len([i for i in self.values()
+ if IConfigurationManager.isImplementedBy(i)]) < 2:
+ raise NoConfigurationManagerError(
+ "Can't delete the last configuration manager")
+ super(ConfigurationManagerContainer, self).__delitem__(name)
+
+ def getConfigurationManager(self):
+ """Get a configuration manager
+ """
+
+ # Get the configuration manager for this folder
+ for name in self:
+ item = self[name]
+ if IConfigurationManager.isImplementedBy(item):
+ # We found one. Get it in context
+ return ContextWrapper(item, self, name=name)
+ else:
+ raise NoConfigurationManagerError(
+ "Couldn't find an configuration manager")
+
+ getConfigurationManager = ContextMethod(getConfigurationManager)
+
# XXX Backward Compatibility for pickles
import sys
=== Zope3/src/zope/app/services/configure.zcml 1.23 => 1.24 ===
--- Zope3/src/zope/app/services/configure.zcml:1.23 Sun Mar 23 12:20:48 2003
+++ Zope3/src/zope/app/services/configure.zcml Sun Mar 23 14:24:46 2003
@@ -253,7 +253,8 @@
<require
permission="zope.ManageServices"
interface="zope.app.interfaces.container.IWriteContainer"
- attributes="getConfigurationManager" />
+ attributes="getConfigurationManager"
+ />
<implements
interface="zope.app.interfaces.annotation.IAttributeAnnotatable" />
@@ -310,7 +311,7 @@
interface="zope.app.interfaces.container.IWriteContainer
zope.app.interfaces.services.pagefolder.IPageFolderInfo"
set_schema="zope.app.interfaces.services.pagefolder.IPageFolderInfo"
- attributes="configured"
+ attributes="configured getConfigurationManager"
/>
<implements
interface="zope.app.interfaces.annotation.IAttributeAnnotatable" />
=== Zope3/src/zope/app/services/folder.py 1.4 => 1.5 ===
--- Zope3/src/zope/app/services/folder.py:1.4 Sun Mar 23 13:04:26 2003
+++ Zope3/src/zope/app/services/folder.py Sun Mar 23 14:24:46 2003
@@ -24,48 +24,13 @@
from zope.app.interfaces.services.folder import ISiteManagementFolder
from zope.app.interfaces.services.service import IComponentManager
from zope.app.interfaces.services.service import IServiceManager
-from zope.app.services.configuration import ConfigurationManager
+from zope.app.services.configuration import ConfigurationManagerContainer
from zope.app.traversing import getPath
from zope.proxy.context import ContextMethod, ContextWrapper
-from zope.app.interfaces.services.configuration import IConfigurationManager
-from zope.app.interfaces.services.folder import NoConfigurationManagerError
-class SiteManagementFolder(BTreeContainer):
+class SiteManagementFolder(ConfigurationManagerContainer, BTreeContainer):
__implements__ = ISiteManagementFolder
- def __init__(self):
- super(SiteManagementFolder, self).__init__()
- self.setObject('configure', ConfigurationManager())
-
-
- def __delitem__(self, name):
- """Delete an item, but not if it's the last configuration manager
- """
-
- item = self[name]
- if IConfigurationManager.isImplementedBy(item):
- # Check to make sure it's not the last one
- if len([i for i in self.values()
- if IConfigurationManager.isImplementedBy(i)]) < 2:
- raise NoConfigurationManagerError(
- "Can't delete the last configuration manager")
- BTreeContainer.__delitem__(self, name)
-
- def getConfigurationManager(self):
- """Get a configuration manager
- """
-
- # Get the configuration manager for this folder
- for name in self:
- item = self[name]
- if IConfigurationManager.isImplementedBy(item):
- # We found one. Get it in context
- return ContextWrapper(item, self, name=name)
- else:
- raise NoConfigurationManagerError(
- "Couldn't find an configuration manager")
-
- getConfigurationManager = ContextMethod(getConfigurationManager)
class SiteManagementFolders(BTreeContainer):
__implements__ = ISiteManagementFolders
=== Zope3/src/zope/app/services/pagefolder.py 1.1 => 1.2 ===
--- Zope3/src/zope/app/services/pagefolder.py:1.1 Sun Mar 23 11:45:44 2003
+++ Zope3/src/zope/app/services/pagefolder.py Sun Mar 23 14:24:46 2003
@@ -27,13 +27,15 @@
from zope.proxy.context import getItem, getAttr
from zope.proxy.context import ContextMethod
from zope.app.interfaces.services.configuration import Active
-from zope.app.services.configuration import ConfigurationManager
+from zope.app.services.configuration import ConfigurationManagerContainer
from zope.app.services.configuration import ConfigurationStatusProperty
from zope.proxy.introspection import removeAllProxies
+from zope.app.services.folder import SiteManagementFolder
from zope.app.services.view import PageConfiguration
from zope.app.interfaces.services.pagefolder import IPageFolder
+from zope.app.interfaces.services.configuration import IConfigurationManager
-class PageFolder(BTreeContainer):
+class PageFolder(ConfigurationManagerContainer, BTreeContainer):
__implements__ = IPageFolder
@@ -45,11 +47,11 @@
attribute = None
template = None
- def __init__(self):
- super(PageFolder, self).__init__()
- super(PageFolder, self).setObject('configure', ConfigurationManager())
-
def setObject(self, name, object):
+ if IConfigurationManager.isImplementedBy(object):
+ # We allow configuration managers as well as templates
+ return super(PageFolder, self).setObject(name, object)
+
if not IZPTTemplate.isImplementedBy(object):
raise TypeError("Can only add templates", object)