[Checkins] SVN: Products.Five/branches/1.2/ Fix: Allow multiple uses of the <class>/<content> directive.

Philipp von Weitershausen philikon at philikon.de
Sun Aug 13 14:51:10 EDT 2006


Log message for revision 69443:
  Fix: Allow multiple uses of the <class>/<content> directive.
  
  Also, reduce the code duplication in the directive handler tremendously
  by using the zope 3 implementation as a base class.
  

Changed:
  U   Products.Five/branches/1.2/CHANGES.txt
  U   Products.Five/branches/1.2/metaconfigure.py
  U   Products.Five/branches/1.2/security.py
  A   Products.Five/branches/1.2/tests/classes.py
  U   Products.Five/branches/1.2/tests/directives.zcml
  U   Products.Five/branches/1.2/tests/test_directives.py
  U   Products.Five/branches/1.2/tests/test_security.py
  U   Products.Five/branches/1.2/version.txt

-=-
Modified: Products.Five/branches/1.2/CHANGES.txt
===================================================================
--- Products.Five/branches/1.2/CHANGES.txt	2006-08-13 18:11:36 UTC (rev 69442)
+++ Products.Five/branches/1.2/CHANGES.txt	2006-08-13 18:51:08 UTC (rev 69443)
@@ -2,13 +2,15 @@
 Five Changes
 ============
 
-Five 1.2.6 (unreleased)
+Five 1.2.6 (2006-08-13)
 =======================
 
+* Allow multiple uses of the <class>/<content> directive.
+
 * Fix problem with WebDAV/HEAD requests due to new traversal order.
 
-* Backported the new traversal lookup order from Zope 2.10 (attribute, adapter,
-  acquired attribute).
+* Backported the new traversal lookup order from Zope 2.10 (attribute,
+  adapter, acquired attribute).
 
 Five 1.2.5 (2006-05-29)
 =======================

Modified: Products.Five/branches/1.2/metaconfigure.py
===================================================================
--- Products.Five/branches/1.2/metaconfigure.py	2006-08-13 18:11:36 UTC (rev 69442)
+++ Products.Five/branches/1.2/metaconfigure.py	2006-08-13 18:51:08 UTC (rev 69443)
@@ -19,52 +19,17 @@
 
 from zope.interface import classImplements
 from zope.configuration.exceptions import ConfigurationError
+from zope.app.component import contentdirective
+from Products.Five.security import protectName, initializeClass
 
-from security import CheckerPublic
-from security import protectName, initializeClass
+class ContentDirective(contentdirective.ContentDirective):
 
-class ContentDirective:
-
     def __init__(self, _context, class_):
         self.__class = class_
         if isinstance(self.__class, ModuleType):
             raise ConfigurationError('Content class attribute must be a class')
         self.__context = _context
 
-    def implements(self, _context, interface):
-        for interface in interface:
-            _context.action(
-                discriminator = (
-                'five::directive:content', self.__class, object()),
-                callable = classImplements,
-                args = (self.__class, interface),
-                )
-            interface(_context, interface)
-
-    def require(self, _context, permission=None,
-                attributes=None, interface=None):
-        """Require a the permission to access a specific aspect"""
-
-        if not (interface or attributes):
-            raise ConfigurationError("Nothing required")
-
-        if interface:
-            for i in interface:
-                if i:
-                    self.__protectByInterface(i, permission)
-        if attributes:
-            self.__protectNames(attributes, permission)
-
-    def allow(self, _context, attributes=None, interface=None):
-        """Like require, but with permission_id zope.Public"""
-        return self.require(_context, CheckerPublic, attributes, interface)
-
-    def __protectByInterface(self, interface, permission_id):
-        "Set a permission on names in an interface."
-        for n, d in interface.namesAndDescriptions(1):
-            self.__protectName(n, permission_id)
-        interface(self.__context, interface)
-
     def __protectName(self, name, permission_id):
         "Set a permission on a particular name."
         self.__context.action(
@@ -73,15 +38,18 @@
             args = (self.__class, name, permission_id)
             )
 
-    def __protectNames(self, names, permission_id):
-        "Set a permission on a bunch of names."
-        for name in names:
-            self.__protectName(name, permission_id)
+    def __protectSetAttributes(self, attributes, permissions):
+        raise ConfigurationError('set_attributes parameter not supported.')
 
+    def __proctectSetSchema(self, schema, permission):
+        raise ConfigurationError('set_schema parameter not supported.')
+
+    def __mimic(self, _context, class_):
+        raise ConfigurationError('like_class parameter not supported.')
+
     def __call__(self):
