Skip to content

Commit

Permalink
Fix tests on urllib3 v1
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr0grog committed Dec 16, 2023
1 parent 6f85af8 commit da46d35
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion wayback/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
ReadTimeoutError,
ProxyError,
TimeoutError)
# The Header dict lives in a different place for urllib3 v2:
try:
from urllib3 import HTTPHeaderDict as Urllib3HTTPHeaderDict
# vs. urllib3 v1:
except ImportError:
from urllib3.response import HTTPHeaderDict as Urllib3HTTPHeaderDict

from warnings import warn
from . import _utils, __version__
from ._models import CdxRecord, Memento
Expand Down Expand Up @@ -307,7 +314,6 @@ def from_httplib(cls, httplib_response, **response_kwargs):
# Unfortunately, we can't wrap the `HTTPConnection.getresponse` method in
# urllib3 v2, since it may have read the response body before returning. So
# we patch the HTTPHeaderDict class instead.
from urllib3._collections import HTTPHeaderDict as Urllib3HTTPHeaderDict
_urllib3_header_init = Urllib3HTTPHeaderDict.__init__

def _new_header_init(self, headers=None, **kwargs):
Expand Down
8 changes: 7 additions & 1 deletion wayback/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@
from urllib.parse import urlparse, ParseResult, parse_qs
from urllib3 import (HTTPConnectionPool,
HTTPResponse,
HTTPHeaderDict,
Timeout as Urllib3Timeout)
# The Header dict lives in a different place for urllib3 v2:
try:
from urllib3 import HTTPHeaderDict
# vs. urllib3 v1:
except ImportError:
from urllib3.response import HTTPHeaderDict

from .support import create_vcr
from .._client import (CdxRecord,
Mode,
Expand Down

0 comments on commit da46d35

Please sign in to comment.