Debian Codegraph @

arduino-core/src/processing/app/i18n/python/requests/hooks.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 """
4 requests.hooks
5 ~~~~~~~~~~~~~~
6
7 This module provides the capabilities for the Requests hooks system.
8
9 Available hooks:
10
11 ``response``:
12 The response generated from a Request.
13
14 """
15
16
17 HOOKS = ['response']
18
19
20 def default_hooks():
21 hooks = {}
22 for event in HOOKS:
23 hooks[event] = []
24 return hooks
25
26 # TODO: response is the only one
27
28
29 def dispatch_hook(key, hooks, hook_data, **kwargs):
30 """Dispatches a hook dictionary on a given piece of data."""
31
32 hooks = hooks or dict()
33
34 if key in hooks:
35 hooks = hooks.get(key)
36
37 if hasattr(hooks, '__call__'):
38 hooks = [hooks]
39
40 for hook in hooks:
41 _hook_data = hook(hook_data, **kwargs)
42 if _hook_data is not None:
43 hook_data = _hook_data
44
45 return hook_data