Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/requests/hooks.py: 93%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

15 statements  

1""" 

2requests.hooks 

3~~~~~~~~~~~~~~ 

4 

5This module provides the capabilities for the Requests hooks system. 

6 

7Available hooks: 

8 

9``response``: 

10 The response generated from a Request. 

11""" 

12 

13HOOKS = ["response"] 

14 

15 

16def default_hooks(): 

17 return {event: [] for event in HOOKS} 

18 

19 

20# TODO: response is the only one 

21 

22 

23def dispatch_hook(key, hooks, hook_data, **kwargs): 

24 """Dispatches a hook dictionary on a given piece of data.""" 

25 hooks = hooks or {} 

26 hooks = hooks.get(key) 

27 if hooks: 

28 if hasattr(hooks, "__call__"): 

29 hooks = [hooks] 

30 for hook in hooks: 

31 _hook_data = hook(hook_data, **kwargs) 

32 if _hook_data is not None: 

33 hook_data = _hook_data 

34 return hook_data