1"""
2 Implements signals based on blinker if available, otherwise
3 falls silently back to a noop. Shamelessly stolen from flask.signals:
4 https://github.com/mitsuhiko/flask/blob/master/flask/signals.py
5"""
6signals_available = False
7try:
8 from blinker import Namespace
9 signals_available = True
10except ImportError:
11 class Namespace:
12 def signal(self, name, doc=None):
13 return _FakeSignal(name, doc)
14
15 class _FakeSignal:
16 """If blinker is unavailable, create a fake class with the same
17 interface that allows sending of signals but will fail with an
18 error on anything else. Instead of doing anything on send, it
19 will just ignore the arguments and do nothing instead.
20 """
21
22 def __init__(self, name, doc=None):
23 self.name = name
24 self.__doc__ = doc
25 def _fail(self, *args, **kwargs):
26 raise RuntimeError('signalling support is unavailable '
27 'because the blinker library is '
28 'not installed.')
29 def send(*a, **kw):
30 return None
31 connect = disconnect = has_receivers_for = receivers_for = \
32 temporarily_connected_to = connected_to = _fail
33 del _fail
34
35# The namespace for code signals. If you are not oauthlib code, do
36# not put signals in here. Create your own namespace instead.
37_signals = Namespace()
38
39
40# Core signals.
41scope_changed = _signals.signal('scope-changed')