summaryrefslogtreecommitdiff
path: root/oauthlib/signals.py
diff options
context:
space:
mode:
authorDavid Baumgold <david@davidbaumgold.com>2014-10-05 09:21:55 -0400
committerDavid Baumgold <david@davidbaumgold.com>2014-10-05 09:43:36 -0400
commit809553ccb71f5c046454e5ce2ac90ab0757729f0 (patch)
tree8af053bdd5ef3cf5309fefd7f4f48a854ac5b805 /oauthlib/signals.py
parent201f9f00ff176c6105142d63b33c85127983b011 (diff)
downloadoauthlib-809553ccb71f5c046454e5ce2ac90ab0757729f0.tar.gz
Dispatch a blinker signal on scope change, instead of raising a warning
See https://github.com/idan/oauthlib/pull/265 for rationale. In brief: raising any exception blows the stack, which is inappropriate for a non-error state.
Diffstat (limited to 'oauthlib/signals.py')
-rw-r--r--oauthlib/signals.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/oauthlib/signals.py b/oauthlib/signals.py
new file mode 100644
index 0000000..2f86650
--- /dev/null
+++ b/oauthlib/signals.py
@@ -0,0 +1,41 @@
+# -*- coding: utf-8 -*-
+"""
+ Implements signals based on blinker if available, otherwise
+ falls silently back to a noop. Shamelessly stolen from flask.signals:
+ https://github.com/mitsuhiko/flask/blob/master/flask/signals.py
+"""
+signals_available = False
+try:
+ from blinker import Namespace
+ signals_available = True
+except ImportError:
+ class Namespace(object):
+ def signal(self, name, doc=None):
+ return _FakeSignal(name, doc)
+
+ class _FakeSignal(object):
+ """If blinker is unavailable, create a fake class with the same
+ interface that allows sending of signals but will fail with an
+ error on anything else. Instead of doing anything on send, it
+ will just ignore the arguments and do nothing instead.
+ """
+
+ def __init__(self, name, doc=None):
+ self.name = name
+ self.__doc__ = doc
+ def _fail(self, *args, **kwargs):
+ raise RuntimeError('signalling support is unavailable '
+ 'because the blinker library is '
+ 'not installed.')
+ send = lambda *a, **kw: None
+ connect = disconnect = has_receivers_for = receivers_for = \
+ temporarily_connected_to = connected_to = _fail
+ del _fail
+
+# The namespace for code signals. If you are not oauthlib code, do
+# not put signals in here. Create your own namespace instead.
+_signals = Namespace()
+
+
+# Core signals.
+scope_changed = _signals.signal('scope-changed')