Skip to content

Commit

Permalink
Merge pull request #4922 from jdufresne/ordered
Browse files Browse the repository at this point in the history
Remove unnecessary compat shim for OrderedDict
  • Loading branch information
kennethreitz authored Aug 20, 2019
2 parents 8086ffd + 2aab9a9 commit bbc3d43
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
2 changes: 2 additions & 0 deletions requests/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import cookielib
from Cookie import Morsel
from StringIO import StringIO
# Keep OrderedDict for backwards compatibility.
from collections import Callable, Mapping, MutableMapping, OrderedDict


Expand All @@ -59,6 +60,7 @@
from http import cookiejar as cookielib
from http.cookies import Morsel
from io import StringIO
# Keep OrderedDict for backwards compatibility.
from collections import OrderedDict
from collections.abc import Callable, Mapping, MutableMapping

Expand Down
3 changes: 2 additions & 1 deletion requests/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
import sys
import time
from datetime import timedelta
from collections import OrderedDict

from .auth import _basic_auth_str
from .compat import cookielib, is_py3, OrderedDict, urljoin, urlparse, Mapping
from .compat import cookielib, is_py3, urljoin, urlparse, Mapping
from .cookies import (
cookiejar_from_dict, extract_cookies_to_jar, RequestsCookieJar, merge_cookies)
from .models import Request, PreparedRequest, DEFAULT_REDIRECT_LIMIT
Expand Down
4 changes: 3 additions & 1 deletion requests/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
Data structures that power Requests.
"""

from .compat import OrderedDict, Mapping, MutableMapping
from collections import OrderedDict

from .compat import Mapping, MutableMapping


class CaseInsensitiveDict(MutableMapping):
Expand Down
3 changes: 2 additions & 1 deletion requests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
import tempfile
import warnings
import zipfile
from collections import OrderedDict

from .__version__ import __version__
from . import certs
# to_native_string is unused here, but imported here for backwards compatibility
from ._internal_utils import to_native_string
from .compat import parse_http_list as _parse_list_header
from .compat import (
quote, urlparse, bytes, str, OrderedDict, unquote, getproxies,
quote, urlparse, bytes, str, unquote, getproxies,
proxy_bypass, urlunparse, basestring, integer_types, is_py3,
proxy_bypass_environment, getproxies_environment, Mapping)
from .cookies import cookiejar_from_dict
Expand Down
8 changes: 4 additions & 4 deletions tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from requests.auth import HTTPDigestAuth, _basic_auth_str
from requests.compat import (
Morsel, cookielib, getproxies, str, urlparse,
builtin_str, OrderedDict)
builtin_str)
from requests.cookies import (
cookiejar_from_dict, morsel_to_cookie)
from requests.exceptions import (
Expand Down Expand Up @@ -130,7 +130,7 @@ def test_params_are_added_before_fragment(self, url, expected):
assert request.url == expected

def test_params_original_order_is_preserved_by_default(self):
param_ordered_dict = OrderedDict((('z', 1), ('a', 1), ('k', 1), ('d', 1)))
param_ordered_dict = collections.OrderedDict((('z', 1), ('a', 1), ('k', 1), ('d', 1)))
session = requests.Session()
request = requests.Request('GET', 'http://example.com/', params=param_ordered_dict)
prep = session.prepare_request(request)
Expand Down Expand Up @@ -446,11 +446,11 @@ def test_headers_on_session_with_None_are_not_sent(self, httpbin):
def test_headers_preserve_order(self, httpbin):
"""Preserve order when headers provided as OrderedDict."""
ses = requests.Session()
ses.headers = OrderedDict()
ses.headers = collections.OrderedDict()
ses.headers['Accept-Encoding'] = 'identity'
ses.headers['First'] = '1'
ses.headers['Second'] = '2'
headers = OrderedDict([('Third', '3'), ('Fourth', '4')])
headers = collections.OrderedDict([('Third', '3'), ('Fourth', '4')])
headers['Fifth'] = '5'
headers['Second'] = '222'
req = requests.Request('GET', httpbin('get'), headers=headers)
Expand Down

0 comments on commit bbc3d43

Please sign in to comment.