[Zope3-checkins] CVS: Zope3/src/zope/app/schema - configure.zcml:1.5 metaconfigure.py:1.2 vocabulary.py:1.5

Stephan Richter srichter at cosmos.phy.tufts.edu
Wed Mar 3 17:54:58 EST 2004


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

Modified Files:
	configure.zcml metaconfigure.py vocabulary.py 
Log Message:


The Zope Vocabulary Registry now uses utilities for the vocabulary factories.


=== Zope3/src/zope/app/schema/configure.zcml 1.4 => 1.5 ===
--- Zope3/src/zope/app/schema/configure.zcml:1.4	Mon Aug  4 19:38:35 2003
+++ Zope3/src/zope/app/schema/configure.zcml	Wed Mar  3 17:54:27 2004
@@ -1,14 +1,5 @@
 <configure xmlns="http://namespaces.zope.org/zope">
 
-  <serviceType
-      id="Vocabularies"
-      interface="zope.schema.interfaces.IVocabularyRegistry" />
-
-  <service
-      serviceType="Vocabularies"
-      permission="zope.Public"
-      component="zope.app.schema.vocabulary.vocabularyService" />
-
   <include file="fields.zcml" />
 
 </configure>


=== Zope3/src/zope/app/schema/metaconfigure.py 1.1 => 1.2 ===
--- Zope3/src/zope/app/schema/metaconfigure.py:1.1	Fri Aug  1 17:48:34 2003
+++ Zope3/src/zope/app/schema/metaconfigure.py	Wed Mar  3 17:54:27 2004
@@ -15,12 +15,11 @@
 
 $Id$
 """
-import zope.app.schema.vocabulary
+from zope.interface import directlyProvides
+from vocabulary import IVocabularyFactory
+from zope.app.component.metaconfigure import utility
 
-__metaclass__ = type
-
-
-class FactoryKeywordPasser:
+class FactoryKeywordPasser(object):
     """Helper that passes additional keywords to the actual factory."""
 
     def __init__(self, factory, kwargs):
@@ -32,11 +31,8 @@
 
 
 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) )
+    directlyProvides(factory, IVocabularyFactory)
+    utility(_context, IVocabularyFactory, factory, name=name)
 


=== Zope3/src/zope/app/schema/vocabulary.py 1.4 => 1.5 ===
--- Zope3/src/zope/app/schema/vocabulary.py:1.4	Fri Aug  1 17:48:34 2003
+++ Zope3/src/zope/app/schema/vocabulary.py	Wed Mar  3 17:54:27 2004
@@ -15,36 +15,26 @@
 
 $Id$
 """
-from zope.interface import implements
-from zope.component import getService
-from zope.schema import vocabulary
+from zope.app import zapi
+from zope.interface import Interface, implements
 from zope.schema.interfaces import IVocabularyRegistry
-from zope.testing import cleanup
 
-__metaclass__ = type
 
+class IVocabularyFactory(Interface):
+    """Can create vocabularies."""
 
-class ZopeVocabularyRegistry:
-    """IVocabularyRegistry that supports local vocabulary services."""
+    def __call__(self, context):
+        """The context provides a location that the vocabulary can make use
+        of."""
+
+
+class ZopeVocabularyRegistry(object):
+    """IVocabularyRegistry that supports global and local utilities."""
 
     implements(IVocabularyRegistry)
     __slots__ = ()
 
     def get(self, context, name):
-        vr = getService(context, "Vocabularies")
-        return vr.get(context, name)
-
-
-def _clear():
-    """Re-initialize the vocabulary service."""
-    # This should normally only be needed by the testing framework,
-    # but is also used for module initialization.
-    global vocabularyService
-    vocabulary._clear()
-    vocabularyService = vocabulary.getVocabularyRegistry()
-    vocabulary._clear()
-    vocabulary.setVocabularyRegistry(ZopeVocabularyRegistry())
-
-
-_clear()
-cleanup.addCleanUp(_clear)
+        """See zope.schema.interfaces.IVocabularyRegistry"""
+        factory = zapi.getUtility(context, IVocabularyFactory, name)
+        return factory(context)




More information about the Zope3-Checkins mailing list