Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/oauthlib/signals.py: 89%

19 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-12-08 06:22 +0000

1""" 

2 Implements signals based on blinker if available, otherwise 

3 falls silently back to a noop. Shamelessly stolen from flask.signals: 

4 https://github.com/mitsuhiko/flask/blob/master/flask/signals.py 

5""" 

6signals_available = False 

7try: 

8 from blinker import Namespace 

9 signals_available = True 

10except ImportError: # noqa 

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 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 

22 def __init__(self, name, doc=None): 

23 self.name = name 

24 self.__doc__ = doc 

25 def _fail(self, *args, **kwargs): 

26 raise RuntimeError('signalling support is unavailable ' 

27 'because the blinker library is ' 

28 'not installed.') 

29 send = lambda *a, **kw: None 

30 connect = disconnect = has_receivers_for = receivers_for = \ 

31 temporarily_connected_to = connected_to = _fail 

32 del _fail 

33 

34# The namespace for code signals. If you are not oauthlib code, do 

35# not put signals in here. Create your own namespace instead. 

36_signals = Namespace() 

37 

38 

39# Core signals. 

40scope_changed = _signals.signal('scope-changed')