You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.5 KiB

  1. # -*- coding: utf-8 -*-
  2. """
  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
  6. """
  7. signals_available = False
  8. try:
  9. from blinker import Namespace
  10. signals_available = True
  11. except ImportError: # noqa
  12. class Namespace(object):
  13. def signal(self, name, doc=None):
  14. return _FakeSignal(name, doc)
  15. class _FakeSignal(object):
  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. def __init__(self, name, doc=None):
  22. self.name = name
  23. self.__doc__ = doc
  24. def _fail(self, *args, **kwargs):
  25. raise RuntimeError('signalling support is unavailable '
  26. 'because the blinker library is '
  27. 'not installed.')
  28. send = lambda *a, **kw: None
  29. connect = disconnect = has_receivers_for = receivers_for = \
  30. temporarily_connected_to = connected_to = _fail
  31. del _fail
  32. # The namespace for code signals. If you are not oauthlib code, do
  33. # not put signals in here. Create your own namespace instead.
  34. _signals = Namespace()
  35. # Core signals.
  36. scope_changed = _signals.signal('scope-changed')