codekingpro/portable-devtools
114k
1"""2 Implements signals based on blinker if available, otherwise3 falls silently back to a noop. Shamelessly stolen from flask.signals:4 https://github.com/mitsuhiko/flask/blob/master/flask/signals.py5"""6signals_available = False7try:8 from blinker import Namespace9 signals_available = True10except 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 same17 interface that allows sending of signals but will fail with an18 error on anything else. Instead of doing anything on send, it19 will just ignore the arguments and do nothing instead.20 """21 22 def __init__(self, name, doc=None):23 self.name = name24 self.__doc__ = doc25 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 None31 connect = disconnect = has_receivers_for = receivers_for = \32 temporarily_connected_to = connected_to = _fail33 del _fail34 35# The namespace for code signals. If you are not oauthlib code, do36# not put signals in here. Create your own namespace instead.37_signals = Namespace()38 39 40# Core signals.41scope_changed = _signals.signal('scope-changed')42 