[Checkins] SVN: zope.generic/trunk/src/zope/generic/ new directive
to register configuration interfaces
Dominik Huber
dominik.huber at perse.ch
Wed May 10 08:30:37 EDT 2006
Log message for revision 68073:
new directive to register configuration interfaces
Changed:
U zope.generic/trunk/src/zope/generic/adapter/README.txt
U zope.generic/trunk/src/zope/generic/adapter/adapter.py
U zope.generic/trunk/src/zope/generic/configuration/README.txt
U zope.generic/trunk/src/zope/generic/configuration/base.py
U zope.generic/trunk/src/zope/generic/configuration/interfaces.py
A zope.generic/trunk/src/zope/generic/configuration/meta.zcml
A zope.generic/trunk/src/zope/generic/configuration/metaconfigure.py
A zope.generic/trunk/src/zope/generic/configuration/metadirectives.py
U zope.generic/trunk/src/zope/generic/configuration/testing.py
A zope.generic/trunk/src/zope/generic/configuration/zope.generic.configuration-meta.zcml
U zope.generic/trunk/src/zope/generic/content/EXAMPLE.txt
U zope.generic/trunk/src/zope/generic/content/README.txt
U zope.generic/trunk/src/zope/generic/factory/README.txt
U zope.generic/trunk/src/zope/generic/factory/factory.py
U zope.generic/trunk/src/zope/generic/informationprovider/NEW_README.txt
U zope.generic/trunk/src/zope/generic/informationprovider/README.txt
U zope.generic/trunk/src/zope/generic/operation/README.txt
-=-
Modified: zope.generic/trunk/src/zope/generic/adapter/README.txt
===================================================================
--- zope.generic/trunk/src/zope/generic/adapter/README.txt 2006-05-10 08:24:46 UTC (rev 68072)
+++ zope.generic/trunk/src/zope/generic/adapter/README.txt 2006-05-10 12:30:36 UTC (rev 68073)
@@ -46,9 +46,8 @@
We register the configuration schema using generic:face directive:
>>> registerDirective('''
- ... <generic:interface
- ... interface="example.IFooConfiguration"
- ... type="zope.generic.configuration.IConfigurationType"
+ ... <generic:configuration
+ ... keyface="example.IFooConfiguration"
... />
... ''')
Modified: zope.generic/trunk/src/zope/generic/adapter/adapter.py
===================================================================
--- zope.generic/trunk/src/zope/generic/adapter/adapter.py 2006-05-10 08:24:46 UTC (rev 68072)
+++ zope.generic/trunk/src/zope/generic/adapter/adapter.py 2006-05-10 12:30:36 UTC (rev 68073)
@@ -55,9 +55,8 @@
We register the configuration schema using generic:face directive:
>>> registerDirective('''
- ... <generic:interface
- ... interface="example.IFooConfiguration"
- ... type="zope.generic.configuration.IConfigurationType"
+ ... <generic:configuration
+ ... keyface="example.IFooConfiguration"
... />
... ''')
@@ -71,9 +70,8 @@
... pass
>>> registerDirective('''
- ... <generic:interface
- ... interface="example.IFoo"
- ... type="zope.generic.face.IKeyfaceType"
+ ... <generic:configuration
+ ... keyface="example.IFoo"
... />
... ''')
Modified: zope.generic/trunk/src/zope/generic/configuration/README.txt
===================================================================
--- zope.generic/trunk/src/zope/generic/configuration/README.txt 2006-05-10 08:24:46 UTC (rev 68072)
+++ zope.generic/trunk/src/zope/generic/configuration/README.txt 2006-05-10 12:30:36 UTC (rev 68073)
@@ -21,17 +21,15 @@
of a configuration object too. The configuration object itself has to provide
the schema too.
- >>> from zope.interface import Interface
>>> from zope.schema import TextLine
- >>> class IFooConfiguration(Interface):
+ >>> class IFooConfiguration(interface.Interface):
... foo = TextLine(title=u'Foo')
... optional = TextLine(title=u'Optional', required=False, default=u'Bla')
>>> registerDirective('''
- ... <generic:interface
- ... interface="example.IFooConfiguration"
- ... type="zope.generic.configuration.IConfigurationType"
+ ... <generic:configuration
+ ... keyface="example.IFooConfiguration"
... />
... ''')
@@ -87,7 +85,7 @@
... if a value might be set to the configurations it must provide the
configuration schema itself. This key interface must provide IConfiguration:
- >>> class IBarConfiguration(Interface):
+ >>> class IBarConfiguration(interface.Interface):
... bar = TextLine(title=u'Bar')
>>> configurations[IBarConfiguration] = object()
@@ -190,3 +188,94 @@
>>> event = events.pop()
>>> [(key.__name__, value) for key, value in event.items()]
[('IFooConfiguration', {})]
+
+Nested Configurations
+---------------------
+
+The configuration directive does evaluate if an key interface is nested:
+
+ >>> from zope.schema import Object
+
+ >>> class ISubConfigurationConfiguration(interface.Interface):
+ ... foo = Object(schema=IFooConfiguration)
+
+ >>> registerDirective('''
+ ... <generic:configuration
+ ... keyface="example.ISubConfigurationConfiguration"
+ ... />
+ ... ''')
+
+ >>> api.INestedConfigurationType.providedBy(ISubConfigurationConfiguration)
+ True
+
+ >>> from zope.schema import Tuple
+
+ >>> class ISubTupleConfiguration(interface.Interface):
+ ... foo = Tuple(value_type=TextLine())
+
+ >>> registerDirective('''
+ ... <generic:configuration
+ ... keyface="example.ISubTupleConfiguration"
+ ... />
+ ... ''')
+
+ >>> api.INestedConfigurationType.providedBy(ISubTupleConfiguration)
+ True
+
+ >>> from zope.schema import Tuple
+
+You can suppress the evaluation by an explicite declaration using the nested
+attribute:
+
+ >>> class ISuppressedContainerConfiguration(interface.Interface):
+ ... foo = Tuple(value_type=TextLine())
+
+ >>> registerDirective('''
+ ... <generic:configuration
+ ... keyface="example.ISuppressedContainerConfiguration"
+ ... nested="False"
+ ... />
+ ... ''')
+
+ >>> api.INestedConfigurationType.providedBy(ISuppressedContainerConfiguration)
+ False
+
+We can create nested configurations by a dictionary where the hierarchy is
+reflected by dotted names.
+
+First test nested configuration:
+
+# >>> data = {'foo.foo': u'bla', 'foo.optional': u'Blu'}
+# >>> config = api.ConfigurationData(ISubConfigurationConfiguration, data)
+# >>> IFooConfiguration.providedBy(config.foo)
+# True
+# >>> config.foo.foo
+# u'bla'
+# >>> config.foo.optional
+# u'Blu'
+#
+# >>> data = {'foo.foo': u'xxx'}
+# >>> config = api.ConfigurationData(ISubConfigurationConfiguration, data)
+# >>> IFooConfiguration.providedBy(config.foo)
+# True
+# >>> config.foo.foo
+# u'xxx'
+# >>> config.foo.optional
+# u'Bla'
+#
+# >>> data = {'foo.optional': u'Blu'}
+# >>> config = api.ConfigurationData(ISubConfigurationConfiguration, data)
+# Traceback (most recent call last):
+# ...
+# TypeError: __init__ requires 'foo.foo' of 'ISubConfigurationConfiguration'.
+#
+# >>> subdata = {'foo': u'bla', 'optional': u'Blu'}
+# >>> subconfig = api.ConfigurationData(IFooConfiguration, subdata)
+# >>> data = {'foo': subconfig}
+# >>> config = api.ConfigurationData(ISubConfigurationConfiguration, data)
+# >>> IFooConfiguration.providedBy(config.foo)
+# True
+# >>> config.foo.foo
+# u'bla'
+# >>> config.foo.optional
+# u'Blu'
Modified: zope.generic/trunk/src/zope/generic/configuration/base.py
===================================================================
--- zope.generic/trunk/src/zope/generic/configuration/base.py 2006-05-10 08:24:46 UTC (rev 68072)
+++ zope.generic/trunk/src/zope/generic/configuration/base.py 2006-05-10 12:30:36 UTC (rev 68073)
@@ -76,7 +76,7 @@
subdata = subData(name, data)
if subdata or field.required is True:
data[name] = ConfigurationData(field.schema, subData(name, data))
- break
+ continue
except:
pass
Modified: zope.generic/trunk/src/zope/generic/configuration/interfaces.py
===================================================================
--- zope.generic/trunk/src/zope/generic/configuration/interfaces.py 2006-05-10 08:24:46 UTC (rev 68072)
+++ zope.generic/trunk/src/zope/generic/configuration/interfaces.py 2006-05-10 12:30:36 UTC (rev 68073)
@@ -40,6 +40,11 @@
+class INestedConfigurationType(IConfigurationType):
+ """Type a key schema that contains nested configuraiton."""
+
+
+
class IConfigurationData(IFaced):
"""Marker for configuration data implementations."""
Added: zope.generic/trunk/src/zope/generic/configuration/meta.zcml
===================================================================
--- zope.generic/trunk/src/zope/generic/configuration/meta.zcml 2006-05-10 08:24:46 UTC (rev 68072)
+++ zope.generic/trunk/src/zope/generic/configuration/meta.zcml 2006-05-10 12:30:36 UTC (rev 68073)
@@ -0,0 +1,15 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ xmlns:meta="http://namespaces.zope.org/meta">
+
+ <meta:directives namespace="http://namespaces.zope.org/generic">
+
+ <meta:directive
+ name="configuration"
+ schema=".metadirectives.IConfigurationDirective"
+ handler=".metaconfigure.configurationDirective"
+ />
+
+ </meta:directives>
+
+</configure>
Property changes on: zope.generic/trunk/src/zope/generic/configuration/meta.zcml
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: zope.generic/trunk/src/zope/generic/configuration/metaconfigure.py
===================================================================
--- zope.generic/trunk/src/zope/generic/configuration/metaconfigure.py 2006-05-10 08:24:46 UTC (rev 68072)
+++ zope.generic/trunk/src/zope/generic/configuration/metaconfigure.py 2006-05-10 12:30:36 UTC (rev 68073)
@@ -0,0 +1,54 @@
+##############################################################################
+#
+# Copyright (c) 2005, 2006 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.
+#
+##############################################################################
+
+"""
+$Id$
+"""
+
+__docformat__ = 'restructuredtext'
+
+from zope.component.interface import provideInterface
+from zope.schema.interfaces import IDict
+from zope.schema.interfaces import ISequence
+from zope.schema.interfaces import IObject
+
+from zope.generic.configuration import IConfigurationType
+from zope.generic.configuration import INestedConfigurationType
+
+
+
+def configurationDirective(_context, keyface, nested=None):
+ """Type configuration key interface by IConfiugrationType."""
+
+ # assume that the correct type was set
+ if IConfigurationType.providedBy(keyface):
+ return
+
+ type = IConfigurationType
+ if nested:
+ type = INestedConfigurationType
+
+ # evaluate if nested
+ elif nested is None:
+ for name in keyface:
+ field = keyface[name]
+ if IObject.providedBy(field) and IConfigurationType.providedBy(field.schema):
+ type = INestedConfigurationType
+ break
+
+ elif ISequence.providedBy(field) or IDict.providedBy(field):
+ type = INestedConfigurationType
+ break
+
+ provideInterface(None, keyface, type)
Property changes on: zope.generic/trunk/src/zope/generic/configuration/metaconfigure.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: zope.generic/trunk/src/zope/generic/configuration/metadirectives.py
===================================================================
--- zope.generic/trunk/src/zope/generic/configuration/metadirectives.py 2006-05-10 08:24:46 UTC (rev 68072)
+++ zope.generic/trunk/src/zope/generic/configuration/metadirectives.py 2006-05-10 12:30:36 UTC (rev 68073)
@@ -0,0 +1,41 @@
+##############################################################################
+#
+# Copyright (c) 2005, 2006 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.
+#
+##############################################################################
+
+"""
+$Id$
+"""
+
+__docformat__ = 'restructuredtext'
+
+from zope.app.i18n import ZopeMessageFactory as _
+from zope.configuration.fields import Bool
+from zope.configuration.fields import GlobalInterface
+from zope.interface import Interface
+
+
+class IConfigurationDirective(Interface):
+ """Type a configuration key interface."""
+
+ keyface = GlobalInterface(
+ title=_('Key Interface'),
+ description=_('Type a key interface to a configuration or nested '
+ 'configuration type.'),
+ required=True,
+ )
+
+ nested = Bool(
+ title=_('Nested'),
+ description=_('Turn on nested configuration support.'),
+ required=False,
+ )
Property changes on: zope.generic/trunk/src/zope/generic/configuration/metadirectives.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: zope.generic/trunk/src/zope/generic/configuration/testing.py
===================================================================
--- zope.generic/trunk/src/zope/generic/configuration/testing.py 2006-05-10 08:24:46 UTC (rev 68072)
+++ zope.generic/trunk/src/zope/generic/configuration/testing.py 2006-05-10 12:30:36 UTC (rev 68073)
@@ -26,6 +26,7 @@
from zope.component import provideAdapter
from zope.component.eventtesting import clearEvents
+from zope.configuration.xmlconfig import XMLConfig
from zope.interface import Interface
from zope.schema import TextLine
@@ -60,6 +61,7 @@
fo = TextLine(title=u'Fo', required=False, readonly=True, default=u'fo default')
+
class TestAttributeFaced(object):
__keyface__ = IFooConfiguration
@@ -78,6 +80,9 @@
provideAdapter(zope.generic.configuration.adapter.AttributeConfigurations,
provides=IConfigurations)
+ import zope.generic.configuration
+ XMLConfig('meta.zcml', zope.generic.configuration)()
+
clearEvents()
def tearDown(doctest=None):
Added: zope.generic/trunk/src/zope/generic/configuration/zope.generic.configuration-meta.zcml
===================================================================
--- zope.generic/trunk/src/zope/generic/configuration/zope.generic.configuration-meta.zcml 2006-05-10 08:24:46 UTC (rev 68072)
+++ zope.generic/trunk/src/zope/generic/configuration/zope.generic.configuration-meta.zcml 2006-05-10 12:30:36 UTC (rev 68073)
@@ -0,0 +1,5 @@
+<configure xmlns="http://namespaces.zope.org/zope">
+
+ <include package="zope.generic.configuration" file="meta.zcml" />
+
+</configure>
Property changes on: zope.generic/trunk/src/zope/generic/configuration/zope.generic.configuration-meta.zcml
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: zope.generic/trunk/src/zope/generic/content/EXAMPLE.txt
===================================================================
--- zope.generic/trunk/src/zope/generic/content/EXAMPLE.txt 2006-05-10 08:24:46 UTC (rev 68072)
+++ zope.generic/trunk/src/zope/generic/content/EXAMPLE.txt 2006-05-10 12:30:36 UTC (rev 68073)
@@ -22,23 +22,20 @@
... """Logical article marker"""
>>> registerDirective('''
- ... <generic:interface
- ... interface="example.IText"
- ... type="zope.generic.face.IKeyfaceType"
+ ... <generic:configuration
+ ... keyface="example.IText"
... />
... ''')
>>> registerDirective('''
- ... <generic:interface
- ... interface="example.INote"
- ... type="zope.generic.face.IKeyfaceType"
+ ... <generic:configuration
+ ... keyface="example.INote"
... />
... ''')
>>> registerDirective('''
- ... <generic:interface
- ... interface="example.IArticle"
- ... type="zope.generic.face.IKeyfaceType"
+ ... <generic:configuration
+ ... keyface="example.IArticle"
... />
... ''')
@@ -61,23 +58,20 @@
... note = schema.Text(title=u"Note body", required=False)
>>> registerDirective('''
- ... <generic:interface
- ... interface="example.ITextConfig"
- ... type="zope.generic.configuration.IConfigurationType"
+ ... <generic:configuration
+ ... keyface="example.ITextConfig"
... />
... ''')
>>> registerDirective('''
- ... <generic:interface
- ... interface="example.INoteConfig"
- ... type="zope.generic.configuration.IConfigurationType"
+ ... <generic:configuration
+ ... keyface="example.INoteConfig"
... />
... ''')
>>> registerDirective('''
- ... <generic:interface
- ... interface="example.IArticleInitializationConfiguration"
- ... type="zope.generic.configuration.IConfigurationType"
+ ... <generic:configuration
+ ... keyface="example.IArticleInitializationConfiguration"
... />
... ''')
Modified: zope.generic/trunk/src/zope/generic/content/README.txt
===================================================================
--- zope.generic/trunk/src/zope/generic/content/README.txt 2006-05-10 08:24:46 UTC (rev 68072)
+++ zope.generic/trunk/src/zope/generic/content/README.txt 2006-05-10 12:30:36 UTC (rev 68073)
@@ -125,16 +125,14 @@
... optional = TextLine(title=u'Other', required=False, default=u'Default bla.')
>>> registerDirective('''
- ... <generic:interface
- ... interface="example.IAnyConfiguration"
- ... type="zope.generic.configuration.IConfigurationType"
+ ... <generic:configuration
+ ... keyface="example.IAnyConfiguration"
... />
... ''')
>>> registerDirective('''
- ... <generic:interface
- ... interface="example.IOtherConfiguration"
- ... type="zope.generic.configuration.IConfigurationType"
+ ... <generic:configuration
+ ... keyface="example.IOtherConfiguration"
... />
... ''')
Modified: zope.generic/trunk/src/zope/generic/factory/README.txt
===================================================================
--- zope.generic/trunk/src/zope/generic/factory/README.txt 2006-05-10 08:24:46 UTC (rev 68072)
+++ zope.generic/trunk/src/zope/generic/factory/README.txt 2006-05-10 12:30:36 UTC (rev 68073)
@@ -47,9 +47,8 @@
... c = TextLine(required=False, default=u'c default')
>>> registerDirective('''
- ... <generic:interface
- ... interface="example.IMyParameter"
- ... type="zope.generic.configuration.IConfigurationType"
+ ... <generic:configuration
+ ... keyface="example.IMyParameter"
... />
... ''')
Modified: zope.generic/trunk/src/zope/generic/factory/factory.py
===================================================================
--- zope.generic/trunk/src/zope/generic/factory/factory.py 2006-05-10 08:24:46 UTC (rev 68072)
+++ zope.generic/trunk/src/zope/generic/factory/factory.py 2006-05-10 12:30:36 UTC (rev 68073)
@@ -155,9 +155,8 @@
... c = TextLine(required=False, default=u'c default')
>>> registerDirective('''
- ... <generic:interface
- ... interface="example.IMyParameter"
- ... type="zope.generic.configuration.IConfigurationType"
+ ... <generic:configuration
+ ... keyface="example.IMyParameter"
... />
... ''')
Modified: zope.generic/trunk/src/zope/generic/informationprovider/NEW_README.txt
===================================================================
--- zope.generic/trunk/src/zope/generic/informationprovider/NEW_README.txt 2006-05-10 08:24:46 UTC (rev 68072)
+++ zope.generic/trunk/src/zope/generic/informationprovider/NEW_README.txt 2006-05-10 12:30:36 UTC (rev 68073)
@@ -40,9 +40,8 @@
be done the following way:
>>> registerDirective('''
- ... <generic:interface
- ... interface="example.ILogConfiguration"
- ... type="zope.generic.configuration.IConfigurationType"
+ ... <generic:configuration
+ ... keyface="example.ILogConfiguration"
... />
... ''')
Modified: zope.generic/trunk/src/zope/generic/informationprovider/README.txt
===================================================================
--- zope.generic/trunk/src/zope/generic/informationprovider/README.txt 2006-05-10 08:24:46 UTC (rev 68072)
+++ zope.generic/trunk/src/zope/generic/informationprovider/README.txt 2006-05-10 12:30:36 UTC (rev 68073)
@@ -114,9 +114,8 @@
... my = TextLine(title=u'My')
>>> registerDirective('''
- ... <generic:interface
- ... interface="example.IMyConfiguration"
- ... type="zope.generic.configuration.IConfigurationType"
+ ... <generic:configuration
+ ... keyface="example.IMyConfiguration"
... />
... ''')
@@ -405,9 +404,8 @@
... text = Text(title=u'Text', required=False, default=u'Bla\\n')
>>> registerDirective('''
- ... <generic:interface
- ... interface="example.IOneConfiguration"
- ... type="zope.generic.configuration.IConfigurationType"
+ ... <generic:configuration
+ ... keyface="example.IOneConfiguration"
... />
... ''')
@@ -418,9 +416,8 @@
... int = Int(title=u'Int', required=False, default=42)
>>> registerDirective('''
- ... <generic:interface
- ... interface="example.IOtherConfiguration"
- ... type="zope.generic.configuration.IConfigurationType"
+ ... <generic:configuration
+ ... keyface="example.IOtherConfiguration"
... />
... ''')
@@ -434,9 +431,8 @@
... dict = Dict(title=u'Dict of TextLine', value_type=TextLine())
>>> registerDirective('''
- ... <generic:interface
- ... interface="example.INestedConfiguration"
- ... type="zope.generic.configuration.IConfigurationType"
+ ... <generic:configuration
+ ... keyface="example.INestedConfiguration"
... />
... ''')
Modified: zope.generic/trunk/src/zope/generic/operation/README.txt
===================================================================
--- zope.generic/trunk/src/zope/generic/operation/README.txt 2006-05-10 08:24:46 UTC (rev 68072)
+++ zope.generic/trunk/src/zope/generic/operation/README.txt 2006-05-10 12:30:36 UTC (rev 68073)
@@ -38,16 +38,14 @@
We have to register those parts:
>>> registerDirective('''
- ... <generic:interface
- ... interface="example.IAnyInput"
- ... type="zope.generic.configuration.IConfigurationType"
+ ... <generic:configuration
+ ... keyface="example.IAnyInput"
... />
... ''')
>>> registerDirective('''
- ... <generic:interface
- ... interface="example.IAnyOutput"
- ... type="zope.generic.configuration.IConfigurationType"
+ ... <generic:configuration
+ ... keyface="example.IAnyOutput"
... />
... ''')
@@ -117,9 +115,8 @@
... print 'Pau input: a=%s.' % (input.a)
>>> registerDirective('''
- ... <generic:interface
- ... interface="example.IPAUConfig"
- ... type="zope.generic.configuration.IConfigurationType"
+ ... <generic:configuration
+ ... keyface="example.IPAUConfig"
... />
... ''')
@@ -155,9 +152,8 @@
... any = TextLine()
>>> registerDirective('''
- ... <generic:interface
- ... interface="example.IComplexConfig"
- ... type="zope.generic.configuration.IConfigurationType"
+ ... <generic:configuration
+ ... keyface="example.IComplexConfig"
... />
... ''')
More information about the Checkins
mailing list