[Zope3-checkins] CVS: Zope3/src/zope/app/schema - metaconfigure.py:1.1 metadirectives.py:1.1 configure.zcml:1.3 meta.zcml:1.5 vocabulary.py:1.4

Stephan Richter srichter@cosmos.phy.tufts.edu
Fri, 1 Aug 2003 17:49:11 -0400


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

Modified Files:
	configure.zcml meta.zcml vocabulary.py 
Added Files:
	metaconfigure.py metadirectives.py 
Log Message:
Converted vocabulary directive to new Configuration mechanism.


=== Added File Zope3/src/zope/app/schema/metaconfigure.py ===
##############################################################################
#
# Copyright (c) 2003 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.
#
##############################################################################
"""ZCML special vocabulary directive handlers

$Id: metaconfigure.py,v 1.1 2003/08/01 21:48:34 srichter Exp $
"""
import zope.app.schema.vocabulary

__metaclass__ = type


class FactoryKeywordPasser:
    """Helper that passes additional keywords to the actual factory."""

    def __init__(self, factory, kwargs):
        self.factory = factory
        self.kwargs = kwargs

    def __call__(self, object):
        return self.factory(object, **self.kwargs)


def vocabulary(_context, name, factory, **kw):
    service = zope.app.schema.vocabulary.vocabularyService
    if kw:
        factory = FactoryKeywordPasser(factory, kw)
    _context.action(
        discriminator=('defineVocabulary', name),
        callable=service.register,
        args=(name, factory) )



=== Added File Zope3/src/zope/app/schema/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.
#
##############################################################################
"""Renderer configuration code

$Id: metadirectives.py,v 1.1 2003/08/01 21:48:34 srichter Exp $
"""
from zope.configuration.fields import GlobalObject
from zope.interface import Interface
from zope.schema import TextLine

class IVocabularyDirective(Interface):
    '''Define a named vocabulary.
    
    This associates a vocabulary name in the global vocabulary service with a
    factory.  Each name may only be defined once.

    Additional keyword arguments may be passed to the factory by adding
    additional attributes beyond those listed here.  This can be useful when
    using vocabularies which implement various kinds of filtering.

    Example::

       <vocabulary
           name="garys-favorite-path-references"
           factory="zope.app.gary.paths.Favorites" />
    '''

    name = TextLine(
        title=u"Name",
        description=u'Provides a title for the source type.", The name of the '\
                    u'vocabulary; this can be used as the value for the ' \
                    u'"vocabulary" argument to the VocabularyField and ' \
                    u'VocabularyMultiField constructors to cause this ' \
                    u'vocabulary to be used.',
        required=True)

    factory = GlobalObject(
        title=u"Factory",
        description=u"Factory that returns an instance of the named " \
                    u"vocabulary when called with the context object as " \
                    u"the only argument.  This should be a dotted-name " \
                    u"that refers to a Python object.",
        required=True)


# Arbitrary keys and values are allowed to be passed to the vocabulary source.
IVocabularyDirective.setTaggedValue('keyword_arguments', True)


=== Zope3/src/zope/app/schema/configure.zcml 1.2 => 1.3 ===
--- Zope3/src/zope/app/schema/configure.zcml:1.2	Tue May 20 12:10:29 2003
+++ Zope3/src/zope/app/schema/configure.zcml	Fri Aug  1 17:48:34 2003
@@ -1,10 +1,12 @@
-<zopeConfigure xmlns='http://namespaces.zope.org/zope'>
+<configure xmlns="http://namespaces.zope.org/zope">
 
-<serviceType id='Vocabularies'
-             interface='zope.schema.interfaces.IVocabularyRegistry' />
+  <serviceType 
+      id="Vocabularies"
+      interface="zope.schema.interfaces.IVocabularyRegistry" />
+  
+  <service 
+      serviceType="Vocabularies"
+      permission="zope.Public"
+      component="zope.app.schema.vocabulary.vocabularyService" />
 
