[Zodb-checkins] CVS: Zope3/lib/python/Interface/Registry - AdapterRegistry.py:1.2.8.3 IAdapterRegistry.py:1.2.8.3
Jim Fulton
jim@zope.com
Thu, 24 Oct 2002 01:52:07 -0400
Update of /cvs-repository/Zope3/lib/python/Interface/Registry
In directory cvs.zope.org:/tmp/cvs-serv23537/lib/python/Interface/Registry
Modified Files:
Tag: Zope3-Bangalore-TTW-Branch
AdapterRegistry.py IAdapterRegistry.py
Log Message:
Made interfaces sortable. I'd prefer that interfaces be sorted from
mosy specific to most general, but this was harder than I'd hoped, so,
for now, we just sort on name. :/
Added an initial adapter registery API to get registration information
that matches given interface specifications.
=== Zope3/lib/python/Interface/Registry/AdapterRegistry.py 1.2.8.2 => 1.2.8.3 ===
--- Zope3/lib/python/Interface/Registry/AdapterRegistry.py:1.2.8.2 Wed Oct 16 04:35:35 2002
+++ Zope3/lib/python/Interface/Registry/AdapterRegistry.py Thu Oct 24 01:52:05 2002
@@ -104,3 +104,55 @@
if registered_provide == provide:
return object
return None
+
+ def getRegisteredMatching(self,
+ required_interfaces=None,
+ provided_interfaces=None):
+
+
+ if provided_interfaces:
+ r = {}
+
+ if required_interfaces:
+ # Both specified
+ for required in _flatten(required_interfaces, 1):
+ for provided in provided_interfaces:
+ v = self._reg.get((required, provided))
+ if v:
+ rprovided, o = v
+ r[required, rprovided] = o
+
+
+ else:
+ # Only provided specified
+ for (required, provided), (rprovided, o) in self._reg.items():
+ for p in provided_interfaces:
+ if provided.extends(p):
+ r[required, rprovided] = o
+ break
+
+ return [(required, provided, o)
+ for ((required, provided), o) in r.items()]
+
+
+ elif required_interfaces:
+ # Just required specified
+ required_interfaces = _flatten(required_interfaces, 1)
+ return [(required, provided, o)
+ for (required, provided), (rprovided, o)
+ in self._reg.items()
+ if ((required in required_interfaces)
+ and
+ provided == rprovided
+ )
+ ]
+
+ else:
+ # Nothing specified
+ return [(required, provided, o)
+ for (required, provided), (rprovided, o)
+ in self._reg.items()
+ if provided == rprovided
+ ]
+
+
=== Zope3/lib/python/Interface/Registry/IAdapterRegistry.py 1.2.8.2 => 1.2.8.3 ===
--- Zope3/lib/python/Interface/Registry/IAdapterRegistry.py:1.2.8.2 Wed Oct 16 04:35:35 2002
+++ Zope3/lib/python/Interface/Registry/IAdapterRegistry.py Thu Oct 24 01:52:05 2002
@@ -84,3 +84,30 @@
"""return data registred specificly for the given interfaces
"""
+ def getRegisteredMatching(required_interfaces=None,
+ provided_interfaces=None):
+ """Return information about registered data
+
+ Zero or more required and provided interfaces may be
+ specified. Registration information matching any of the
+ specified interfaces is returned. The returned value is a
+ sequence of three-element tuples:
+
+ - required interface
+
+ - provided interface
+
+ - the object registered specifically for the required and
+ provided interfaces.
+
+ To understand hopw the matching works, imagine that we have
+ interfaces R1, R2, P1, and P2. R2 extends R1. P2 extends P1.
+ We've registered C to require R1 and provide P2. Given this,
+ if we call getRegisteredMatching:
+
+ registery.getRegisteredMatching([R2], [P1])
+
+ the returned value will include:
+
+ (R1, P2, C)
+ """