added win_unicode_console module
[twitter-api-cdsw] / oauthlib / signals.py
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:
12     class Namespace(object):
13         def signal(self, name, doc=None):
14             return _FakeSignal(name, doc)
15
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.
21         """
22
23         def __init__(self, name, doc=None):
24             self.name = name
25             self.__doc__ = doc
26         def _fail(self, *args, **kwargs):
27             raise RuntimeError('signalling support is unavailable '
28                                'because the blinker library is '
29                                'not installed.')
30         send = lambda *a, **kw: 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.
41 scope_changed = _signals.signal('scope-changed')

Benjamin Mako Hill || Want to submit a patch?