[Zope3-checkins] CVS: Zope3/src/zope/app/schema - vocabulary.py:1.1.2.4

Fred L. Drake, Jr. fred@zope.com
Wed, 14 May 2003 13:49:39 -0400


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

Modified Files:
      Tag: schema-vocabulary-branch
	vocabulary.py 
Log Message:
- allow additional keyword args to be associated with the call to a
  vocabulary factory
- add tests for the ZCML integration


=== Zope3/src/zope/app/schema/vocabulary.py 1.1.2.3 => 1.1.2.4 ===
--- Zope3/src/zope/app/schema/vocabulary.py:1.1.2.3	Thu May  8 12:38:27 2003
+++ Zope3/src/zope/app/schema/vocabulary.py	Wed May 14 13:49:08 2003
@@ -21,13 +21,24 @@
 from zope.testing import cleanup
 
 
-def register(_context, name, factory):
-    factory = _context.resolve(factory)
+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:
+    def __init__(self, factory, kwargs):
+        self.factory = factory
+        self.kwargs = kwargs
+
+    def __call__(self, object):
+        return self.factory(object, **self.kwargs)
 
 
 class ZopeVocabularyRegistry(object):