[Zope3-checkins] CVS: Zope3/src/zope/configuration - backward.py:1.2

Jim Fulton jim@zope.com
Wed, 30 Jul 2003 14:35:43 -0400


Update of /cvs-repository/Zope3/src/zope/configuration
In directory cvs.zope.org:/tmp/cvs-serv7787/src/zope/configuration

Modified Files:
	backward.py 
Log Message:
Added support for including an attribute named "*" when using the old
meta-configuration directives to allow arbitrary parameters.

(For new-style directives, this is signalled by setting the
"keyword_arguments" tagged value to true on the directive schema.)


=== Zope3/src/zope/configuration/backward.py 1.1 => 1.2 ===
--- Zope3/src/zope/configuration/backward.py:1.1	Mon Jul 28 18:22:39 2003
+++ Zope3/src/zope/configuration/backward.py	Wed Jul 30 14:35:09 2003
@@ -139,7 +139,7 @@
     constructor:
 
     >>> context = config.ConfigurationMachine()
-    >>> x = Attributed(config, attributes=u"a b c")
+    >>> x = Attributed(context, attributes=u"a b c")
 
     Or the can be provides as keys added to the attributes disctionary:
 
@@ -156,11 +156,38 @@
     Text b b 0
     Int foo Foo 1
 
+    If you need to be able to accept arbritrary parameters, include an
+    attribute named "*" in the list of attributes:
+
+    >>> context = config.ConfigurationMachine()
+    >>> x = Attributed(context, attributes=u"a b c *")
+    >>> x._schema_from_attrs()
+    >>> for name in x.schema:
+    ...   f = x.schema[name]
+    ...   print f.__class__.__name__, f.__name__, f.title, int(f.required)
+    Text a a 0
+    Text c c 0
+    Text b b 0
+
+    Note that we don't see "*" in the schema. Rather, we see that the
+    schema as a tagged value:
+
+    >>> x.schema.getTaggedValue("keyword_arguments")
+    1
+
+    Indicating that the directive handler accepts extra keyword
+    arguments, which means that arbitrary extra parameters can be given.
     """
 
     interface.implementsOnly(IDescribed)
 
+    __keyword_arguments = False
+
     def attribute(self, name, required=False, description=u''):
+        if name == '*':
+            self.__keyword_arguments = True
+            return
+        
         aname = str(name)
         if iskeyword(name):
             aname += '_'
@@ -186,6 +213,9 @@
             # No attribute definitions, allow keyword args
             schema.setTaggedValue('keyword_arguments', True)
         self.schema = schema
+
+        if self.__keyword_arguments:
+            schema.setTaggedValue('keyword_arguments', True)
     
 
 class Directive(Attributed, Described):