Skip to content

Commit da46d35

Browse files
committed
Fix tests on urllib3 v1
1 parent 6f85af8 commit da46d35

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

wayback/_client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@
3838
ReadTimeoutError,
3939
ProxyError,
4040
TimeoutError)
41+
# The Header dict lives in a different place for urllib3 v2:
42+
try:
43+
from urllib3 import HTTPHeaderDict as Urllib3HTTPHeaderDict
44+
# vs. urllib3 v1:
45+
except ImportError:
46+
from urllib3.response import HTTPHeaderDict as Urllib3HTTPHeaderDict
47+
4148
from warnings import warn
4249
from . import _utils, __version__
4350
from ._models import CdxRecord, Memento
@@ -307,7 +314,6 @@ def from_httplib(cls, httplib_response, **response_kwargs):
307314
# Unfortunately, we can't wrap the `HTTPConnection.getresponse` method in
308315
# urllib3 v2, since it may have read the response body before returning. So
309316
# we patch the HTTPHeaderDict class instead.
310-
from urllib3._collections import HTTPHeaderDict as Urllib3HTTPHeaderDict
311317
_urllib3_header_init = Urllib3HTTPHeaderDict.__init__
312318

313319
def _new_header_init(self, headers=None, **kwargs):

wayback/tests/test_client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@
88
from urllib.parse import urlparse, ParseResult, parse_qs
99
from urllib3 import (HTTPConnectionPool,
1010
HTTPResponse,
11-
HTTPHeaderDict,
1211
Timeout as Urllib3Timeout)
12+
# The Header dict lives in a different place for urllib3 v2:
13+
try:
14+
from urllib3 import HTTPHeaderDict
15+
# vs. urllib3 v1:
16+
except ImportError:
17+
from urllib3.response import HTTPHeaderDict
18+
1319
from .support import create_vcr
1420
from .._client import (CdxRecord,
1521
Mode,

0 commit comments

Comments
 (0)