[Zope3-checkins] CVS: Zope3/src/zope/app/publisher/xmlrpc - metadirectives.py:1.1 meta.zcml:1.3 metaconfigure.py:1.12

Stephan Richter srichter at cosmos.phy.tufts.edu
Sun Aug 3 20:48:23 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app/publisher/xmlrpc
In directory cvs.zope.org:/tmp/cvs-serv4980

Modified Files:
	meta.zcml metaconfigure.py 
Added Files:
	metadirectives.py 
Log Message:
Last ZCML namespace (xmlrpc) converted.


=== Added File Zope3/src/zope/app/publisher/xmlrpc/metadirectives.py ===
##############################################################################
#
# 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.
#
##############################################################################
"""'xmlrpc' ZCML Namespace Schemas

$Id: metadirectives.py,v 1.1 2003/08/03 23:47:47 srichter Exp $
"""
from zope.interface import Interface
from zope.configuration.fields import GlobalObject, Tokens, PythonIdentifier
from zope.schema import TextLine, Id

class IViewDirective(Interface):
    """View Directive for XML-RPC methods."""

    name = TextLine(
        title=u"The name of the view.",
        description=u"The name shows up in URLs/paths. For example 'foo'.",
        required=False)

    factory = Tokens(
        title=u"Factory",
        description=u"Specifies a component that is used to provide the "\
                    u"methods.",
        value_type=GlobalObject(),
        required=False)

    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.""",
        required=False)

    permission = Id(
        title=u"Permission",
        description=u"The permission needed to use the view.",
        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_methods = 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_methods',
        you can make the permission also apply to the extra attributes
        on the view object.""",
        required=False,
        value_type=PythonIdentifier() )


class IMethodDirective(Interface):
    """This is the method subdirective."""

    name = TextLine(
        title=u"The name of the view.",
        description=u"The name shows up in URLs/paths. For example 'foo'.",
        required=True)

    permission = Id(
        title=u"Permission",
        description=u"The permission needed to use the view.",
        required=False)

    attribute = PythonIdentifier(
        title=u"Attribute",
        description=u"The attribute that describes the method that will be "\
                    u"known as 'name'",
        required=False)


=== Zope3/src/zope/app/publisher/xmlrpc/meta.zcml 1.2 => 1.3 ===
--- Zope3/src/zope/app/publisher/xmlrpc/meta.zcml:1.2	Wed Dec 25 09:13:11 2002
+++ Zope3/src/zope/app/publisher/xmlrpc/meta.zcml	Sun Aug  3 19:47:47 2003
@@ -1,16 +1,17 @@
-<zopeConfigure xmlns='http://namespaces.zope.org/zope'>
+<configure 
+    xmlns:meta="http://namespaces.zope.org/meta"
+    xmlns="http://namespaces.zope.org/zope">
   
-<directives namespace="http://namespaces.zope.org/xmlrpc">
-
-  <directive 
+  <meta:complexDirective 
+       namespace="http://namespaces.zope.org/xmlrpc"
        name="view" 
-       attributes="factory for name
-                   permission allowed_interface allowed_methods"
-       handler="zope.app.publisher.xmlrpc.metaconfigure.view">
-     <subdirective name="method" 
-                   attributes="name attribute permission" /> 
-  </directive>
+       schema=".metadirectives.IViewDirective"
+       handler=".metaconfigure.view">
+
+     <meta:subdirective 
+         name="method" 
+         schema=".metadirectives.IMethodDirective" /> 
 
-</directives>
+  </meta:complexDirective>
 
-</zopeConfigure>
+</configure>


