Skip to content
Myr

Some pythonic suggestions for requests/hooks.py

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ueg1990 · committed by ueg1990 · parent 7c74050 · Browse files · 1 file+5 added−13 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+5 added−13 removed

  • other:+5 added−13 removed

1 file+5 added−13 removed

modified:requests/hooks.py+5 added-13 removed
10 unmodified lines
11``response``:12 The response generated from a Request.1314"""15from collections import defaultdict161617HOOKS = ['response']181920def default_hooks():21 hooks = {}22 for event in HOOKS:23 hooks[event] = []24 return hooks21 return dict((event, []) for event in HOOKS)2223# TODO: response is the only one242526def dispatch_hook(key, hooks, hook_data, **kwargs):27 """Dispatches a hook dictionary on a given piece of data."""3128 hooks = hooks or dict()3334 if key in hooks:35 hooks = hooks.get(key)3629 hooks = hooks.get(key)30 if hooks:31 if hasattr(hooks, '__call__'):32 hooks = [hooks]3933 for hook in hooks:34 _hook_data = hook(hook_data, **kwargs)35 if _hook_data is not None:36 hook_data = _hook_data4445 return hook_data37 return hook_data