-<service serviceType='Vocabularies'
-         permission='zope.Public'
-         component='zope.app.schema.vocabulary.vocabularyService' />
-
-</zopeConfigure>
+</configure>


=== Zope3/src/zope/app/schema/meta.zcml 1.4 => 1.5 ===
--- Zope3/src/zope/app/schema/meta.zcml:1.4	Wed Jul 30 15:08:43 2003
+++ Zope3/src/zope/app/schema/meta.zcml	Fri Aug  1 17:48:34 2003
@@ -1,52 +1,11 @@
-<zopeConfigure xmlns='http://namespaces.zope.org/zope'>
-<directives namespace="http://namespaces.zope.org/zope">
+<configure
+    xmlns="http://namespaces.zope.org/zope"
+    xmlns:meta="http://namespaces.zope.org/meta">
+
+  <meta:directive 
+      namespace="http://namespaces.zope.org/zope"
+      name="vocabulary" 
+      schema=".metadirectives.IVocabularyDirective"
+      handler=".metaconfigure.vocabulary" />
 
-  <directive name="vocabulary" handler=".vocabulary.register">
-    <!-- example:
-         <vocabulary name="garys-favorite-path-references"
-                     factory="zope.app.gary.paths.Favorites" />
-      -->
-
-    <description>
-      Define a named vocabulary.
-
-      This associates a vocabulary name in the global vocabulary
-      service with a factory.  Each name may only be defined once.
-
-      Additional keyword arguments may be passed to the factory by
-      adding additional attributes beyond those listed here.  This can
-      be useful when using vocabularies which implement various kinds
-      of filtering.
-    </description>
-
-    <attribute name="name" required="yes">
-      <description>
-        The name of the vocabulary; this can be used as the value for
-        the "vocabulary" argument to the VocabularyField and
-        VocabularyMultiField constructors to cause this vocabulary to
-        be used.
-      </description>
-    </attribute>
-
-    <attribute name="factory" required="yes">
-      <description>
-        Factory that returns an instance of the named vocabulary when
-        called with the context object as the only argument.  This
-        should be a dotted-name that refers to a Python object.
-      </description>
-    </attribute>
-
-    <attribute name="*" required="no">
-      <description>
-        Arbitrary keys and values are allowed to be passed to the vocabulary
-        source.
-      </description>
-    </attribute>
-
-    <attribute name="filter" />
-    <attribute name="another" />
-
-  </directive>
-
-</directives>
-</zopeConfigure>
+</configure>


=== Zope3/src/zope/app/schema/vocabulary.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/schema/vocabulary.py:1.3	Wed Jun  4 06:46:37 2003
+++ Zope3/src/zope/app/schema/vocabulary.py	Fri Aug  1 17:48:34 2003
@@ -11,38 +11,17 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
+"""Implementation of ZCML action to register vocabulary factories.
 
-"""Implementation of ZCML action to register vocabulary factories."""
-
+$Id$
+"""
 from zope.interface import implements
 from zope.component import getService
-from zope.configuration.action import Action
 from zope.schema import vocabulary
 from zope.schema.interfaces import IVocabularyRegistry
 from zope.testing import cleanup
 
 __metaclass__ = type
-
-def register(_context, name, factory, **kw):
-    factory = _context.resolve(factory.strip())
-    if kw:
-        factory = FactoryKeywordPasser(factory, kw)
-    return [
-        Action(discriminator=('defineVocabulary', name),
-               callable=vocabularyService.register,
-               args=(name, factory))
-        ]
-
-
-class FactoryKeywordPasser:
-    """Helper that passes additional keywords to the actual factory."""
-
-    def __init__(self, factory, kwargs):
-        self.factory = factory
-        self.kwargs = kwargs
-
-    def __call__(self, object):
-        return self.factory(object, **self.kwargs)
 
 
 class ZopeVocabularyRegistry: