[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/component/ Fix subscriber directive for multiple for's and permission being

Stephan Richter srichter at cosmos.phy.tufts.edu
Sat Nov 5 13:24:23 EST 2005


Log message for revision 39919:
  Fix subscriber directive for multiple for's and permission being 
  specified.
  

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-11-05 15:52:56 UTC (rev 39918)
+++ Zope3/trunk/src/zope/app/component/metaconfigure.py	2005-11-05 18:24:22 UTC (rev 39919)
@@ -98,30 +98,14 @@
             raise TypeError("No for attribute was provided and can't "
                             "determine what the factory (or handler) adapts.")
 
-    factory = [factory]
-
     if permission is not None:
         if permission == PublicPermission:
             permission = CheckerPublic
         checker = InterfaceChecker(provides, permission)
-        factory.append(lambda c: proxify(c, checker))
+        factory = _protectedFactory(factory, checker)
 
     for_ = tuple(for_)
 
-    # Generate a single factory from multiple factories:
-    factories = factory
-    if len(factories) == 1:
-        factory = factories[0]
-    elif len(factories) < 1:
-        raise ValueError("No factory specified")
-    elif len(factories) > 1 and len(for_) != 1:
-        raise ValueError("Can't use multiple factories and multiple for")
-    else:
-        def factory(ob):
-            for f in factories:
-                ob = f(ob)
-            return ob
-
     # invoke custom adapter factories
     if locate or (permission is not None and permission is not CheckerPublic):
         if trusted:

Modified: Zope3/trunk/src/zope/app/component/tests/test_directives.py
===================================================================
--- Zope3/trunk/src/zope/app/component/tests/test_directives.py	2005-11-05 15:52:56 UTC (rev 39918)
+++ Zope3/trunk/src/zope/app/component/tests/test_directives.py	2005-11-05 18:24:22 UTC (rev 39919)
@@ -57,7 +57,7 @@
 
 class Context(object):
     actions = ()
-    
+
     def action(self, discriminator, callable, args):
         self.actions += ((discriminator, callable, args), )
 
@@ -132,6 +132,35 @@
         self.assertEqual(a3.__class__, A3)
         self.assertEqual(a3.context, (content, a1))
 
+
+    def testSubscriberWithPermission(self):
+        xmlconfig(StringIO(template % (
+            '''
+            <permission
+                id="y.x"
+                title="XY"
+                description="Allow XY." />
+
+            <subscriber
+              provides="zope.app.component.tests.adapter.IS"
+              factory="zope.app.component.tests.adapter.A3"
+              for="zope.app.component.tests.components.IContent
+                   zope.app.component.tests.adapter.I1"
+              permission="y.x"
+              />
+            '''
+            )))
+
+        content = Content()
+        a1 = A1()
+        subscribers = zapi.subscribers((content, a1), IS)
+
+        a3 = subscribers[0]
+
+        self.assertEqual(a3.__class__, A3)
+        self.assertEqual(a3.context, (content, a1))
+        self.assertEqual(type(a3).__name__, 'LocationProxy')
+
     def testSubscriber_wo_for(self):
         xmlconfig(StringIO(template % (
             '''
@@ -170,8 +199,8 @@
 
         self.assertEqual(a3.__class__, A3)
         self.assertEqual(a3.context, (content, a1, a2))
-        
 
+
     def testTrustedSubscriber(self):
         xmlconfig(StringIO(template % (
             '''
@@ -247,7 +276,8 @@
         # behind the security proxy is a locatio proxy:
         from zope.security.proxy import removeSecurityProxy
         self.assert_(removeSecurityProxy(a3).context[0] is content)
-        self.assertEqual(type(removeSecurityProxy(a3)).__name__, 'LocationProxy')
+        self.assertEqual(type(removeSecurityProxy(a3)).__name__,
+                         'LocationProxy')
 
     def testSubscriber_w_no_provides(self):
         xmlconfig(StringIO(template % (
@@ -265,7 +295,7 @@
         list(zapi.subscribers((content, a1), None))
 
         self.assertEqual(content.args, ((a1,),))
-        
+
     def testSubscriberHavingARequiredClass(self):
         xmlconfig(StringIO(template % (
             '''
@@ -279,10 +309,10 @@
 
         subs = zapi.subscribers((Content(),), I1)
         self.assert_(isinstance(subs[0], A1))
-        
+
         class MyContent:
             implements(IContent)
-        
+
         self.assertEqual(zapi.subscribers((MyContent(),), I1), [])
 
     def testMultiSubscriber(self):
@@ -365,7 +395,7 @@
             '''
             )))
 
-        self.assertEqual(IApp(Content()).__class__, Comp)        
+        self.assertEqual(IApp(Content()).__class__, Comp)
 
     def testAdapter_wo_provides_and_no_implented_fails(self):
         try:
@@ -688,7 +718,7 @@
                              '''
                              )),
                           )
-        
+
         self.assertRaises(ConfigurationError,
                           xmlconfig,
                           StringIO(template % (
@@ -703,8 +733,8 @@
                              '''
                              )),
                           )
-        
 
+
     def testNamedAdapter(self):
         self.testAdapter()
         self.assertEqual(IApp(Content()).__class__, Comp)
@@ -1021,7 +1051,7 @@
                                    ),
                           )
 
-        
+
     def testViewThatProvidesAnInterface(self):
         ob = Ob()
         self.assertEqual(
@@ -1529,8 +1559,8 @@
 
         # Make sure we know about the interfaces
         self.assertEqual(queryInterface(PREFIX+"I"), module.I)
-        
 
+
     def testMultipleInterface(self):
 
         self.assertEqual(queryInterface(PREFIX+"I3"), None)



More information about the Zope3-Checkins mailing list