scrapy / scrapy
1 7
from pydispatch import dispatcher
2 7
from scrapy.utils import signal as _signal
3

4

5 7
class SignalManager:
6

7 7
    def __init__(self, sender=dispatcher.Anonymous):
8 7
        self.sender = sender
9

10 7
    def connect(self, receiver, signal, **kwargs):
11
        """
12
        Connect a receiver function to a signal.
13

14
        The signal can be any object, although Scrapy comes with some
15
        predefined signals that are documented in the :ref:`topics-signals`
16
        section.
17

18
        :param receiver: the function to be connected
19
        :type receiver: collections.abc.Callable
20

21
        :param signal: the signal to connect to
22
        :type signal: object
23
        """
24 7
        kwargs.setdefault('sender', self.sender)
25 7
        return dispatcher.connect(receiver, signal, **kwargs)
26

27 7
    def disconnect(self, receiver, signal, **kwargs):
28
        """
29
        Disconnect a receiver function from a signal. This has the
30
        opposite effect of the :meth:`connect` method, and the arguments
31
        are the same.
32
        """
33 0
        kwargs.setdefault('sender', self.sender)
34 0
        return dispatcher.disconnect(receiver, signal, **kwargs)
35

36 7
    def send_catch_log(self, signal, **kwargs):
37
        """
38
        Send a signal, catch exceptions and log them.
39

40
        The keyword arguments are passed to the signal handlers (connected
41
        through the :meth:`connect` method).
42
        """
43 7
        kwargs.setdefault('sender', self.sender)
44 7
        return _signal.send_catch_log(signal, **kwargs)
45

46 7
    def send_catch_log_deferred(self, signal, **kwargs):
47
        """
48
        Like :meth:`send_catch_log` but supports returning
49
        :class:`~twisted.internet.defer.Deferred` objects from signal handlers.
50

51
        Returns a Deferred that gets fired once all signal handlers
52
        deferreds were fired. Send a signal, catch exceptions and log them.
53

54
        The keyword arguments are passed to the signal handlers (connected
55
        through the :meth:`connect` method).
56
        """
57 7
        kwargs.setdefault('sender', self.sender)
58 7
        return _signal.send_catch_log_deferred(signal, **kwargs)
59

60 7
    def disconnect_all(self, signal, **kwargs):
61
        """
62
        Disconnect all receivers from the given signal.
63

64
        :param signal: the signal to disconnect from
65
        :type signal: object
66
        """
67 0
        kwargs.setdefault('sender', self.sender)
68 0
        return _signal.disconnect_all(signal, **kwargs)

Read our documentation on viewing source code .

Loading