Skip to content

Instantly share code, notes, and snippets.

@deontologician
Created July 11, 2012 21:19
Show Gist options
  • Save deontologician/3093600 to your computer and use it in GitHub Desktop.
Save deontologician/3093600 to your computer and use it in GitHub Desktop.
hooks!
def dispatch_hook(key, hooks, hook_data):
"""Dispatches a hook dictionary on a given piece of data."""
hooks = hooks or dict()
if key in hooks:
hooks = hooks.get(key)
if hasattr(hooks, '__call__'):
hooks = [hooks]
for hook in hooks:
try:
_hook_data = hook(hook_data)
if _hook_data is not None:
hook_data = _hook_data
except Exception:
traceback.print_exc()
return hook_data
@deontologician
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment