diff options
-rw-r--r-- | requests/compat.py | 2 | ||||
-rw-r--r-- | requests/cookies.py | 5 | ||||
-rw-r--r-- | requests/models.py | 8 | ||||
-rw-r--r-- | requests/sessions.py | 3 | ||||
-rw-r--r-- | requests/structures.py | 10 | ||||
-rw-r--r-- | requests/utils.py | 5 | ||||
-rw-r--r-- | tests/test_requests.py | 3 |
7 files changed, 17 insertions, 19 deletions
diff --git a/requests/compat.py b/requests/compat.py index f417cfd8..6b9c6fac 100644 --- a/requests/compat.py +++ b/requests/compat.py @@ -43,6 +43,7 @@ if is_py2: import cookielib from Cookie import Morsel from StringIO import StringIO + from collections import Callable, Mapping, MutableMapping from urllib3.packages.ordered_dict import OrderedDict @@ -60,6 +61,7 @@ elif is_py3: from http.cookies import Morsel from io import StringIO from collections import OrderedDict + from collections.abc import Callable, Mapping, MutableMapping builtin_str = str str = str diff --git a/requests/cookies.py b/requests/cookies.py index ab3c88b9..4c0893ff 100644 --- a/requests/cookies.py +++ b/requests/cookies.py @@ -12,10 +12,9 @@ requests.utils imports from here, so be careful with imports. import copy import time import calendar -import collections from ._internal_utils import to_native_string -from .compat import cookielib, urlparse, urlunparse, Morsel +from .compat import cookielib, urlparse, urlunparse, Morsel, MutableMapping try: import threading @@ -169,7 +168,7 @@ class CookieConflictError(RuntimeError): """ -class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping): +class RequestsCookieJar(cookielib.CookieJar, MutableMapping): """Compatibility class; is a cookielib.CookieJar, but exposes a dict interface. diff --git a/requests/models.py b/requests/models.py index 37e7f9a2..0eaaaf94 100644 --- a/requests/models.py +++ b/requests/models.py @@ -7,7 +7,6 @@ requests.models This module contains the primary objects that power Requests. """ -import collections import datetime import sys @@ -37,6 +36,7 @@ from .utils import ( stream_decode_response_unicode, to_key_val_list, parse_header_links, iter_slices, guess_json_utf, super_len, check_header_validity) from .compat import ( + Callable, Mapping, cookielib, urlunparse, urlsplit, urlencode, str, bytes, is_py2, chardet, builtin_str, basestring) from .compat import json as complexjson @@ -178,10 +178,10 @@ class RequestHooksMixin(object): if event not in self.hooks: raise ValueError('Unsupported event specified, with event name "%s"' % (event)) - if isinstance(hook, collections.Callable): + if isinstance(hook, Callable): self.hooks[event].append(hook) elif hasattr(hook, '__iter__'): - self.hooks[event].extend(h for h in hook if isinstance(h, collections.Callable)) + self.hooks[event].extend(h for h in hook if isinstance(h, Callable)) def deregister_hook(self, event, hook): """Deregister a previously registered hook. @@ -465,7 +465,7 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin): is_stream = all([ hasattr(data, '__iter__'), - not isinstance(data, (basestring, list, tuple, collections.Mapping)) + not isinstance(data, (basestring, list, tuple, Mapping)) ]) try: diff --git a/requests/sessions.py b/requests/sessions.py index 4ffed46a..ba135268 100644 --- a/requests/sessions.py +++ b/requests/sessions.py @@ -10,11 +10,10 @@ requests (cookies, auth, proxies). import os import sys import time -from collections import Mapping from datetime import timedelta from .auth import _basic_auth_str -from .compat import cookielib, is_py3, OrderedDict, urljoin, urlparse +from .compat import cookielib, is_py3, OrderedDict, urljoin, urlparse, Mapping from .cookies import ( cookiejar_from_dict, extract_cookies_to_jar, RequestsCookieJar, merge_cookies) from .models import Request, PreparedRequest, DEFAULT_REDIRECT_LIMIT diff --git a/requests/structures.py b/requests/structures.py index 05d2b3f5..da930e28 100644 --- a/requests/structures.py +++ b/requests/structures.py @@ -7,16 +7,14 @@ requests.structures Data structures that power Requests. """ -import collections +from .compat import OrderedDict, Mapping, MutableMapping -from .compat import OrderedDict - -class CaseInsensitiveDict(collections.MutableMapping): +class CaseInsensitiveDict(MutableMapping): """A case-insensitive ``dict``-like object. Implements all methods and operations of - ``collections.MutableMapping`` as well as dict's ``copy``. Also + ``MutableMapping`` as well as dict's ``copy``. Also provides ``lower_items``. All keys are expected to be strings. The structure remembers the @@ -71,7 +69,7 @@ class CaseInsensitiveDict(collections.MutableMapping): ) def __eq__(self, other): - if isinstance(other, collections.Mapping): + if isinstance(other, Mapping): other = CaseInsensitiveDict(other) else: return NotImplemented diff --git a/requests/utils.py b/requests/utils.py index 07f8c7f7..431f6be0 100644 --- a/requests/utils.py +++ b/requests/utils.py @@ -9,7 +9,6 @@ that are also useful for external consumption. """ import codecs -import collections import contextlib import io import os @@ -29,7 +28,7 @@ from .compat import parse_http_list as _parse_list_header from .compat import ( quote, urlparse, bytes, str, OrderedDict, unquote, getproxies, proxy_bypass, urlunparse, basestring, integer_types, is_py3, - proxy_bypass_environment, getproxies_environment) + proxy_bypass_environment, getproxies_environment, Mapping) from .cookies import cookiejar_from_dict from .structures import CaseInsensitiveDict from .exceptions import ( @@ -301,7 +300,7 @@ def to_key_val_list(value): if isinstance(value, (str, bytes, bool, int)): raise ValueError('cannot encode objects that are not 2-tuples') - if isinstance(value, collections.Mapping): + if isinstance(value, Mapping): value = value.items() return list(value) diff --git a/tests/test_requests.py b/tests/test_requests.py index 0106713d..55a2f97d 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -29,6 +29,7 @@ from requests.structures import CaseInsensitiveDict from requests.sessions import SessionRedirectMixin from requests.models import urlencode from requests.hooks import default_hooks +from requests.compat import MutableMapping from .compat import StringIO, u from .utils import override_environ @@ -745,7 +746,7 @@ class TestRequests: requests.post(url, files=['bad file data']) def test_post_with_custom_mapping(self, httpbin): - class CustomMapping(collections.MutableMapping): + class CustomMapping(MutableMapping): def __init__(self, *args, **kwargs): self.data = dict(*args, **kwargs) |