[Zope3-checkins] SVN: Zope3/trunk/ Fixed a bug:

Jim Fulton jim at zope.com
Fri Apr 15 15:10:21 EDT 2005


Log message for revision 30010:
  Fixed a bug:
  
  The getAdapters function on site managers returned None when
    adapter factories returned None. These values should not be
    included in the output and now aren't.
  

Changed:
  U   Zope3/trunk/doc/CHANGES.txt
  U   Zope3/trunk/src/zope/component/site.py
  U   Zope3/trunk/src/zope/component/tests.py

-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt	2005-04-15 18:07:52 UTC (rev 30009)
+++ Zope3/trunk/doc/CHANGES.txt	2005-04-15 19:10:21 UTC (rev 30010)
@@ -566,6 +566,10 @@
 
     Bug Fixes
 
+      - the getAdapters function on site managers returned None when
+        adapter factories returned None. These values should not be
+        included in the output and now aren't.
+
       - Fixed issue #394: starting zope with command -C arg
         causes request.form to contain '-C':''
 

Modified: Zope3/trunk/src/zope/component/site.py
===================================================================
--- Zope3/trunk/src/zope/component/site.py	2005-04-15 18:07:52 UTC (rev 30009)
+++ Zope3/trunk/src/zope/component/site.py	2005-04-15 19:10:21 UTC (rev 30010)
@@ -76,9 +76,13 @@
     
     def getAdapters(self, objects, provided):
         """See ISiteManager interface"""
-        return [(name, adapter(*objects))
-                for name, adapter in self.adapters.lookupAll(
-                                        map(providedBy, objects), provided)]
+        result = []
+        for name, factory in self.adapters.lookupAll(map(providedBy, objects),
+                                                     provided):
+            adapter = factory(*objects)
+            if adapter is not None:
+                result.append((name, adapter))
+        return result
 
     def subscribers(self, required, provided):
         """See ISiteManager interface"""

Modified: Zope3/trunk/src/zope/component/tests.py
===================================================================
--- Zope3/trunk/src/zope/component/tests.py	2005-04-15 18:07:52 UTC (rev 30009)
+++ Zope3/trunk/src/zope/component/tests.py	2005-04-15 19:10:21 UTC (rev 30010)
@@ -436,6 +436,18 @@
       >>> adapters.sort()
       >>> [(name, adapter.__class__.__name__) for name, adapter in adapters]
       [(u'', 'Comp'), (u'foo', 'Comp')]
+
+    Note that the output doesn't include None values. If an adapter
+    factory returns None, it is as if it wasn't present.
+
+      >>> zope.component.getGlobalSiteManager().provideAdapter(
+      ...     [I1], I2, 'nah', lambda context: None)
+      >>> adapters = zope.component.getAdapters((ob,), I2)
+      >>> adapters.sort()
+      >>> [(name, adapter.__class__.__name__) for name, adapter in adapters]
+      [(u'', 'Comp'), (u'foo', 'Comp')]
+      
+
     """
 
 def testUtility():



More information about the Zope3-Checkins mailing list