Commit 4b34c4dc authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Raise appropriate exceptions for poorly formatted URLs

parent 2f4fe78e
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
#  Copyright 2021,2022  Dominik Sekotill <dom.sekotill@kodo.org.uk>
#  Copyright 2021-2023  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
@@ -18,6 +18,8 @@ from urllib.parse import urlparse
import requests.adapters
from urllib3 import connection
from urllib3 import connectionpool
from urllib3.exceptions import LocationParseError
from urllib3.exceptions import URLSchemeUnknown


def redirect(
@@ -59,10 +61,13 @@ class _DirectedAdapter(requests.adapters.HTTPAdapter):

	def get_connection(self, url: str, proxies: Mapping[str, str]|None = None) -> connectionpool.HTTPConnectionPool:
		parts = urlparse(url)
		if parts.hostname is None:
			raise LocationParseError(url)
		if parts.scheme == "https":
			return _HTTPSConnectionPool(parts.hostname, parts.port, address=self.destination)
		else:
		if parts.scheme == "http":
			return _HTTPConnectionPool(parts.hostname, parts.port, address=self.destination)
		raise URLSchemeUnknown(parts.scheme)

	def cert_verify(
		self,