mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
+3
-2
@@ -9,6 +9,7 @@ This module contains the primary objects that power Requests.
|
||||
|
||||
import os
|
||||
import socket
|
||||
import collections
|
||||
from datetime import datetime
|
||||
from io import BytesIO
|
||||
|
||||
@@ -467,10 +468,10 @@ class Request(object):
|
||||
|
||||
def register_hook(self, event, hook):
|
||||
"""Properly register a hook."""
|
||||
if callable(hook):
|
||||
if isinstance(hook, collections.Callable):
|
||||
self.hooks[event].append(hook)
|
||||
elif hasattr(hook, '__iter__'):
|
||||
self.hooks[event].extend(h for h in hook if callable(h))
|
||||
self.hooks[event].extend(h for h in hook if isinstance(h, collections.Callable))
|
||||
|
||||
def deregister_hook(self, event, hook):
|
||||
"""Deregister a previously registered hook.
|
||||
|
||||
@@ -11,6 +11,7 @@ import json
|
||||
import unittest
|
||||
import pickle
|
||||
import tempfile
|
||||
import collections
|
||||
|
||||
import requests
|
||||
from requests.compat import str, StringIO
|
||||
@@ -805,7 +806,7 @@ class RequestsTestSuite(TestSetup, TestBaseMixin, unittest.TestCase):
|
||||
|
||||
def assert_hooks_are_callable(hooks):
|
||||
for h in hooks['args']:
|
||||
self.assertTrue(callable(h))
|
||||
self.assertTrue(isinstance(h, collections.Callable))
|
||||
|
||||
hooks = [add_foo_header, add_bar_header]
|
||||
r = requests.models.Request()
|
||||
|
||||
Reference in New Issue
Block a user