1 # -*- coding: utf-8 -*-
3 Implements signals based on blinker if available, otherwise
4 falls silently back to a noop. Shamelessly stolen from flask.signals:
5 https://github.com/mitsuhiko/flask/blob/master/flask/signals.py
7 signals_available = False
9 from blinker import Namespace
10 signals_available = True
12 class Namespace(object):
13 def signal(self, name, doc=None):
14 return _FakeSignal(name, doc)
16 class _FakeSignal(object):
17 """If blinker is unavailable, create a fake class with the same
18 interface that allows sending of signals but will fail with an
19 error on anything else. Instead of doing anything on send, it
20 will just ignore the arguments and do nothing instead.
23 def __init__(self, name, doc=None):
26 def _fail(self, *args, **kwargs):
27 raise RuntimeError('signalling support is unavailable '
28 'because the blinker library is '
30 send = lambda *a, **kw: None
31 connect = disconnect = has_receivers_for = receivers_for = \
32 temporarily_connected_to = connected_to = _fail
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()
41 scope_changed = _signals.signal('scope-changed')