[Zope3-checkins] SVN: Zope3/trunk/ Fixed issue 354.

Stephan Richter srichter at cosmos.phy.tufts.edu
Sat Feb 26 11:20:57 EST 2005


Log message for revision 29314:
  Fixed issue 354.
  
  The page view did not actually fail anymore, but I realized that it only 
  did not, because subscriptions were not included in the list of adapters 
  anymore. So I added subscriptions back and the problem reoccurred, which 
  was due to the fact that subscription registrations do not have a name. 
  
  Then I noticed another problem. Subscriptions often have `None` as its 
  provided interface and not all code did expect that, so I fixed it. For 
  some reason the code checking for `None` in the required adapters was 
  already done.
  
  

Changed:
  U   Zope3/trunk/doc/CHANGES.txt
  U   Zope3/trunk/src/zope/app/apidoc/component.py
  U   Zope3/trunk/src/zope/app/apidoc/component.txt
  U   Zope3/trunk/src/zope/app/apidoc/ifacemodule/component_macros.pt
  U   Zope3/trunk/src/zope/component/site.py

-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt	2005-02-26 15:20:59 UTC (rev 29313)
+++ Zope3/trunk/doc/CHANGES.txt	2005-02-26 16:20:57 UTC (rev 29314)
@@ -461,6 +461,9 @@
 
     Bug Fixes
 
+      - Fixed issue #354 (apidoc: 'SubscriptionRegistration' object has no 
+                          attribute 'name')
+
       - Fixed issue #366 (_zope_interface_coptimizations.c compilation error)
 
       - Fixed issue #368 (Typo fix in src/zope/app/container/constraints.py)

Modified: Zope3/trunk/src/zope/app/apidoc/component.py
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/component.py	2005-02-26 15:20:59 UTC (rev 29313)
+++ Zope3/trunk/src/zope/app/apidoc/component.py	2005-02-26 16:20:57 UTC (rev 29314)
@@ -19,7 +19,8 @@
 import types
 
 from zope.component.interfaces import IFactory
-from zope.component.site import AdapterRegistration, UtilityRegistration
+from zope.component.site import AdapterRegistration, SubscriptionRegistration
+from zope.component.site import UtilityRegistration
 from zope.interface import Interface
 from zope.publisher.interfaces import IRequest
 
@@ -37,7 +38,7 @@
     gsm = zapi.getGlobalSiteManager()
     for reg in gsm.registrations():
         # Only get adapters
-        if not isinstance(reg, AdapterRegistration):
+        if not isinstance(reg, (AdapterRegistration, SubscriptionRegistration)):
             continue
         # Ignore views
         if not withViews and reg.required[-1] and \
@@ -54,14 +55,14 @@
     gsm = zapi.getGlobalSiteManager()
     for reg in gsm.registrations():
         # Only get adapters
-        if not isinstance(reg, AdapterRegistration):
+        if not isinstance(reg, (AdapterRegistration, SubscriptionRegistration)):
             continue
         # Ignore views
         if not withViews and reg.required[-1] and \
                reg.required[-1].isOrExtends(IRequest):
             continue
         # Only get adapters for which this interface is provided
-        if not reg.provided.isOrExtends(iface):
+        if reg.provided is None or not reg.provided.isOrExtends(iface):
             continue
         yield reg
 
@@ -147,6 +148,8 @@
 
 def getInterfaceInfoDictionary(iface):
     """Return a PT-friendly info dictionary for an interface."""
+    if iface is None:
+        return None
     return {'module': iface.__module__, 'name': iface.getName()}
     
 
@@ -170,7 +173,7 @@
         'required': [getInterfaceInfoDictionary(iface)
                      for iface in reg.required
                      if iface is not None],
-        'name': getattr(reg, 'name', None),
+        'name': getattr(reg, 'name', '<subscription>'),
         'factory': path,
         'factory_url': url,
         'doc': doc,

Modified: Zope3/trunk/src/zope/app/apidoc/component.txt
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/component.txt	2005-02-26 15:20:59 UTC (rev 29313)
+++ Zope3/trunk/src/zope/app/apidoc/component.txt	2005-02-26 16:20:57 UTC (rev 29314)
@@ -39,12 +39,14 @@
   >>> ztapi.provideAdapter((IFoo,), IResult, None)
   >>> ztapi.provideAdapter((IFoo, IBar), ISpecialResult, None)
   >>> ztapi.provideAdapter((IFoo, IRequest), ISpecialResult, None)
+  >>> ztapi.subscribe((IFoo,), None, 'stubFactory')
 
   >>> regs = list(component.getRequiredAdapters(IFoo))
   >>> regs.sort()
   >>> regs
   [AdapterRegistration(('IFoo', 'IBar'), 'ISpecialResult', '', None, ''), 
-   AdapterRegistration(('IFoo',), 'IResult', '', None, '')]
+   AdapterRegistration(('IFoo',), 'IResult', '', None, ''),
+   SubscriptionRegistration(('IFoo',), None, 'stubFactory', '')]
 
 Note how the adapter requiring an `IRequest` at the end of the required
 interfaces is neglected. This is because it is recognized as a view and views
