Avoid using callable().

Callable() is not included in Python 3.1, so we shouldn't use it.
This commit is contained in:
Cory Benfield
2012-11-24 12:15:30 +00:00
parent 991f47ac08
commit d5f9a2a51c
2 changed files with 5 additions and 3 deletions
+3 -2
View File
@@ -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.
+2 -1
View File
@@ -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()