App Engine Python SDK version 1.9.2
[gae.git] / python / lib / requests / requests / hooks.py
blob5dfaf6b68018885d099b2f6e8c7bb876a9cf29d3
1 # -*- coding: utf-8 -*-
3 """
4 requests.hooks
5 ~~~~~~~~~~~~~~
7 This module provides the capabilities for the Requests hooks system.
9 Available hooks:
11 ``response``:
12 The response generated from a Request.
14 """
17 HOOKS = ['response']
20 def default_hooks():
21 hooks = {}
22 for event in HOOKS:
23 hooks[event] = []
24 return hooks
26 # TODO: response is the only one
29 def dispatch_hook(key, hooks, hook_data, **kwargs):
30 """Dispatches a hook dictionary on a given piece of data."""
32 hooks = hooks or dict()
34 if key in hooks:
35 hooks = hooks.get(key)
37 if hasattr(hooks, '__call__'):
38 hooks = [hooks]
40 for hook in hooks:
41 _hook_data = hook(hook_data, **kwargs)
42 if _hook_data is not None:
43 hook_data = _hook_data
45 return hook_data