[Zope3-checkins] CVS: Zope3/src/zope/app/workflow -
globalimportexport.py:1.6
Jim Fulton
jim at zope.com
Thu Apr 15 11:29:45 EDT 2004
Update of /cvs-repository/Zope3/src/zope/app/workflow
In directory cvs.zope.org:/tmp/cvs-serv747/src/zope/app/workflow
Modified Files:
globalimportexport.py
Log Message:
We are getting rid of zope.interface.implementor.
Moved that implementation here for now, for use internally.
This import/export system needs more thought.
(E.g. why not just use utilities for importers or exporters?)
=== Zope3/src/zope/app/workflow/globalimportexport.py 1.5 => 1.6 ===
--- Zope3/src/zope/app/workflow/globalimportexport.py:1.5 Fri Feb 27 11:50:37 2004
+++ Zope3/src/zope/app/workflow/globalimportexport.py Thu Apr 15 11:29:45 2004
@@ -17,7 +17,6 @@
"""
__metaclass__ = type
-from zope.interface.implementor import ImplementorRegistry
from zope.proxy import removeAllProxies
from zope.interface import implements, providedBy
@@ -79,6 +78,56 @@
"""
self._exporters.register(interface, factory)
+
+from zope.interface import Interface
+class ImplementorRegistry:
+ # This was copied from zope.interface.implementor
+ # zope.interface.implementor has been removed
+
+ # The implementation that needs this should be rethought
+
+ def __init__(self):
+ self._reg = {}
+
+ def _registerAllProvided(self, primary_provide, object, provide):
+ # Registers a component using (require, provide) as a key.
+ # Also registers superinterfaces of the provided interface,
+ # stopping when the registry already has a component
+ # that provides a more general interface or when the Base is Interface.
+
+ reg = self._reg
+ reg[provide] = (primary_provide, object)
+ bases = getattr(provide, '__bases__', ())
+ for base in bases:
+ if base is Interface:
+ # Never register the say-nothing Interface.
+ continue
+ existing = reg.get(base, None)
+ if existing is not None:
+ existing_provide = existing[0]
+ if existing_provide is not primary_provide:
+ if not existing_provide.extends(primary_provide):
+ continue
+ # else we are registering a general component
+ # after a more specific component.
+ self._registerAllProvided(primary_provide, object, base)
+
+
+ def register(self, provide, object):
+ self._registerAllProvided(provide, object, provide)
+
+
+ def getRegisteredMatching(self):
+ return [(iface, impl)
+ for iface, (regiface, impl) in self._reg.items()
+ if iface is regiface]
+
+ def get(self, interface, default=None):
+ c = self._reg.get(interface)
+ if c is not None:
+ return c[1]
+
+ return default
globalImportExport = ImportExportUtility()
More information about the Zope3-Checkins
mailing list