summaryrefslogtreecommitdiff
path: root/docs/zcml/subscriber.rst
blob: 371ec075201d1539276a570c388cef0e6e671dce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
.. _subscriber_directive:

``subscriber``
--------------

The ``subscriber`` ZCML directive configures an :term:`subscriber`
callable to listen for events broadcast by the :mod:`repoze.bfg` web
framework.

Attributes
~~~~~~~~~~

``for``
   The class or :term:`interface` that you are subscribing the
   listener for, e.g. :class:`repoze.bfg.interfaces.INewRequest`.
   Registering a subscriber for a specific class or interface limits
   the event types that the subscriber will receive to those specified
   by the interface or class.  Default: ``zope.interface.Interface``
   (implying *any* event type).

``handler``
   A :term:`dotted Python name` which references an event handler
   callable.  The callable should accept a single argument: ``event``.
   The return value of the callable is ignored.

Examples
~~~~~~~~

.. code-block:: xml
   :linenos:

   <subscriber
      for="repoze.bfg.interfaces.INewRequest"
      handler=".subscribers.handle_new_request"
    />

Alternatives
~~~~~~~~~~~~

You can also register an event listener by using the
:meth:`repoze.bfg.configuration.Configurator.add_subscriber` method.

See Also
~~~~~~~~

See also :ref:`events_chapter`.