Verified Commit aeb1ee4a authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Support requests >=2.32

Requests 2.32 seems to have introduced some breaking changes.
parent 69073a87
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
#  Copyright 2021-2023  Dominik Sekotill <dom.sekotill@kodo.org.uk>
#  Copyright 2021-2024  Dominik Sekotill <dom.sekotill@kodo.org.uk>
#
#  This Source Code Form is subject to the terms of the Mozilla Public
#  License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -60,8 +60,24 @@ class _DirectedAdapter(requests.adapters.HTTPAdapter):
		self.destination = address, port
		self.certificate = certificate

	def get_connection(self, url: str, proxies: Mapping[str, str]|None = None) -> connectionpool.HTTPConnectionPool:
	def get_connection_with_tls_context(
		self,
		request: requests.PreparedRequest,
		verify: bool|str|None,
		proxies: Mapping[str, str]|None = None,
		cert: tuple[str, str]|str|None = None,
	) -> connectionpool.HTTPConnectionPool:
		assert request.url is not None
		return self.get_connection(request.url, proxies)

	def get_connection(
		self,
		url: str|bytes,
		proxies: Mapping[str, str]|None = None,
	) -> connectionpool.HTTPConnectionPool:
		address, port = self.destination
		if isinstance(url, bytes):
			url = url.decode("ascii")
		parts = urlparse(url)
		if parts.hostname is None:
			raise LocationParseError(url)