[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/component/ Modified
the subscriber directive so that the provided interface can
Jim Fulton
jim at zope.com
Tue May 25 16:40:43 EDT 2004
Log message for revision 24973:
Modified the subscriber directive so that the provided interface can
be omitted.
-=-
Modified: Zope3/trunk/src/zope/app/component/metaconfigure.py
===================================================================
--- Zope3/trunk/src/zope/app/component/metaconfigure.py 2004-05-25 20:29:07 UTC (rev 24972)
+++ Zope3/trunk/src/zope/app/component/metaconfigure.py 2004-05-25 20:40:43 UTC (rev 24973)
@@ -79,7 +79,7 @@
return ob
-def subscriber(_context, factory, provides, for_, permission=None):
+def subscriber(_context, factory, for_, provides=None, permission=None):
factory = [factory]
if permission is not None:
@@ -104,23 +104,20 @@
ob = f(ob)
return ob
- # Check that the principal has the permission necessary. We
- # specify discriminator as None because there can be multiple
- # subscriptions.
_context.action(
discriminator = None,
callable = checkingHandler,
args = (permission, Adapters, 'subscribe',
for_, provides, factory),
)
+
+ if provides is not None:
+ _context.action(
+ discriminator = None,
+ callable = provideInterface,
+ args = ('', provides)
+ )
- # Stating that the adapter provides the specified interface.
- _context.action(
- discriminator = None,
- callable = provideInterface,
- args = ('', provides)
- )
-
# For each interface, state that the adapter provides that interface.
for iface in for_:
if iface is not None:
Modified: Zope3/trunk/src/zope/app/component/metadirectives.py
===================================================================
--- Zope3/trunk/src/zope/app/component/metadirectives.py 2004-05-25 20:29:07 UTC (rev 24972)
+++ Zope3/trunk/src/zope/app/component/metadirectives.py 2004-05-25 20:40:43 UTC (rev 24973)
@@ -194,7 +194,7 @@
title=u"Interface the component provides",
description=u"""This attribute specifes the interface the adapter
instance must provide.""",
- required=True
+ required=False,
)
for_ = Tokens(
Modified: Zope3/trunk/src/zope/app/component/tests/adapter.py
===================================================================
--- Zope3/trunk/src/zope/app/component/tests/adapter.py 2004-05-25 20:29:07 UTC (rev 24972)
+++ Zope3/trunk/src/zope/app/component/tests/adapter.py 2004-05-25 20:40:43 UTC (rev 24973)
@@ -40,3 +40,6 @@
class A3(Adapter):
zope.interface.implements(I3)
+def Handler(content, *args):
+ # uninteresting handler
+ content.args = getattr(content, 'args', ()) + (args, )
Modified: Zope3/trunk/src/zope/app/component/tests/test_directives.py
===================================================================
--- Zope3/trunk/src/zope/app/component/tests/test_directives.py 2004-05-25 20:29:07 UTC (rev 24972)
+++ Zope3/trunk/src/zope/app/component/tests/test_directives.py 2004-05-25 20:40:43 UTC (rev 24973)
@@ -125,6 +125,26 @@
self.assertEqual(a3.__class__, A3)
self.assertEqual(a3.context, (content, a1))
+ def testSubscriber_w_no_provides(self):
+ from zope.app.component.tests.adapter import A1, A2, Handler, I3
+ from zope.component.tests.components import Content
+
+ xmlconfig(StringIO(template % (
+ """
+ <subscriber
+ for="zope.component.tests.components.IContent
+ zope.app.component.tests.adapter.I1"
+ factory="zope.app.component.tests.adapter.Handler"
+ />
+ """
+ )))
+
+ content = Content()
+ a1 = A1()
+ list(zapi.subscribers((content, a1), None))
+
+ self.assertEqual(content.args, ((a1,),))
+
def testMultiSubscriber(self):
from zope.app.component.tests.adapter import A1, A2, A3, I3
from zope.component.tests.components import Content
More information about the Zope3-Checkins
mailing list