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

32 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 06:35 +0000

1import typing as t 

2 

3try: 

4 from blinker import Namespace 

5 

6 signals_available = True 

7except ImportError: 

8 signals_available = False 

9 

10 class Namespace: # type: ignore 

11 def signal(self, name: str, doc: t.Optional[str] = None) -> "_FakeSignal": 

12 return _FakeSignal(name, doc) 

13 

14 class _FakeSignal: 

15 """If blinker is unavailable, create a fake class with the same 

16 interface that allows sending of signals but will fail with an 

17 error on anything else. Instead of doing anything on send, it 

18 will just ignore the arguments and do nothing instead. 

19 """ 

20 

21 def __init__(self, name: str, doc: t.Optional[str] = None) -> None: 

22 self.name = name 

23 self.__doc__ = doc 

24 

25 def send(self, *args: t.Any, **kwargs: t.Any) -> t.Any: 

26 pass 

27 

28 def _fail(self, *args: t.Any, **kwargs: t.Any) -> t.Any: 

29 raise RuntimeError( 

30 "Signalling support is unavailable because the blinker" 

31 " library is not installed." 

32 ) from None 

33 

34 connect = connect_via = connected_to = temporarily_connected_to = _fail 

35 disconnect = _fail 

36 has_receivers_for = receivers_for = _fail 

37 del _fail 

38 

39 

40# The namespace for code signals. If you are not Flask code, do 

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

42_signals = Namespace() 

43 

44 

45# Core signals. For usage examples grep the source code or consult 

46# the API documentation in docs/api.rst as well as docs/signals.rst 

47template_rendered = _signals.signal("template-rendered") 

48before_render_template = _signals.signal("before-render-template") 

49request_started = _signals.signal("request-started") 

50request_finished = _signals.signal("request-finished") 

51request_tearing_down = _signals.signal("request-tearing-down") 

52got_request_exception = _signals.signal("got-request-exception") 

53appcontext_tearing_down = _signals.signal("appcontext-tearing-down") 

54appcontext_pushed = _signals.signal("appcontext-pushed") 

55appcontext_popped = _signals.signal("appcontext-popped") 

56message_flashed = _signals.signal("message-flashed")