[Zope-dev] Patch: getRequiredAdapters()
Erik Rose
psucorp at grinchcentral.com
Mon Oct 15 17:29:40 EDT 2007
Here's a little patch that eliminates some duplication in
getRequiredAdapters(). It changes it to use the
_adapterishRegistrations() utility function, as getProvidedAdapters()
does, rather than repeating the ('registeredAdapters',
'registeredSubscriptionAdapters', 'registeredHandlers') triad.
--- src/zope/app/apidoc/component.py (revision 80884)
+++ src/zope/app/apidoc/component.py (working copy)
@@ -45,22 +45,18 @@
def getRequiredAdapters(iface, withViews=False):
"""Get adapter registrations where the specified interface is
required."""
gsm = getGlobalSiteManager()
- for meth in ('registeredAdapters',
- 'registeredSubscriptionAdapters',
- 'registeredHandlers'):
+ for reg in _adapterishRegistrations(gsm):
+ # Ignore adapters that have no required interfaces
+ if len(reg.required) == 0:
+ continue
+ # Ignore views
+ if not withViews and reg.required[-1].isOrExtends(IRequest):
+ continue
+ # Only get the adapters for which this interface is required
+ for required_iface in reg.required:
+ if iface.isOrExtends(required_iface):
+ yield reg
- for reg in getattr(gsm, meth)():
- # Ignore adapters that have no required interfaces
- if len(reg.required) == 0:
- continue
- # Ignore views
- if not withViews and reg.required[-1].isOrExtends
(IRequest):
- continue
- # Only get the adapters for which this interface is
required
- for required_iface in reg.required:
- if iface.isOrExtends(required_iface):
- yield reg
-
Cheers,
Erik Rose
WebLion Core Developer
Pennsylvania State University
More information about the Zope-Dev
mailing list