=== Zope3/src/zope/app/publisher/xmlrpc/metaconfigure.py 1.11 => 1.12 ===
--- Zope3/src/zope/app/publisher/xmlrpc/metaconfigure.py:1.11	Mon Jul 28 18:21:08 2003
+++ Zope3/src/zope/app/publisher/xmlrpc/metaconfigure.py	Sun Aug  3 19:47:47 2003
@@ -15,19 +15,13 @@
 
 $Id$
 """
-
-from zope.interface import classProvides
-from zope.security.proxy import Proxy
-from zope.security.checker import CheckerPublic, NamesChecker, Checker
-
-from zope.configuration.action import Action
-from zope.configuration.exceptions import ConfigurationError
-
+from zope.app.component.metaconfigure import handler
 from zope.app.services.servicenames import Interfaces
-
+from zope.configuration.exceptions import ConfigurationError
 from zope.publisher.interfaces.xmlrpc import IXMLRPCPresentation
+from zope.security.proxy import Proxy
+from zope.security.checker import CheckerPublic, NamesChecker, Checker
 
-from zope.app.component.metaconfigure import handler, resolveInterface
 
 class view(object):
     '''This view class handles the directives for the XML-RPC Presentation'''
@@ -38,9 +32,6 @@
                  permission=None, allowed_interface=None,
                  allowed_methods=None):
 
-        # Resolve and save the component these views are for
-        if for_ is not None:
-            for_ = resolveInterface(_context, for_)
         self.for_ = for_
 
         if ((allowed_methods or allowed_interface)
@@ -50,10 +41,8 @@
                 "allowed_methods"
                 )
 
-        if allowed_interface is not None:
-            allowed_interface = resolveInterface(_context, allowed_interface)
-
-        self.factory = map(_context.resolve, factory.strip().split())
+        self._context = _context
+        self.factory = factory
         self.name = name
         self.permission = permission
         self.allowed_methods = allowed_methods
@@ -63,7 +52,7 @@
 
     def method(self, _context, name, attribute, permission=None):
         permission = permission or self.permission
-        # make a copy of the factory sequence, sinc ewe might modify it
+        # make a copy of the factory sequence, since we might modify it
         # specifically for this method.
         factory = self.factory[:]
 
@@ -73,36 +62,32 @@
             if permission == 'zope.Public':
                 permission = CheckerPublic
 
-            def methodView(context, request,
-                         factory=factory[-1], attribute=attribute,
-                         permission=permission):
+            def methodView(context, request, factory=factory[-1],
+                           attribute=attribute, permission=permission):
+
                 return Proxy(getattr(factory(context, request), attribute),
                              NamesChecker(__call__ = permission))
         else:
 
-            def methodView(context, request,
-                         factory=factory[-1], attribute=attribute):
+            def methodView(context, request, factory=factory[-1],
+                           attribute=attribute):
                 return getattr(factory(context, request), attribute)
 
         factory[-1] = methodView
 
         self.methods += 1
 
-        return [
-            Action(
-                discriminator = ('view', self.for_, name, self.type),
-                callable = handler,
-                args = ('Views', 'provideView', self.for_, name, self.type,
-                        factory),
-                )
-            ]
+        _context.action(
+            discriminator = ('view', self.for_, name, self.type),
+            callable = handler,
+            args = ('Views', 'provideView', self.for_, name, self.type, factory)
+            )
 
 
     def _proxyFactory(self, factory, checker):
         factory = factory[:]
 
-        def proxyView(context, request,
-                      factory=factory[-1], checker=checker):
+        def proxyView(context, request, factory=factory[-1], checker=checker):
 
             view = factory(context, request)
 
@@ -119,27 +104,26 @@
 
     def __call__(self):
         if self.name is None:
-            return ()
+            return
 
         permission = self.permission
-        allowed_interface = self.allowed_interface
-        allowed_methods = self.allowed_methods
+        allowed_interface = self.allowed_interface or []
+        allowed_methods = self.allowed_methods or []
         factory = self.factory[:]
 
+
         if permission:
             if permission == 'zope.Public':
                 permission = CheckerPublic
 
-            if ((not allowed_methods) and (allowed_interface is None)
-                and (not self.methods)):
-                allowed_methods = self.default_allowed_methods
-
             require = {}
-            for name in (allowed_methods or '').split():
+            for name in allowed_methods:
                 require[name] = permission
+
             if allowed_interface:
-                for name in allowed_interface.names(all=True):
-                    require[name] = permission
+                for iface in allowed_interface:
+                    for name in iface:
+                        require[name] = permission
 
             checker = Checker(require.get)
 
@@ -153,22 +137,16 @@
 
             factory[-1] =  proxyView
 
-        actions = [
-            Action(
+        self._context.action(
             discriminator = ('view', self.for_, self.name, self.type),
             callable = handler,
             args = ('Views', 'provideView', self.for_, self.name,
-                    self.type, factory),
-            )
-            ]
+                    self.type, factory) )
+
         if self.for_ is not None:
-            actions.append
-            (
-                Action(
+            self._context.action(
                 discriminator = None,
                 callable = handler,
                 args = (Interfaces, 'provideInterface',
                         self.for_.__module__+'.'+self.for_.__name__, self.for_)
                 )
-                )
-        return actions




More information about the Zope3-Checkins mailing list