summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt15
-rw-r--r--pyramid/events.py9
-rw-r--r--pyramid/tests/test_events.py10
3 files changed, 31 insertions, 3 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index adc380c34..07c0b564d 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -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)
==================
diff --git a/pyramid/events.py b/pyramid/events.py
index 9cb8b31ad..e181ef33f 100644
--- a/pyramid/events.py
+++ b/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 @@ 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
@@ -66,7 +69,7 @@ class subscriber(object):
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):
diff --git a/pyramid/tests/test_events.py b/pyramid/tests/test_events.py
index 4b58a129c..f35083c02 100644
--- a/pyramid/tests/test_events.py
+++ b/pyramid/tests/test_events.py
@@ -155,6 +155,16 @@ class TestSubscriber(unittest.TestCase):
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