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

Fred L. Drake, Jr. fred@zope.com
Thu, 8 May 2003 11:17:31 -0400


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

Modified Files:
      Tag: schema-vocabulary-branch
	vocabulary.py 
Log Message:
_clear(): support for the testing framework


=== Zope3/src/zope/app/schema/vocabulary.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/app/schema/vocabulary.py:1.1.2.1	Thu May  8 10:46:00 2003
+++ Zope3/src/zope/app/schema/vocabulary.py	Thu May  8 11:17:31 2003
@@ -18,6 +18,7 @@
 from zope.configuration.action import Action
 from zope.schema import vocabulary
 from zope.schema.interfaces import IVocabularyRegistry
+from zope.testing import cleanup
 
 
 def register(_context, name, factory):
@@ -40,10 +41,16 @@
         return vr.get(context, name)
 
 
-# This can only be done once; more than that causes confusion!
-try:
-    vocabularyService
-except NameError:
+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)