@@ -55,7 +57,8 @@
   >>> regs
   [AdapterRegistration(('IFoo', 'IBar'), 'ISpecialResult', '', None, ''), 
    AdapterRegistration(('IFoo', 'IRequest'), 'ISpecialResult', '', None, ''), 
-   AdapterRegistration(('IFoo',), 'IResult', '', None, '')]
+   AdapterRegistration(('IFoo',), 'IResult', '', None, ''),
+   SubscriptionRegistration(('IFoo',), None, 'stubFactory', '')]
 
 The function will also pick up registrations that have required interfaces the
 specified interface extends:
@@ -64,7 +67,8 @@
   >>> regs.sort()
   >>> regs
   [AdapterRegistration(('IFoo', 'IBar'), 'ISpecialResult', '', None, ''), 
-   AdapterRegistration(('IFoo',), 'IResult', '', None, '')]
+   AdapterRegistration(('IFoo',), 'IResult', '', None, ''),
+   SubscriptionRegistration(('IFoo',), None, 'stubFactory', '')]
 
 And all of the required interfaces are considered, of course:
 
@@ -200,10 +204,27 @@
    UtilityRegistration('IFooBar', '', <MyFooBar object at ...>, '')]
 
 
+`getInterfaceInfoDictionary(iface)`
+-----------------------------------
+
+This function returns a small info dictionary for an interface. It only
+reports the module and the name. This is useful for cases when we only want to
+list interfaces in the context of other components, like adapters and
+utilities.
+
+  >>> pprint(component.getInterfaceInfoDictionary(IFoo))
+  {'module': '__builtin__', 'name': 'IFoo'}
+
+The functions using this function use it with little care and can also
+sometimes pass in `None`. In these cases we want to return `None`:
+
+  >>> component.getInterfaceInfoDictionary(None) is None
+  True
+
+
 `getAdapterInfoDictionary(reg)`
 -------------------------------
 
-
 This function returns a page-template-friendly dictionary representing the
 data of an adapter registration in an output-friendly format.
 
@@ -223,14 +244,29 @@
    'factory': '__builtin__.MyResult',
    'factory_url': '__builtin__/MyResult',
    'name': 'FooToResult',
-   'provided': {'module': '__builtin__',
-                'name': 'IResult'},
-   'required': [{'module': '__builtin__',
-                 'name': 'IFoo'},
-                {'module': '__builtin__',
-                 'name': 'IBar'}],
+   'provided': {'module': '__builtin__', 'name': 'IResult'},
+   'required': [{'module': '__builtin__', 'name': 'IFoo'},
+                {'module': '__builtin__', 'name': 'IBar'}],
    'zcml': None}
 
+This function can also handle subscription registrations, which are pretty
+much like adapter registrations, except that they do not have name. So let's
+see how the function handles subscriptions:
+
+  >>> from zope.component.site import SubscriptionRegistration
+  >>> reg = SubscriptionRegistration((IFoo, IBar), None, MyResult, 'doc info')
+
+  >>> pprint(component.getAdapterInfoDictionary(reg))
+  {'doc': 'doc info',
+   'factory': '__builtin__.MyResult',
+   'factory_url': '__builtin__/MyResult',
+   'name': '<subscription>',
+   'provided': None,
+   'required': [{'module': '__builtin__', 'name': 'IFoo'},
+                {'module': '__builtin__', 'name': 'IBar'}],
+   'zcml': None}
+
+
 `getFactoryInfoDictionary(reg)`
 -------------------------------
 

Modified: Zope3/trunk/src/zope/app/apidoc/ifacemodule/component_macros.pt
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/ifacemodule/component_macros.pt	2005-02-26 15:20:59 UTC (rev 29313)
+++ Zope3/trunk/src/zope/app/apidoc/ifacemodule/component_macros.pt	2005-02-26 16:20:57 UTC (rev 29314)
@@ -59,6 +59,9 @@
               string:../${iface/module}.${iface/name}/apiindex.html">
       <metal:block use-macro="context/@@interface_macros/ifacename" />
     </a>  
+    <span tal:condition="not:iface" i18n:translate="">
+      No interface provided.
+    </span>
   </div>
 
   <div tal:condition="adapter/doc">

Modified: Zope3/trunk/src/zope/component/site.py
===================================================================
--- Zope3/trunk/src/zope/component/site.py	2005-02-26 15:20:59 UTC (rev 29313)
+++ Zope3/trunk/src/zope/component/site.py	2005-02-26 16:20:57 UTC (rev 29314)
@@ -285,7 +285,7 @@
         return '%s(%r, %r, %r, %r, %r)' % (
             self.__class__.__name__,
             tuple([getattr(r, '__name__', None) for r in self.required]),
-            self.provided.__name__, self.name,
+            getattr(self.provided, '__name__', None), self.name,
             self.value, self.doc,
             )
 
@@ -304,7 +304,7 @@
         return '%s(%r, %r, %r, %r)' % (
             self.__class__.__name__,
             tuple([getattr(r, '__name__', None) for r in self.required]),
-            self.provided.__name__, self.value, self.doc,
+            getattr(self.provided, '__name__', None), self.value, self.doc,
             )
 
     def __cmp__(self, other):
@@ -320,7 +320,7 @@
     def __repr__(self):
         return '%s(%r, %r, %r, %r)' % (
             self.__class__.__name__,
-            self.provided.__name__, self.name,
+            getattr(self.provided, '__name__', None), self.name,
             getattr(self.component, '__name__', self.component), self.doc,
             )
 



More information about the Zope3-Checkins mailing list