[Zope3-checkins] CVS: Zope3/src/zope/app/component - metadirectives.py:1.3 contentdirective.py:1.6 meta.zcml:1.10 metaconfigure.py:1.15

Philipp von Weitershausen philikon at philikon.de
Sat Aug 2 23:13:46 EDT 2003


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

Modified Files:
	contentdirective.py meta.zcml metaconfigure.py 
Added Files:
	metadirectives.py 
Log Message:
Here we go again. All tests have been run twice and passed. Sorry again for
the trouble I've caused. Anthony and Steve, I owe you guys are beer.

Converted the three most important packages that define ZCML directives
to the new ZCML architecture (using schemas):

- zope.app.component

- zope.app.browser.form

- zope.app.publisher.browser


=== Zope3/src/zope/app/component/metadirectives.py 1.2 => 1.3 ===
--- /dev/null	Sat Aug  2 22:13:44 2003
+++ Zope3/src/zope/app/component/metadirectives.py	Sat Aug  2 22:13:08 2003
@@ -0,0 +1,373 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (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.
+#
+##############################################################################
+"""
+$Id$
+"""
+
+from zope.interface import Interface
+from zope.configuration.fields import GlobalObject, Tokens, Path, \
+     PythonIdentifier
+from zope.schema import Text, TextLine, Id
+
+class IBasicComponentInformation(Interface):
+
+    component = GlobalObject(
+        title=u"Component to be used",
+        required=False
+        )
+
+    permission = Id(
+        title=u"Permission",
+        required=False
+        )
+
+    factory = GlobalObject(
+        title=u"Factory",
+        required=False
+        )
+
+class IBasicViewInformation(Interface):
+    """
+    This is the basic information for all views.
+    """
+
+    for_ = GlobalObject(
+        title=u"The interface this view applies to.",
+        description=u"""
+        The view will be for all objects that implement this
+        interface. If this is not supplied, the view applies to all
+        objects (XXX this ought to change).""",
+        required=False
+        )
+
+    permission = Id(
+        title=u"Permission",
+        description=u"The permission needed to use the view.",
+        required=False
+        )
+
+    class_ = GlobalObject(
+        title=u"Class",
+        description=u"A class that provides attributes used by the view.",
+        required=False
+        )
+
+    layer = TextLine(
+        title=u"The layer the view is in.",
+        description=u"""
+        A skin is composed of layers. It is common to put skin
+        specific views in a layer named after the skin. If the 'layer'
+        attribute is not supplied, it defaults to 'default'.""",
+        required=False
+        )
+
+    allowed_interface = Tokens(
+        title=u"Interface that is also allowed if user has permission.",
+        description=u"""
+        By default, 'permission' only applies to viewing the view and
+        any possible sub views. By specifying this attribute, you can
+        make the permission also apply to everything described in the
+        supplied interface.
+
+        Multiple interfaces can be provided, separated by
+        whitespace.""",
+        required=False,
+        value_type=GlobalObject()
+        )
+
+    allowed_attributes = Tokens(
+        title=u"View attributes that are also allowed if user has permission.",
+        description=u"""
+        By default, 'permission' only applies to viewing the view and
+        any possible sub views. By specifying 'allowed_attributes',
+        you can make the permission also apply to the extra attributes
+        on the view object.""",
+        required=False,
+        value_type=PythonIdentifier()
+        )
+
+class IBasicResourceInformation(Interface):
+    """
+    Basic information for resources
+    """
+
+    name = TextLine(
+        title=u"The name of the resource.",
+        description=u"The name shows up in URLs/paths. For example 'foo'.",
+        required=True
+        )
+
+    type = GlobalObject(
+        title=u"Type of the resource",
+        required=True
+        )
+
+class IInterfaceDirective(Interface):
+    """
+    Define an interface
+    """
+    
+    interface = GlobalObject(
+        title=u"Interface",
+        required=True
+        )
+
+class IAdapterDirective(Interface):
+    """
+    Register an adapter
+    """
+
+    factory = Tokens(
+        title=u"Adapter factory/factories",
+        required=True,
+        value_type=GlobalObject()
+        )
+
+    provides = GlobalObject(
+        title=u"Interface the component provides",
+        required=True
+        )
+
+    for_ = GlobalObject(
+        title=u"Interface the component is used for",
+        required=True
+        )
+
+    permission = Id(
+        title=u"Permission",
+        required=False
+        )
+
+    name = TextLine(
+        title=u"Name",
+        required=False
+        )
+
+class IUtilityDirective(IBasicComponentInformation):
+    """
+    Register a utility
+    """
+
+    provides = GlobalObject(
+        title=u"Interface the component provides",
+        required=True
+        )
+
+    name = TextLine(
+        title=u"Name",
+        required=False
+        )
+
+class IFactoryDirective(Interface):
+    """
+    Define a factory
+    """
+
+    component = GlobalObject(
+        title=u"Component to be used",
+        required=True
+        )
+    
+    id = TextLine(
+        title=u"ID",
+        required=False
+        )
+
+    permission = Id(
+        title=u"Permission",
+        required=False
+        )
+
+class IViewDirective(IBasicViewInformation, IBasicResourceInformation):
+    """
+    Register a view for a component
+    """
+
+    factory = Tokens(
+        title=u"Factory",
+        required=False,
+        value_type=GlobalObject()
+        )
+
+class IResourceDirective(IBasicComponentInformation, IBasicResourceInformation):
+    """
+    Register a resource
+    """
+    
+    layer = TextLine(
+        title=u"The layer the resource is in.",
+        required=False
+        )
+
+    allowed_interface = Tokens(
+        title=u"Interface that is also allowed if user has permission.",
+        required=False,
+        value_type=GlobalObject()
+        )
+
+    allowed_attributes = Tokens(
+        title=u"View attributes that are also allowed if user has permission.",
+        required=False,
+        value_type=PythonIdentifier()
+        )
+
+class ISkinDirective(IBasicResourceInformation):
+    """
+    Register a skin
+    """
+
+    layers = Tokens(
+        title=u"The layers it consists of.",
+        required=True,
+        value_type=TextLine()
+        )
+
+class IServiceTypeDirective(Interface):
+
+    id = TextLine(
+        title=u"ID of the service type",
+        required=True
+        )
+
+    interface = GlobalObject(
+        title=u"Interface of the service type",
+        required=True
+        )
+
+class IServiceDirective(IBasicComponentInformation):
+    """
+    Register a service
+    """
+
+    serviceType = TextLine(
+        title=u"ID of service type",
+        required=True
+        )
+
+class IClassDirective(Interface):
+    """
+    Make statements about a class
+    """
+
+    class_ = GlobalObject(
+        title=u"Class",
+        required=True
+        )
+
+class IImplementsSubdirective(Interface):
+    """
+    Declare that the class given by the content directive's class
+    attribute implements a given interface
+    """
+
+    interface = Tokens(
+        title=u"One or more interfaces",
+        required=True,
+        value_type=GlobalObject()
+        )
+
+class IRequireSubdirective(Interface):
+    """
+    Indicate that the a specified list of names or the names in a
+    given Interface require a given permission for access.
+    """
+
+    permission = Id(
+        title=u"Permission",
+        required=False
+        )
+
+    attributes = Tokens(
+        title=u"Attributes",
+        required=False,
+        value_type=PythonIdentifier()
+        )
+        
+    set_attributes = Tokens(
+        title=u"Attributes that can be set",
+        required=False,
+        value_type=PythonIdentifier()
+        )
+
+    interface = Tokens(
+        title=u"Interface",
+        required=False,
+        value_type=GlobalObject()
+        )
+
+    set_schema = Tokens(
+        title=u"The attributes specified by the schema can be set",
+        required=False,
+        value_type=GlobalObject()
+        )
+
+    like_class = GlobalObject(
+        title=u"Configure like this class",
+        required=False
+        )
+    
+class IAllowSubdirective(Interface):
+    """
+    Declare a part of the class to be publicly viewable (that is,
+    requires the zope.Public permission). Only one of the following
+    two attributes may be used.
+    """
+
+    attributes = Tokens(
+        title=u"Attributes",
+        required=False,
+        value_type=PythonIdentifier()
+        )
+
+    interface = Tokens(
+        title=u"Interface",
+        required=False,
+        value_type=GlobalObject()
+        )
+
+class IFactorySubdirective(Interface):
+    """
+    Specify the factory used to create this content object
+    """
+
+    id = TextLine(
+        title=u"ID",
+        description=u"""
+        the identifier for this factory in the ZMI factory
+        identification scheme.  If not given, defaults to the literal
+        string given as the content directive's 'class' attribute.""",
+        required=False
+        )
+
+    permission = Id(
+        title=u"Permission",
+        description=u"""
+        permission id required to use this factory.  Although
+        optional, this attribute should normally be specified.""",
+        required=False
+        )
+
+    title = TextLine(
+        title=u"Title",
+        description=u"""
+        text suitable for use in the 'add content' menu of a
+        management interface""",
+        required=False
+        )
+
+    description = Text(
+        title=u"Description",
+        description=u"Longer narrative description of what this factory does",
+        required=False
+        )


=== Zope3/src/zope/app/component/contentdirective.py 1.5 => 1.6 ===
--- Zope3/src/zope/app/component/contentdirective.py:1.5	Sat Aug  2 05:11:15 2003
+++ Zope3/src/zope/app/component/contentdirective.py	Sat Aug  2 22:13:08 2003
@@ -21,9 +21,7 @@
 from zope.component import getService
 from zope.app.services.servicenames import Interfaces, Factories
 from zope.configuration.exceptions import ConfigurationError
-from zope.configuration.action import Action
 from zope.app.component.classfactory import ClassFactory
-from zope.app.component.metaconfigure import resolveInterface
 from zope.app.security.protectclass \
     import protectLikeUnto, protectName, protectSetAttribute
 from zope.app.security.registries.permissionregistry import permissionRegistry
@@ -50,7 +48,7 @@
 
     def __init__(self, _context, class_):
         self.__id = class_
-        self.__class = _context.resolve(class_)
+        self.__class = class_
         if isinstance(self.__class, ModuleType):
             raise ConfigurationError('Content class attribute must be a class')
         # not used yet
@@ -59,137 +57,119 @@
         self.__context = _context
 
     def implements(self, _context, interface):
-        r = []
-        for interface in interface.strip().split():
-
-            resolved_interface = resolveInterface(_context, interface)
-            r += [
-                Action(
-                    discriminator = (
-                        'ContentDirective', self.__class, object()),
-                    callable = classImplements,
-                    args = (self.__class, resolved_interface),
-                    ),
-                Action(
-                   discriminator = None,
-                   callable = handler,
-                   args = (Interfaces, 'provideInterface',
-                           resolved_interface.__module__+
-                           '.'+
-                           resolved_interface.__name__,
-                           resolved_interface)
-                   )
-                ]
-        return r
+        for interface in interface:
+            _context.action(
+                discriminator = (
+                'ContentDirective', self.__class, object()),
+                callable = classImplements,
+                args = (self.__class, interface),
+                )
+            _context.action(
+                discriminator = None,
+                callable = handler,
+                args = (Interfaces, 'provideInterface',
+                        interface.__module__+
+                        '.'+
+                        interface.__name__,
+                        interface)
+                )
 
     def require(self, _context,
                 permission=None, attributes=None, interface=None,
                 like_class=None, set_attributes=None, set_schema=None):
         """Require a the permission to access a specific aspect"""
-
         if like_class:
-            r = self.__mimic(_context, like_class)
-        else:
-            r = []
+            self.__mimic(_context, like_class)
 
         if not (interface or attributes or set_attributes or set_schema):
-            if r:
-                return r
+            if like_class:
+                return
             raise ConfigurationError("Nothing required")
 
         if not permission:
             raise ConfigurationError("No permission specified")
 
-
         if interface:
-            for i in interface.strip().split():
-                self.__protectByInterface(i, permission, r)
+            for i in interface:
+                if i:
+                    self.__protectByInterface(i, permission)
         if attributes:
-            self.__protectNames(attributes, permission, r)
+            self.__protectNames(attributes, permission)
         if set_attributes:
-            self.__protectSetAttributes(set_attributes, permission, r)
+            self.__protectSetAttributes(set_attributes, permission)
         if set_schema:
-            for s in set_schema.strip().split():
-                self.__protectSetSchema(s, permission, r)
-
-
-        return r
+            for s in set_schema:
+                self.__protectSetSchema(s, permission)
 
     def __mimic(self, _context, class_):
         """Base security requirements on those of the given class"""
-        class_to_mimic = _context.resolve(class_)
-        return [
-            Action(discriminator=('mimic', self.__class, object()),
-                   callable=protectLikeUnto,
-                   args=(self.__class, class_to_mimic),
-                   )
-            ]
+        _context.action(
+            discriminator=('mimic', self.__class, object()),
+            callable=protectLikeUnto,
+            args=(self.__class, class_),
+            )
 
     def allow(self, _context, attributes=None, interface=None):
         """Like require, but with permission_id zope.Public"""
         return self.require(_context, PublicPermission, attributes, interface)
 
-
-
-    def __protectByInterface(self, interface, permission_id, r):
+    def __protectByInterface(self, interface, permission_id):
         "Set a permission on names in an interface."
-        interface = resolveInterface(self.__context, interface)
         for n, d in interface.namesAndDescriptions(1):
-            self.__protectName(n, permission_id, r)
-        r.append(
-            Action(
-               discriminator = None,
-               callable = handler,
-               args = (Interfaces, 'provideInterface',
-                       interface.__module__+ '.'+ interface.__name__,
-                       interface)
-               )
+            self.__protectName(n, permission_id)
+        self.__context.action(
+            discriminator = None,
+            callable = handler,
+            args = (Interfaces, 'provideInterface',
+                    interface.__module__+ '.'+ interface.__name__,
+                    interface)
             )
 
-    def __protectName(self, name, permission_id, r):
+    def __protectName(self, name, permission_id):
         "Set a permission on a particular name."
-        r.append((
-            ('protectName', self.__class, name),
-            protectName, (self.__class, name, permission_id)))
+        self.__context.action(
+            discriminator = ('protectName', self.__class, name),
+            callable = protectName,
+            args = (self.__class, name, permission_id)
+            )
 
-    def __protectNames(self, names, permission_id, r):
+    def __protectNames(self, names, permission_id):
         "Set a permission on a bunch of names."
-        for name in names.split():
-            self.__protectName(name.strip(), permission_id, r)
+        for name in names:
+            self.__protectName(name, permission_id)
 
-    def __protectSetAttributes(self, names, permission_id, r):
+    def __protectSetAttributes(self, names, permission_id):
         "Set a permission on a bunch of names."
-        for name in names.split():
-            r.append((
-                ('protectSetAttribute', self.__class, name),
-                protectSetAttribute, (self.__class, name, permission_id)))
+        for name in names:
+            self.__context.action(
+                discriminator = ('protectSetAttribute', self.__class, name),
+                callable = protectSetAttribute,
+                args = (self.__class, name, permission_id)
+                )
 
-    def __protectSetSchema(self, schema, permission_id, r):
+    def __protectSetSchema(self, schema, permission_id):
         "Set a permission on a bunch of names."
-        schema = resolveInterface(self.__context, schema)
+        _context = self.__context
         for name in schema:
             field = schema[name]
             if IField.isImplementedBy(field) and not field.readonly:
-                r.append((
-                    ('protectSetAttribute', self.__class, name),
-                    protectSetAttribute, (self.__class, name, permission_id)))
-
-        r.append(
-            Action(
-               discriminator = None,
-               callable = handler,
-               args = (Interfaces, 'provideInterface',
-                       schema.__module__+ '.'+ schema.__name__,
-                       schema)
-               )
+                _context.action(
+                    discriminator = ('protectSetAttribute', self.__class, name),
+                    callable = protectSetAttribute,
+                    args = (self.__class, name, permission_id)
+                    )
+        _context.action(
+            discriminator = None,
+            callable = handler,
+            args = (Interfaces, 'provideInterface',
+                    schema.__module__+ '.'+ schema.__name__,
+                    schema)
             )
 
-
     def __call__(self):
         "Handle empty/simple declaration."
         return ()
 
-
     def factory(self, _context,
                 permission=None, title="", id=None, description=''):
         """Register a zmi factory for this class"""
@@ -199,14 +179,12 @@
         # note factories are all in one pile, services and content,
         # so addable names must also act as if they were all in the
         # same namespace, despite the service/content division
-        return [
-            Action(
-                discriminator = ('FactoryFromClass', id),
-                callable = provideClass,
-                args = (id, self.__class,
-                        permission, title, description)
-                )
-            ]
+        _context.action(
+            discriminator = ('FactoryFromClass', id),
+            callable = provideClass,
+            args = (id, self.__class,
+                    permission, title, description)
+            )
 
 def provideClass(id, _class, permission=None,
                  title='', description=''):


=== Zope3/src/zope/app/component/meta.zcml 1.9 => 1.10 ===
--- Zope3/src/zope/app/component/meta.zcml:1.9	Sat Aug  2 05:11:15 2003
+++ Zope3/src/zope/app/component/meta.zcml	Sat Aug  2 22:13:08 2003
@@ -1,261 +1,125 @@
-<zopeConfigure xmlns='http://namespaces.zope.org/zope'>
+<configure
+    xmlns="http://namespaces.zope.org/zope"
+    xmlns:meta="http://namespaces.zope.org/meta">
+
+  <meta:directives namespace="http://namespaces.zope.org/zope">
+
+    <meta:directive
+        name="interface"
+        schema=".metadirectives.IInterfaceDirective"
+        handler="zope.app.component.metaconfigure.interface"
+        />
+
+    <meta:directive
+        name="adapter"
+        schema=".metadirectives.IAdapterDirective"
+        handler="zope.app.component.metaconfigure.adapter"
+        />
+
+    <meta:directive
+        name="utility"
+        schema=".metadirectives.IUtilityDirective"
+        handler="zope.app.component.metaconfigure.utility"
+        />
+
+    <meta:directive
+        name="factory"
+        schema=".metadirectives.IFactoryDirective"
+        handler="zope.app.component.metaconfigure.factory"
+        />
+
+    <meta:directive
+        name="view"
+        schema=".metadirectives.IViewDirective"
+        handler="zope.app.component.metaconfigure.view"
+        />
+
+    <meta:directive
+        name="defaultView"
+        schema=".metadirectives.IViewDirective"
+        handler="zope.app.component.metaconfigure.defaultView"
+        />
+
+    <meta:directive
+        name="resource"
+        schema=".metadirectives.IResourceDirective"
+        handler="zope.app.component.metaconfigure.resource"
+        />
+
+    <meta:directive
+        name="skin"
+        schema=".metadirectives.ISkinDirective"
+        handler="zope.app.component.metaconfigure.skin"
+        />
+
+    <meta:directive
+        name="serviceType"
+        schema=".metadirectives.IServiceTypeDirective"
+        handler="zope.app.component.metaconfigure.serviceType"
+        />
+
+    <meta:directive
+        name="service" 
+        schema=".metadirectives.IServiceDirective"
+        handler="zope.app.component.metaconfigure.service"
+        />
 
-  <directives namespace="http://namespaces.zope.org/zope">
-
-    <directive name="interface" attributes="interface"
-       handler="zope.app.component.metaconfigure.interface" />
-
-    <directive name="adapter" 
-               attributes="factory provides for permission name"
-       handler="zope.app.component.metaconfigure.adapter" />
-
-    <directive name="utility" 
-               attributes="component provides permission name factory"
-       handler="zope.app.component.metaconfigure.utility" />
-
-    <directive name="factory" attributes="component id permission"
-       handler="zope.app.component.metaconfigure.factory" />
-
-    <directive
-       name="view"
-       attributes="component type name for layer factory
-                   permission allowed_interface allowed_attributes"
-       handler="zope.app.component.metaconfigure.view" />
+    <meta:complexDirective
+        name="class"
+        schema=".metadirectives.IClassDirective"
+        handler="zope.app.component.contentdirective.ContentDirective"
+        >
 
-    <directive name="defaultView"
-               attributes="component type name for layer factory
-                           permission allowed_attributes"
-       handler="zope.app.component.metaconfigure.defaultView" />
+      <meta:subdirective
+          name="implements"
+          schema=".metadirectives.IImplementsSubdirective"
+          />
 
-    <directive
-       name="resource"
-       attributes="component type name layer factory
-                   permission allowed_interface allowed_attributes"
-       handler="zope.app.component.metaconfigure.resource" />
+      <meta:subdirective
+          name="require"
+          schema=".metadirectives.IRequireSubdirective"
+          />
 
-    <directive name="skin" attributes="name type layers"
-        handler="zope.app.component.metaconfigure.skin" />
+      <meta:subdirective
+          name="allow"
+          schema=".metadirectives.IAllowSubdirective"
+          />
 
-    <directive name="serviceType" attributes="id interface"
-       handler="zope.app.component.metaconfigure.serviceType" />
+      <meta:subdirective
+          name="factory"
+          schema=".metadirectives.IFactorySubdirective"
+          />
 
-    <directive name="service" 
-               attributes="serviceType component permission factory"
-       handler="zope.app.component.metaconfigure.service" />
+    </meta:complexDirective>
 
-    <directive
+    <meta:complexDirective
         name="content"
+        schema=".metadirectives.IClassDirective"
         handler="zope.app.component.contentdirective.ContentDirective"
-        description="Make a component available as a content object type"
         >
-      <attribute
-          name="class"
-          required="yes"
-          description="resolvable name of a class"
-          />
-
-      <subdirective name="implements">
 
-        <description>
-              Declare that the class given by the content
-              directive's class attribute implements a given interface
-          </description>
-
-        <attribute
-            name="interface"
-            required="yes"
-            description="resolvable name of an Interface"
-            />
-      </subdirective>
-
-      <subdirective name="require">
-        <description>
-            Indicate that the a specified list of names or the
-            names in a given Interface require a given permission for
-            access.
-          </description>
-
-        <attribute
-            name="permission"
-            required="no"
-            description="a permission id"
-            />
-
-        <attribute
-            name="attributes"
-            description="space-separated list of attribute names"
-            />
-
-        <attribute
-            name="set_attributes"
-            description="space-separated list of attribute names
-                         for attributes that can be set"
-            />
-
-        <attribute
-            name="set_schema"
-            >
-            Dotted name of a schema
-
-            The non-read-only fields in the schema can be set with the
-            specified permission.
-            
-          </attribute>
-
-        <attribute
-            name="interface"
-            description="the resolvable name of an interface"
-            />
-
-        <attribute name="like_class">
-          <description>
-                a class on which the security requirements
-                for this class will be based
-              </description>
-          </attribute>
-
-      </subdirective>
-
-      <subdirective name="allow">
-        <description>
-              Declare a part of the class to be publicly
-              viewable (that is, requires the zope.Public
-              permission).  Only one of the following two
-              attributes may be used.
-           </description>
-
-        <attribute
-            name="attributes"
-            description="space-separated list of attribute names"
-            />
-
-        <attribute
-            name="interface"
-            description="the resolvable name of an interface"
-            />
-
-      </subdirective>
-
-      <subdirective name="factory">
-
-        <description>
-              Specify the factory used to create this
-              content object
-          </description>
-
-        <attribute name="permission">
-          <description>
-                permission id required to use this factory.
-                Although optional, this attribute should normally
-                be specified.
-                </description>
-          </attribute>
-
-        <attribute name="id">
-          <description>
-                the identifier for this factory in the
-                ZMI factory identification scheme.  If not given, defaults
-                to the literal string given as the content directive's
-                'class' attribute.
-              </description>
-          </attribute>
-
-        <attribute name="title">
-          <description>
-                text suitable for use in the 'add content' menu of
-                a management interface
-              </description>
-          </attribute>
-
-        <attribute name="description">
-          <description>
-                longer narrative description of what this
-                factory does
-            </description>
-          </attribute>
-
-      </subdirective>
-    </directive>
-
-    <directive
-        name="class"
-        handler="zope.app.component.contentdirective.ContentDirective"
-        description="Make statements about a class"
-        >
-      <attribute
-          name="class"
-          required="yes"
-          description="resolvable name of a class"
+      <meta:subdirective
+          name="implements"
+          schema=".metadirectives.IImplementsSubdirective"
           />
 
-      <subdirective name="implements">
+      <meta:subdirective
+          name="require"
+          schema=".metadirectives.IRequireSubdirective"
+          />
 
-        <description>
-              Declare that the class given by the content
-              directive's class attribute implements a given interface
-          </description>
-
-        <attribute
-            name="interface"
-            required="yes"
-            description="resolvable name of an Interface"
-            />
-      </subdirective>
-
-      <subdirective name="require">
-        <description>
-            Indicate that the a specified list of names or the
-            names in a given Interface require a given permission for
-            access.
-          </description>
-
-        <attribute
-            name="permission"
-            required="yes"
-            description="a permission id"
-            />
-
-        <attribute
-            name="attributes"
-            description="space-separated list of attribute names"
-            />
-
-        <attribute
-            name="interface"
-            description="the resolvable name of an interface"
-            />
-
-        <attribute name="like_class">
-          <description>
-                a class on which the security requirements
-                for this class will be based
-              </description>
-          </attribute>
-
-      </subdirective>
-
-      <subdirective name="allow">
-        <description>
-              Declare a part of the class to be publicly
-              viewable (that is, requires the zope.Public
-              permission).  Only one of the following two
-              attributes may be used.
-           </description>
-
-        <attribute
-            name="attributes"
-            description="space-separated list of attribute names"
-            />
-
-        <attribute
-            name="interface"
-            description="the resolvable name of an interface"
-            />
+      <meta:subdirective
+          name="allow"
+          schema=".metadirectives.IAllowSubdirective"
+          />
 
-      </subdirective>
+      <meta:subdirective
+          name="factory"
+          schema=".metadirectives.IFactorySubdirective"
+          />
 
-    </directive>
+    </meta:complexDirective>
 
-  </directives>
+  </meta:directives>
 
-</zopeConfigure>
+</configure>


=== Zope3/src/zope/app/component/metaconfigure.py 1.14 => 1.15 ===
--- Zope3/src/zope/app/component/metaconfigure.py:1.14	Sat Aug  2 05:11:15 2003
+++ Zope3/src/zope/app/component/metaconfigure.py	Sat Aug  2 22:13:08 2003
@@ -11,6 +11,9 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
+"""
+$Id$
+"""
 
 from zope.configuration.exceptions import ConfigurationError
 from zope.security.proxy import Proxy, ProxyFactory
@@ -18,7 +21,6 @@
 from zope.app.services.servicenames import Adapters, Interfaces, Skins
 from zope.app.services.servicenames import Views, Resources, Factories
 from zope.app.component.globalinterfaceservice import interfaceService
-from zope.configuration.action import Action
 from zope.security.checker import InterfaceChecker, CheckerPublic, \
      Checker, NamesChecker
 from zope.app.security.registries.permissionregistry import permissionRegistry
@@ -55,71 +57,42 @@
     method(*args, **kwargs)
 
 def interface(_context, interface):
-    interface = resolveInterface(_context, interface)
-    return [
-        Action(
-          discriminator = None,
-          callable = handler,
-          args = (Interfaces, 'provideInterface', '', interface)
-        ),
-      ]
-
+    _context.action(
+        discriminator = None,
+        callable = handler,
+        args = (Interfaces, 'provideInterface', '', interface)
+        )
 
 def adapter(_context, factory, provides, for_, permission=None, name=''):
-    if for_ == '*':
-        for_ = None
-    elif not for_:
-        raise ValueError(
-            "A for interface must be provided. Use * for all objects.")
-
-    if for_:
-        for_ = resolveInterface(_context, for_)
-
-    provides = resolveInterface(_context, provides)
-    factory = map(_context.resolve, factory.split())
-
     if permission is not None:
         if permission == PublicPermission:
             permission = CheckerPublic
         checker = InterfaceChecker(provides, permission)
         factory.append(lambda c: Proxy(c, checker))
-    actions=[
-        Action(
-            discriminator = ('adapter', for_, provides, name),
-            callable = checkingHandler,
-            args = (permission, Adapters, 'provideAdapter',
-                    for_, provides, factory, name),
-               ),
-        Action(
-            discriminator = None,
-            callable = handler,
-            args = (Interfaces, 'provideInterface', '', provides)
-              )
-              ]
+    _context.action(
+        discriminator = ('adapter', for_, provides, name),
+        callable = checkingHandler,
+        args = (permission, Adapters, 'provideAdapter',
+                for_, provides, factory, name),
+        )
+    _context.action(
+        discriminator = None,
+        callable = handler,
+        args = (Interfaces, 'provideInterface', '', provides)
+        )
     if for_ is not None:
-        actions.append
-        (
-        Action(
+        _context.action(
             discriminator = None,
             callable = handler,
             args = (Interfaces, 'provideInterface', '', for_)
-              )
-         )
-
-    return actions
-
+            )
 
 def utility(_context, provides, component=None, factory=None,
             permission=None, name=''):
-    provides = resolveInterface(_context, provides)
-
     if factory:
         if component:
             raise TypeError("Can't specify factory and component.")
-
-        component = _context.resolve(factory)()
-    else:
-        component = _context.resolve(component)
+        component = factory()
 
     if permission is not None:
         if permission == PublicPermission:
@@ -128,35 +101,25 @@
 
         component = Proxy(component, checker)
 
-    return [
-        Action(
-            discriminator = ('utility', provides, name),
-            callable = checkingHandler,
-            args = (permission, 'Utilities', 'provideUtility',
-                    provides, component, name),
-            ),
-        Action(
-            discriminator = None,
-            callable = handler,
-            args = (Interfaces, 'provideInterface',
-                    provides.__module__+'.'+provides.__name__, provides)
-              )
-        ]
-
+    _context.action(
+        discriminator = ('utility', provides, name),
+        callable = checkingHandler,
+        args = (permission, 'Utilities', 'provideUtility',
+                provides, component, name),
+        )
+    _context.action(
+        discriminator = None,
+        callable = handler,
+        args = (Interfaces, 'provideInterface',
+                provides.__module__+'.'+provides.__name__, provides)
+        )
 
 def factory(_context, component, id=None, permission=None):
-    if id is None:
-        id = component
-
-    component = _context.resolve(component)
-
-    return [
-        Action(
-            discriminator = ('factory', id),
-            callable = provideFactory,
-            args = (id, component, permission),
-            )
-        ]
+    _context.action(
+        discriminator = ('factory', id),
+        callable = provideFactory,
+        args = (id, component, permission),
+        )
 
 def provideFactory(name, factory, permission):
     # make sure the permission is defined
@@ -168,29 +131,30 @@
 
     if permission:
         # XXX should getInterfaces be public, as below?
-        factory = ProxyFactory(factory,
-                               NamesChecker(('getInterfaces',),
-                                            __call__=permission))
-
+        factory = ProxyFactory(
+            factory,
+            NamesChecker(('getInterfaces',),
+                         __call__=permission)
+            )
     getService(None, Factories).provideFactory(name, factory)
 
-
 def _checker(_context, permission, allowed_interface, allowed_attributes):
     if (not allowed_attributes) and (not allowed_interface):
-        allowed_attributes = "__call__"
+        allowed_attributes = ["__call__"]
 
     if permission == PublicPermission:
         permission = CheckerPublic
 
     require={}
-    for name in (allowed_attributes or '').split():
-        require[name] = permission
-    if allowed_interface:
-        for name in resolveInterface(_context, allowed_interface).names(all=True):
+    if allowed_attributes:
+        for name in allowed_attributes:
             require[name] = permission
+    if allowed_interface:
+        for i in allowed_interface:
+            for name in i.names(all=True):
+                require[name] = permission
 
     checker = Checker(require.get)
-
     return checker
 
 def resource(_context, factory, type, name, layer='default',
@@ -204,11 +168,6 @@
             "allowed_attributes"
             )
 
-
-    type = _context.resolve(type)
-    factory = _context.resolve(factory)
-
-
     if permission:
 
         checker = _checker(_context, permission,
@@ -219,20 +178,18 @@
 
         factory = proxyResource
 
-    return [
-        Action(
-            discriminator = ('resource', name, type, layer),
-            callable = checkingHandler,
-            args = (permission, Resources,'provideResource',
-                    name, type, factory, layer),
-            ),
-        Action(
-            discriminator = None,
-            callable = handler,
-            args = (Interfaces, 'provideInterface',
-                    type.__module__+'.'+type.__name__, type)
-              )
-        ]
+    _context.action(
+        discriminator = ('resource', name, type, layer),
+        callable = checkingHandler,
+        args = (permission, Resources,'provideResource',
+                name, type, factory, layer),
+        )
+    _context.action(
+        discriminator = None,
+        callable = handler,
+        args = (Interfaces, 'provideInterface',
+                type.__module__+'.'+type.__name__, type)
+        )
 
 def view(_context, factory, type, name, for_, layer='default',
          permission=None, allowed_interface=None, allowed_attributes=None):
@@ -247,11 +204,6 @@
             "allowed_attributes"
             )
 
-    if for_ is not None:
-        for_ = resolveInterface(_context, for_)
-    type = _context.resolve(type)
-
-    factory = map(_context.resolve, factory.strip().split())
     if not factory:
         raise ConfigurationError("No view factory specified.")
 
@@ -265,33 +217,27 @@
 
         factory[-1] = proxyView
 
-    actions=[
-        Action(
-            discriminator = ('view', for_, name, type, layer),
-            callable = checkingHandler,
-            args = (permission, Views,'provideView', for_, name,
-                    type, factory, layer),
-            ),
-        Action(
-            discriminator = None,
-            callable = handler,
-            args = (Interfaces, 'provideInterface',
-                    type.__module__+'.'+type.__name__, type)
-            )
-            ]
+    _context.action(
+        discriminator = ('view', for_, name, type, layer),
+        callable = checkingHandler,
+        args = (permission, Views,'provideView', for_, name,
+                type, factory, layer),
+        )
+    _context.action(
+        discriminator = None,
+        callable = handler,
+        args = (Interfaces, 'provideInterface',
+                type.__module__+'.'+type.__name__, type)
+        )
+
     if for_ is not None:
-        actions.append
-        (
-        Action(
+        _context.action(
             discriminator = None,
             callable = handler,
             args = (Interfaces, 'provideInterface',
                     for_.__module__+'.'+for_.__name__,
                     for_)
-              )
-         )
-
-    return actions
+            )
 
 def defaultView(_context, type, name, for_, **__kw):
 
@@ -299,55 +245,40 @@
         for_ = None
 
     if __kw:
-        actions = view(_context, type=type, name=name, for_=for_, **__kw)
-    else:
-        actions = []
-
-    if for_ is not None:
-        for_ = resolveInterface(_context, for_)
-    type = _context.resolve(type)
+        view(_context, type=type, name=name, for_=for_, **__kw)
 
-    actions += [
-        Action(
+    _context.action(
         discriminator = ('defaultViewName', for_, type, name),
         callable = handler,
         args = (Views,'setDefaultViewName', for_, type, name),
-        ),
-        Action(
-            discriminator = None,
-            callable = handler,
-            args = (Interfaces, 'provideInterface',
-                    type.__module__+'.'+type.__name__, type)
-            )
-               ]
+        )
+    _context.action(
+        discriminator = None,
+        callable = handler,
+        args = (Interfaces, 'provideInterface',
+                type.__module__+'.'+type.__name__, type)
+        )
+
     if for_ is not None:
-        actions.append
-        (
-        Action(
+        _context.action(
             discriminator = None,
             callable = handler,
             args = (Interfaces, 'provideInterface',
                     for_.__module__+'.'+for_.__name__, for_)
-              )
-         )
-
-    return actions
+            )
 
 def serviceType(_context, id, interface):
-    interface = resolveInterface(_context, interface)
-    return [
-        Action(
-            discriminator = ('serviceType', id),
-            callable = managerHandler,
-            args = ('defineService', id, interface),
-            ),
-        Action(
-            discriminator = None,
-            callable = provideInterface,
-            args = (interface.__module__+'.'+interface.__name__,
-                    interface)
-            )
-        ]
+    _context.action(
+        discriminator = ('serviceType', id),
+        callable = managerHandler,
+        args = ('defineService', id, interface),
+        )
+    _context.action(
+        discriminator = None,
+        callable = provideInterface,
+        args = (interface.__module__+'.'+interface.__name__,
+                interface)
+        )
 
 def provideService(serviceType, component, permission):
     # This is needed so we can add a security proxy.
@@ -357,7 +288,6 @@
     service_manager = getServiceManager(None)
 
     if permission:
-
         for stype, interface in service_manager.getServiceDefinitions():
             if stype == serviceType:
                 break
@@ -382,39 +312,33 @@
         if component:
             raise TypeError("Can't specify factory and component.")
 
-        component = _context.resolve(factory)()
-    else:
-        component = _context.resolve(component)
-
-    return [
-        Action(
-            discriminator = ('service', serviceType),
-            callable = provideService,
-            args = (serviceType, component, permission),
-            )
-        ]
+        component = factory()
+
+    _context.action(
+        discriminator = ('service', serviceType),
+        callable = provideService,
+        args = (serviceType, component, permission),
+        )
 
 def skin(_context, name, layers, type):
-    type = _context.resolve(type)
     if ',' in layers:
         raise TypeError("Commas are not allowed in layer names.")
 
-    layers = layers.strip().split()
-    actions = [
-        Action(
-            discriminator = ('skin', name, type),
-            callable = handler,
-            args = (Skins,'defineSkin',name, type, layers)
-              ),
-        Action(
-            discriminator = None,
-            callable = handler,
-            args = (Interfaces, 'provideInterface',
-                    type.__module__+'.'+type.__name__, type)
-              )
-             ]
-    return actions
+    _context.action(
+        discriminator = ('skin', name, type),
+        callable = handler,
+        args = (Skins,'defineSkin',name, type, layers)
+        )
+
+    _context.action(
+        discriminator = None,
+        callable = handler,
+        args = (Interfaces, 'provideInterface',
+                type.__module__+'.'+type.__name__, type)
+        )
 
+# XXX this will have to incorporated into
+# zope.configuration.fields.GlobalObject
 def resolveInterface(_context, id):
     interface = interfaceService.queryInterface(id, None)
     if interface is None:




More information about the Zope3-Checkins mailing list