Chris McDonough
2012-01-03 52a948e65ef923340a9c172fe6d258f2832f8799
- The documentation of ``pyramid.events.subscriber`` indicated that using it
as a decorator with no arguments like this::

@subscriber()
def somefunc(event):
pass

Would register ``somefunc`` to receive all events sent via the registry,
but this was untrue. Instead, it would receive no events at all. This has
now been fixed and the code matches the documentation. See also
https://github.com/Pylons/pyramid/issues/386

Closes #386
3 files modified
34 ■■■■■ changed files
CHANGES.txt 15 ●●●●● patch | view | raw | blame | history
pyramid/events.py 9 ●●●●● patch | view | raw | blame | history
pyramid/tests/test_events.py 10 ●●●●● patch | view | raw | blame | history
CHANGES.txt
@@ -12,6 +12,21 @@
- Use the ``waitress`` WSGI server instead of ``wsgiref`` in scaffolding.
Bug Fixes
---------
- The documentation of ``pyramid.events.subscriber`` indicated that using it
  as a decorator with no arguments like this::
    @subscriber()
    def somefunc(event):
        pass
  Would register ``somefunc`` to receive all events sent via the registry,
  but this was untrue.  Instead, it would receive no events at all.  This has
  now been fixed and the code matches the documentation.  See also
  https://github.com/Pylons/pyramid/issues/386
1.3a3 (2011-12-21)
==================
pyramid/events.py
@@ -1,6 +1,9 @@
import venusian
from zope.interface import implementer
from zope.interface import (
    implementer,
    Interface
    )
from pyramid.interfaces import (
    IContextFound,
@@ -26,7 +29,7 @@
       def mysubscriber(event):
           event.request.foo = 1
    More than one event type can be passed as a construtor argument.  The
    More than one event type can be passed as a constructor argument.  The
    decorated subscriber will be called for each event type.
    .. code-block:: python
@@ -66,7 +69,7 @@
    def register(self, scanner, name, wrapped):
        config = scanner.config
        for iface in self.ifaces:
        for iface in self.ifaces or (Interface,):
            config.add_subscriber(wrapped, iface)
    def __call__(self, wrapped):
pyramid/tests/test_events.py
@@ -155,6 +155,16 @@
        dec.register(scanner, None, foo)
        self.assertEqual(config.subscribed, [(foo, IFoo), (foo, IBar)])
    def test_register_none_means_all(self):
        from zope.interface import Interface
        dec = self._makeOne()
        def foo(): pass
        config = DummyConfigurator()
        scanner = Dummy()
        scanner.config = config
        dec.register(scanner, None, foo)
        self.assertEqual(config.subscribed, [(foo, Interface)])
    def test_register_objectevent(self):
        from zope.interface import Interface
        class IFoo(Interface): pass