[Zope-Checkins] CVS: Zope3/lib/python/Zope/ComponentArchitecture - IToIRegistry.py:1.1.4.12
Jim Fulton
jim@zope.com
Fri, 22 Feb 2002 15:37:48 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/ComponentArchitecture
In directory cvs.zope.org:/tmp/cvs-serv15128
Modified Files:
Tag: Zope-3x-branch
IToIRegistry.py
Log Message:
Added getAll and getAllForObject to
=== Zope3/lib/python/Zope/ComponentArchitecture/IToIRegistry.py 1.1.4.11 => 1.1.4.12 ===
return None
+ def getAll(self, ob_interface, provide, result=None, seen=None):
+ """Get all components that match an interface
+
+ Finds all registered components that provides the given interface.
+ Returns None if not found.
+ """
+ if result is None:
+ result = []
+ if seen is None:
+ seen = {}
+
+ if ob_interface in seen:
+ return result
+
+ c = self._find(ob_interface, provide)
+ if c is not None:
+ result.append(c[1])
+ seen[ob_interface] = 1
+
+ bases = getattr(ob_interface, '__bases__', ())
+ if bases:
+ # 'require' might be a subinterface of a required interface
+ # for a registered component.
+ for base in bases:
+ self.getAll(base, provide, result, seen)
+
+ return result
+
def getForObject(self, ob, provided):
for i in objectImplements(ob):
c=self.get(i, provided)
if c is not None: return c
return self.get(None, provided)
+ def getAllForObject(self, ob, provided):
+ """Get all components that match an object's interfaces
+
+ Finds all registered components that provides the given interface.
+ Returns None if not found.
+ """
+ result = []
+ seen = {}
+ for i in objectImplements(ob):
+ self.getAll(i, provided, result, seen)
+
+ return self.getAll(None, provided, result, seen)
+
+
class IRegistry(IToIRegistry):
"""Registry for components that provide an interface but down require one
@@ -142,10 +184,12 @@
self._registerAll(require, None, data, None)
def getForObject(self, ob):
- for i in objectImplements(ob):
- c=self.get(i, None)
- if c is not None: return c
- return self.get(None, None)
+ return IToIRegistry.getForObject(self, ob, None)
+
+ def getAllForObject(self, ob):
+ return IToIRegistry.getAllForObject(self, ob, None)
def getForType(self, interface):
return self.get(interface, None)
+
+