[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/apidoc/component. apidoc would fail if it was in a system that had an adapter or subscriber registered for a class (as opposed to an interface). Fix included, with test.

Gary Poster gary at zope.com
Wed Dec 21 22:07:18 EST 2005


Log message for revision 40969:
  apidoc would fail if it was in a system that had an adapter or subscriber registered for a class (as opposed to an interface).  Fix included, with test.
  

Changed:
  U   Zope3/trunk/src/zope/app/apidoc/component.py
  U   Zope3/trunk/src/zope/app/apidoc/component.txt

-=-
Modified: Zope3/trunk/src/zope/app/apidoc/component.py
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/component.py	2005-12-21 23:21:32 UTC (rev 40968)
+++ Zope3/trunk/src/zope/app/apidoc/component.py	2005-12-22 03:07:18 UTC (rev 40969)
@@ -23,6 +23,7 @@
 from zope.component.site import UtilityRegistration
 from zope.interface import Interface
 from zope.interface.interface import InterfaceClass
+import zope.interface.declarations
 from zope.publisher.interfaces import IRequest
 
 from zope.app import zapi
@@ -163,9 +164,12 @@
 
 def getInterfaceInfoDictionary(iface):
     """Return a PT-friendly info dictionary for an interface."""
+    if isinstance(iface, zope.interface.declarations.Implements):
+        iface = iface.inherit
     if iface is None:
         return None
-    return {'module': iface.__module__, 'name': iface.getName()}
+    return {'module': getattr(iface, '__module__', '<unknown>'),
+            'name': getattr(iface, '__name__', '<unknown>')}
 
 
 def getAdapterInfoDictionary(reg):

Modified: Zope3/trunk/src/zope/app/apidoc/component.txt
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/component.txt	2005-12-21 23:21:32 UTC (rev 40968)
+++ Zope3/trunk/src/zope/app/apidoc/component.txt	2005-12-22 03:07:18 UTC (rev 40969)
@@ -280,7 +280,19 @@
   >>> component.getInterfaceInfoDictionary(None) is None
   True
 
+It's also possible for this function to be passed a 
+zope.interface.declarations.Implements instance.  For instance, this function
+is sometimes used to analyze the required elements of an adapter registration:
+if an adapter or subscriber is registered against a class, then the required
+element will be an Implements instance.  In this case, we currently believe
+that we want to return the module and name of the object that the Implements
+object references.  This may change.
 
+  >>> from zope.interface import implementedBy
+  >>> pprint(component.getInterfaceInfoDictionary(implementedBy(MyFoo)))
+  {'module': 'zope.app.apidoc.doctest', 'name': 'MyFoo'}
+
+
 `getAdapterInfoDictionary(reg)`
 -------------------------------
 



More information about the Zope3-Checkins mailing list