mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Only register callable items in lists
Prior to this, you could sneak a list of anything to register_hook and it would accept it. This will check if the items in the list are callable before registering them. Also added a regression test to make sure if this gets changed it will be noticed.
This commit is contained in:
committed by
Radu Voicilas
parent
46fd297c3a
commit
4e6cf21d82
+3
-3
@@ -462,10 +462,10 @@ class Request(object):
|
||||
|
||||
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.
|
||||
|
||||
@@ -778,6 +778,10 @@ class RequestsTestSuite(TestSetup, TestBaseMixin, unittest.TestCase):
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user