summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJason Madden <jamadden@gmail.com>2021-03-18 08:00:59 -0500
committerJason Madden <jamadden@gmail.com>2021-03-18 08:18:11 -0500
commitf81a7f8448225f45bad51ed8aa52b0f27640d625 (patch)
treef578e64bb47f54652cb67d55206acd6fd3dc5ef6 /src
parent41cafd34b01555bc5c8bb7fe1b6181a7acf32fe7 (diff)
downloadzope-component-issue9.tar.gz
Fix the subscriber directive when a factory is given that implements an interface and no provides= attribute is specified.issue9
fixes #9
Diffstat (limited to 'src')
-rw-r--r--src/zope/component/tests/test_zcml.py23
-rw-r--r--src/zope/component/zcml.py4
2 files changed, 27 insertions, 0 deletions
diff --git a/src/zope/component/tests/test_zcml.py b/src/zope/component/tests/test_zcml.py
index bb92da4..0bf4591 100644
--- a/src/zope/component/tests/test_zcml.py
+++ b/src/zope/component/tests/test_zcml.py
@@ -598,6 +598,29 @@ class Test_subscriber(unittest.TestCase):
self.assertEqual(action['discriminator'], None)
self.assertEqual(action['args'], ('', Interface))
+ def test_no_for__no_provides_subscriber_adapts_subscriber_implements(self):
+ from zope.interface import Interface
+ from zope.interface import implementer
+ from zope.component._declaration import adapter
+ from zope.component.zcml import handler
+ class IFoo(Interface):
+ pass
+ @adapter(Interface)
+ @implementer(IFoo)
+ class _Factory(object):
+ def __init__(self, context):
+ self.context = context
+ _cfg_ctx = _makeConfigContext()
+ self._callFUT(_cfg_ctx, factory=_Factory)
+ self.assertEqual(len(_cfg_ctx._actions), 3)
+ self.assertEqual(_cfg_ctx._actions[0][0], ())
+ # Register the subscriber
+ action = _cfg_ctx._actions[0][1]
+ self.assertEqual(action['callable'], handler)
+ self.assertIsNone(action['discriminator'])
+ self.assertEqual(action['args'],
+ ('registerSubscriptionAdapter', _Factory, (Interface,), IFoo,
+ '', 'TESTING'))
class Test_utility(unittest.TestCase):
diff --git a/src/zope/component/zcml.py b/src/zope/component/zcml.py
index e3d040b..bc02c9f 100644
--- a/src/zope/component/zcml.py
+++ b/src/zope/component/zcml.py
@@ -304,6 +304,10 @@ def subscriber(_context, for_=None, factory=None, handler=None, provides=None,
if handler is not None:
raise TypeError("Cannot use handler with factory")
if provides is None:
+ p = list(implementedBy(factory))
+ if len(p) == 1:
+ provides = p[0]
+ if provides is None:
raise TypeError(
"You must specify a provided interface when registering "
"a factory")