Patch: getRequiredAdapters() refactoring

Bug #153309 reported by Erik Rose
2
Affects Status Importance Assigned to Milestone
Zope 3
Won't Fix
Undecided
Unassigned
zope.app.apidoc
Fix Committed
Low
Christian Theune

Bug Description

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

Revision history for this message
Erik Rose (psucorp) wrote : The patch, with whitespace preserved

(In case whitespace is as trashed as it looks)

Changed in zope3:
status: New → Won't Fix
Changed in zope.app.apidoc:
status: New → In Progress
importance: Undecided → Low
assignee: nobody → Christian Theune (ct-gocept)
Revision history for this message
Christian Theune (ctheune) wrote :

Thanks for the patch. Applied in 111337 for zope.app.apidoc 3.7

Changed in zope.app.apidoc:
status: In Progress → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.