[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/component/ Fixed a bug in handling adapter directives without provides

Jim Fulton jim at zope.com
Fri Jan 28 16:14:27 EST 2005


Log message for revision 28972:
  Fixed a bug in handling adapter directives without provides
  and with permissions.
  

Changed:
  U   Zope3/trunk/src/zope/app/component/metaconfigure.py
  U   Zope3/trunk/src/zope/app/component/tests/test_directives.py

-=-
Modified: Zope3/trunk/src/zope/app/component/metaconfigure.py
===================================================================
--- Zope3/trunk/src/zope/app/component/metaconfigure.py	2005-01-28 20:41:54 UTC (rev 28971)
+++ Zope3/trunk/src/zope/app/component/metaconfigure.py	2005-01-28 21:14:25 UTC (rev 28972)
@@ -151,12 +151,6 @@
 def adapter(_context, factory, provides=None, for_=None, permission=None,
             name='', trusted=False):
 
-    if permission is not None:
-        if permission == PublicPermission:
-            permission = CheckerPublic
-        checker = InterfaceChecker(provides, permission)
-        factory.append(lambda c: proxify(c, checker))
-
     if for_ is None:
         if len(factory) == 1:
             try:
@@ -179,6 +173,12 @@
         if provides is None:
             raise TypeError("Missing 'provides' attribute")            
 
+    if permission is not None:
+        if permission == PublicPermission:
+            permission = CheckerPublic
+        checker = InterfaceChecker(provides, permission)
+        factory.append(lambda c: proxify(c, checker))
+
     # Generate a single factory from multiple factories:
     factories = factory
     if len(factories) == 1:

Modified: Zope3/trunk/src/zope/app/component/tests/test_directives.py
===================================================================
--- Zope3/trunk/src/zope/app/component/tests/test_directives.py	2005-01-28 20:41:54 UTC (rev 28971)
+++ Zope3/trunk/src/zope/app/component/tests/test_directives.py	2005-01-28 21:14:25 UTC (rev 28972)
@@ -503,6 +503,27 @@
         self.assertEqual(items, ['a', 'f'])
         self.assertEqual(removeSecurityProxy(adapter).__class__, Comp)
 
+    def testProtectedAdapter_wo_for_or_provides(self):
+
+        # Full import is critical!
+        from zope.component.tests.components import Content, IApp, Comp
+
+        self.assertEqual(IV(Content(), None), None)
+
+        xmlconfig(StringIO(template % (
+            """
+            <adapter
+              factory="zope.component.tests.components.Comp"
+              permission="zope.Public"
+              />
+            """
+            )))
+
+        adapter = ProxyFactory(IApp(Content()))
+        items = [item[0] for item in getTestProxyItems(adapter)]
+        self.assertEqual(items, ['a', 'f'])
+        self.assertEqual(removeSecurityProxy(adapter).__class__, Comp)
+
     def testAdapterUndefinedPermission(self):
         config = StringIO(template % (
              """



More information about the Zope3-Checkins mailing list