Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth Reitz committed Oct 2, 2012
2 parents ccf5504 + 1e61cf5 commit f1ffe19
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions requests/models.py
Expand Up @@ -462,10 +462,10 @@ def path_url(self):

def register_hook(self, event, hook):
"""Properly register a hook."""
if isinstance(hook, (list, tuple, set)):
self.hooks[event].extend(hook)
else:
if callable(hook):
self.hooks[event].append(hook)
elif hasattr(hook, '__iter__'):
self.hooks[event].extend(h for h in hook if callable(h))

def deregister_hook(self, event, hook):
"""Deregister a previously registered hook.
Expand Down
4 changes: 4 additions & 0 deletions tests/test_requests.py
Expand Up @@ -778,6 +778,10 @@ def assert_hooks_are_callable(hooks):
r = requests.models.Request(hooks={'args': hooks})
assert_hooks_are_callable(r.hooks)

hooks.append('string that should not be registered')
r = requests.models.Request(hooks={'args': hooks})
assert_hooks_are_callable(r.hooks)

def test_session_persistent_cookies(self):

s = requests.session()
Expand Down

0 comments on commit f1ffe19

Please sign in to comment.