annotate requests/hooks.py @ 10:ccec96a537b7

planemo upload for repository https://toolrepo.galaxytrakr.org/view/jpayne/bioproject_to_srr_2/556cac4fb538
author jpayne
date Mon, 06 May 2024 00:12:39 -0400
parents 5eb2d5e3bf22
children
rev   line source
jpayne@7 1 """
jpayne@7 2 requests.hooks
jpayne@7 3 ~~~~~~~~~~~~~~
jpayne@7 4
jpayne@7 5 This module provides the capabilities for the Requests hooks system.
jpayne@7 6
jpayne@7 7 Available hooks:
jpayne@7 8
jpayne@7 9 ``response``:
jpayne@7 10 The response generated from a Request.
jpayne@7 11 """
jpayne@7 12 HOOKS = ["response"]
jpayne@7 13
jpayne@7 14
jpayne@7 15 def default_hooks():
jpayne@7 16 return {event: [] for event in HOOKS}
jpayne@7 17
jpayne@7 18
jpayne@7 19 # TODO: response is the only one
jpayne@7 20
jpayne@7 21
jpayne@7 22 def dispatch_hook(key, hooks, hook_data, **kwargs):
jpayne@7 23 """Dispatches a hook dictionary on a given piece of data."""
jpayne@7 24 hooks = hooks or {}
jpayne@7 25 hooks = hooks.get(key)
jpayne@7 26 if hooks:
jpayne@7 27 if hasattr(hooks, "__call__"):
jpayne@7 28 hooks = [hooks]
jpayne@7 29 for hook in hooks:
jpayne@7 30 _hook_data = hook(hook_data, **kwargs)
jpayne@7 31 if _hook_data is not None:
jpayne@7 32 hook_data = _hook_data
jpayne@7 33 return hook_data