[Zope3-checkins] CVS: Zope3/src/zope/app/services - configure.zcml:1.34 pagefolder.py:1.10 role.py:1.6

Steve Alexander steve@cat-box.net
Thu, 5 Jun 2003 08:03:48 -0400


Update of /cvs-repository/Zope3/src/zope/app/services
In directory cvs.zope.org:/tmp/cvs-serv15171/src/zope/app/services

Modified Files:
	configure.zcml pagefolder.py role.py 
Log Message:
Placeful setup for tests now sets up a  ZopeContainerDecorator.
This means that in such tests, you no longer need to use
ZopeContainerAdapter to get the correct events issued, and perform context-
wrapping duties, when you use a container.
However, it does mean that your tests need to expect these events and
context-wrappers to be used.



=== Zope3/src/zope/app/services/configure.zcml 1.33 => 1.34 ===
--- Zope3/src/zope/app/services/configure.zcml:1.33	Mon Jun  2 13:54:54 2003
+++ Zope3/src/zope/app/services/configure.zcml	Thu Jun  5 08:03:17 2003
@@ -324,6 +324,12 @@
         interface="zope.app.interfaces.annotation.IAttributeAnnotatable" />
     </content>
 
+    <adapter
+        for="zope.app.interfaces.services.pagefolder.IPageFolder"
+        provides="zope.app.interfaces.context.IZopeContextWrapper"
+        factory="zope.app.services.pagefolder.PageFolderContextDecorator"
+        />
+
 <!-- Connection Service -->
 
   <content class="zope.app.services.connection.ConnectionService">


=== Zope3/src/zope/app/services/pagefolder.py 1.9 => 1.10 ===
--- Zope3/src/zope/app/services/pagefolder.py:1.9	Sun Jun  1 11:59:36 2003
+++ Zope3/src/zope/app/services/pagefolder.py	Thu Jun  5 08:03:17 2003
@@ -21,6 +21,7 @@
 __metaclass__ = type
 
 from zope.app.container.btree import BTreeContainer
+from zope.app.container.zopecontainer import ZopeContainerDecorator
 from zope.app.interfaces.services.view import IZPTTemplate
 from zope.publisher.interfaces.browser import IBrowserPresentation
 from zope.app.traversing import getPath
@@ -35,10 +36,11 @@
 from zope.app.interfaces.file import IDirectoryFactory
 from zope.app.fssync.classes import ObjectEntryAdapter, AttrMapping
 from zope.app.interfaces.fssync import IObjectDirectory
+from zope.interface import implements
 
 class PageFolder(ConfigurationManagerContainer, BTreeContainer):
 
-    __implements__ = IPageFolder
+    implements(IPageFolder)
 
     presentationType = IBrowserPresentation
     layer = "default"
@@ -49,35 +51,12 @@
     template = None
 
     def setObject(self, name, object):
-        if IConfigurationManager.isImplementedBy(object):
-            # We allow configuration managers as well as templates
+        if (IConfigurationManager.isImplementedBy(object) or
+            IZPTTemplate.isImplementedBy(object)):
             return super(PageFolder, self).setObject(name, object)
-
-        if not IZPTTemplate.isImplementedBy(object):
+        else:
             raise TypeError("Can only add templates", object)
 
-        # super() does not work on a context wrapped instance
-        base = removeAllProxies(self)
-
-        name = super(PageFolder, base).setObject(name, object)
-        template = getItem(self, name)
-        template = getPath(template)
-        config = PageConfiguration(
-            forInterface=self.forInterface,
-            viewName=name,
-            permission=self.permission,
-            class_=self.factoryName,
-            template=template,
-            layer=self.layer,
-            )
-        configure = self.getConfigurationManager()
-        id = configure.setObject('', config)
-        config = getItem(configure, id)
-        config.status = Active
-        return name
-
-    setObject = ContextMethod(setObject)
-
     def configured(self):
         return (hasattr(self, 'permission')
                 and hasattr(self, 'forInterface')
@@ -100,7 +79,7 @@
 class PageFolderAdapter(ObjectEntryAdapter):
     """ObjectFile adapter for PageFolder objects."""
 
-    __implements__ =  IObjectDirectory
+    implements(IObjectDirectory)
 
     def contents(self):
         return self.context.items()
@@ -109,15 +88,39 @@
         return AttrMapping(self.context, _attrNames)
 
 
-class PageFolderFactory(object):
+class PageFolderFactory:
 
-    __implements__ = IDirectoryFactory
+    implements(IDirectoryFactory)
 
     def __init__(self, context):
         self.context = context
 
     def __call__(self, name):
         return PageFolder()
+
+class PageFolderContextDecorator(ZopeContainerDecorator):
+
+    def setObject(self, name, object):
+        name = super(PageFolderContextDecorator, self).setObject(name, object)
+
+        # If a template is added, we need to configure it too.
+        if IZPTTemplate.isImplementedBy(object):
+            template = getItem(self, name)
+            template = getPath(template)
+            config = PageConfiguration(
+                forInterface=self.forInterface,
+                viewName=name,
+                permission=self.permission,
+                class_=self.factoryName,
+                template=template,
+                layer=self.layer,
+                )
+            configure = self.getConfigurationManager()
+            id = configure.setObject('', config)
+            config = getItem(configure, id)
+            config.status = Active
+        return name
+
 
 # XXX Backward compatibility. This is needed to support old pickles.
 ViewPackage = PageFolder


=== Zope3/src/zope/app/services/role.py 1.5 => 1.6 ===
--- Zope3/src/zope/app/services/role.py:1.5	Tue May 27 10:18:24 2003
+++ Zope3/src/zope/app/services/role.py	Thu Jun  5 08:03:17 2003
@@ -25,6 +25,7 @@
 from zope.context import ContextMethod
 from zope.app.component.nextservice import getNextService
 from zope.app.interfaces.services.service import ISimpleService
+from zope.interface import implements
 
 class Role(Role, Persistent):
     "Persistent Role"
@@ -34,7 +35,7 @@
 
 class RoleService(BTreeContainer):
 
-    __implements__ = ILocalRoleService, ISimpleService
+    implements(ILocalRoleService, ISimpleService)
 
     def getRole(wrapped_self, rid):
         '''See interface IRoleService'''