Created
July 11, 2012 21:19
-
-
Save deontologician/3093600 to your computer and use it in GitHub Desktop.
hooks!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Found this today in https://github.com/kennethreitz/requests/blob/develop/requests/hooks.py