Skip to content

Commit

Permalink
- The documentation of pyramid.events.subscriber indicated that u…
Browse files Browse the repository at this point in the history
…sing 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
  #386

Closes #386
  • Loading branch information
mcdonc committed Jan 3, 2012
1 parent 22c2200 commit 52a948e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
15 changes: 15 additions & 0 deletions CHANGES.txt
Expand Up @@ -12,6 +12,21 @@ Features

- 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)
==================

Expand Down
9 changes: 6 additions & 3 deletions 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,
Expand All @@ -26,7 +29,7 @@ class subscriber(object):
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
Expand Down Expand Up @@ -66,7 +69,7 @@ def __init__(self, *ifaces):

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):
Expand Down
10 changes: 10 additions & 0 deletions pyramid/tests/test_events.py
Expand Up @@ -155,6 +155,16 @@ def foo(): pass
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
Expand Down

0 comments on commit 52a948e

Please sign in to comment.