-        "Handle empty/simple declaration."
         return self.__context.action(
-            discriminator = ('five:initialize:class', self.__class),
+            discriminator = None,
             callable = initializeClass,
             args = (self.__class,)
             )

Modified: Products.Five/branches/1.2/security.py
===================================================================
--- Products.Five/branches/1.2/security.py	2006-08-13 18:11:36 UTC (rev 69442)
+++ Products.Five/branches/1.2/security.py	2006-08-13 18:51:08 UTC (rev 69443)
@@ -118,12 +118,6 @@
     """Protect the attribute 'name' on 'klass' using the given
        permission"""
     security = _getSecurity(klass)
-    # XXX: Sometimes, the object CheckerPublic is used instead of the
-    # string zope.Public. I haven't ben able to figure out why, or if
-    # it is correct, or a bug. So this is a workaround.
-    if permission_id is CheckerPublic:
-        security.declarePublic(name)
-        return
     # Zope 2 uses string, not unicode yet
     name = str(name)
     if permission_id == CheckerPublicId:

Added: Products.Five/branches/1.2/tests/classes.py
===================================================================
--- Products.Five/branches/1.2/tests/classes.py	2006-08-13 18:11:36 UTC (rev 69442)
+++ Products.Five/branches/1.2/tests/classes.py	2006-08-13 18:51:08 UTC (rev 69443)
@@ -0,0 +1,32 @@
+##############################################################################
+#
+# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Interfaces test fixtures
+
+$Id$
+"""
+from zope.interface import Interface
+
+class One(object):
+    'A class'
+
+class Two(object):
+    'Another class'
+
+class IOne(Interface):
+    """This is a Zope 3 interface.
+    """
+
+class ITwo(Interface):
+    """This is another Zope 3 interface.
+    """


Property changes on: Products.Five/branches/1.2/tests/classes.py
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: Products.Five/branches/1.2/tests/directives.zcml
===================================================================
--- Products.Five/branches/1.2/tests/directives.zcml	2006-08-13 18:11:36 UTC (rev 69442)
+++ Products.Five/branches/1.2/tests/directives.zcml	2006-08-13 18:51:08 UTC (rev 69443)
@@ -47,4 +47,15 @@
       factory=".adapters.OriginalAdapter"
       />
 
+  <!-- this tests whether content / class can be declared on the same class
+       with two different interfaces. -->
+
+  <class class=".classes.One" >
+    <implements interface=".classes.IOne" />
+  </class>
+
+  <class class=".classes.One" >
+    <implements interface=".classes.ITwo" />
+  </class>
+
 </configure>

Modified: Products.Five/branches/1.2/tests/test_directives.py
===================================================================
--- Products.Five/branches/1.2/tests/test_directives.py	2006-08-13 18:11:36 UTC (rev 69442)
+++ Products.Five/branches/1.2/tests/test_directives.py	2006-08-13 18:51:08 UTC (rev 69443)
@@ -62,6 +62,14 @@
       >>> dest.method()
       'Overridden'
 
+    Check the result of the <class> directives
+
+      >>> from Products.Five.tests.classes import One, Two, IOne, ITwo
+      >>> IOne.implementedBy(One)
+      True
+      >>> ITwo.implementedBy(One)
+      True
+
     Clean up:
 
       >>> tearDown()

Modified: Products.Five/branches/1.2/tests/test_security.py
===================================================================
--- Products.Five/branches/1.2/tests/test_security.py	2006-08-13 18:11:36 UTC (rev 69442)
+++ Products.Five/branches/1.2/tests/test_security.py	2006-08-13 18:51:08 UTC (rev 69443)
@@ -72,13 +72,15 @@
 
       >>> configure_zcml = '''
       ... <configure xmlns="http://namespaces.zope.org/zope">
-      ...   <content class="Products.Five.tests.test_security.Dummy1">
+      ...   <class class="Products.Five.tests.test_security.Dummy1">
       ...     <allow attributes="foo" />
       ...     <!--deny attributes="baz" /--> <!-- XXX not yet supported -->
+      ...   </class>
+      ...   <class class="Products.Five.tests.test_security.Dummy1">
       ...     <require attributes="bar keg"
       ...              permission="zope2.ViewManagementScreens"
       ...              />
-      ...   </content>
+      ...   </class>
       ... </configure>
       ... '''
       >>> zcml.load_string(configure_zcml)

Modified: Products.Five/branches/1.2/version.txt
===================================================================
--- Products.Five/branches/1.2/version.txt	2006-08-13 18:11:36 UTC (rev 69442)
+++ Products.Five/branches/1.2/version.txt	2006-08-13 18:51:08 UTC (rev 69443)
@@ -1 +1 @@
-Five 1.2.5
+Five 1.2.6



More information about the Checkins mailing list