Remove the deprecated urllib3.contrib.ntlmpool module
MODIFY
.coveragerc
.coveragerc
@@ -4,7 +4,6 @@ source =
omit =
*urllib3/packages/*
- *urllib3/contrib/ntlmpool.py
*urllib3/contrib/pyopenssl.py
*urllib3/contrib/securetransport.py
*urllib3/contrib/_securetransport/*

MODIFY
docs/conf.py
docs/conf.py
@@ -9,23 +9,6 @@ from datetime import date
root_path = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
sys.path.insert(0, root_path)
-# Mock some expensive/platform-specific modules so build will work.
-# (https://read-the-docs.readthedocs.io/en/latest/faq.html#\
-# i-get-import-errors-on-libraries-that-depend-on-c-modules)
-from unittest import mock
-
-
-class MockModule(mock.Mock):
- @classmethod
- def __getattr__(cls, name):
- return MockModule()
-
-
-MOCK_MODULES = ("ntlm",)
-
-sys.modules.update((mod_name, MockModule()) for mod_name in MOCK_MODULES)
-
-
import urllib3
# -- General configuration -----------------------------------------------------

MODIFY
docs/reference/contrib/index.rst
docs/reference/contrib/index.rst
@@ -6,7 +6,6 @@ prime time or that require optional third-party dependencies.
.. toctree::
- ntlmpool
pyopenssl
securetransport
socks

DELETE
docs/reference/contrib/ntlmpool.rst
-NTLM Authentication
-===================
-
-.. automodule:: urllib3.contrib.ntlmpool
- :members:
- :undoc-members:
- :show-inheritance:

DELETE
src/urllib3/contrib/ntlmpool.py
-"""
-NTLM authenticating pool, contributed by erikcederstran
-
-Issue #10, see: http://code.google.com/p/urllib3/issues/detail?id=10
-"""
-
-from http.client import HTTPSConnection
-from logging import getLogger
-from typing import Any, Dict, Optional, Union
-
-from ntlm import ntlm # type:ignore
-
-from .. import HTTPSConnectionPool
-from ..connection import _TYPE_BODY
-from ..response import BaseHTTPResponse
-from ..util.retry import Retry
-
-log = getLogger(__name__)
-
-
-class NTLMConnectionPool(HTTPSConnectionPool):
- """
- Implements an NTLM authentication version of an urllib3 connection pool
- """
-
- scheme = "https"
-
- def __init__(self, user: str, pw: str, authurl: str, *args: Any, **kwargs: Any):
- """
- authurl is a random URL on the server that is protected by NTLM.
- user is the Windows user, probably in the DOMAIN\\username format.
- pw is the password for the user.
- """
- super().__init__(*args, **kwargs)
- self.authurl = authurl
- self.rawuser = user
- user_parts = user.split("\\", 1)
- self.domain = user_parts[0].upper()
- self.user = user_parts[1]
- self.pw = pw
-
- def _new_conn(self) -> HTTPSConnection: # type: ignore
- # Performs the NTLM handshake that secures the connection. The socket
- # must be kept open while requests are performed.
- self.num_connections += 1
- log.debug(
- "Starting NTLM HTTPS connection no. %d: https://%s%s",
- self.num_connections,
- self.host,
- self.authurl,
- )
-
- headers = {"Connection": "Keep-Alive"}
- req_header = "Authorization"
- resp_header = "www-authenticate"
-
- conn = HTTPSConnection(host=self.host, port=self.port)
-
- # Send negotiation message
- headers[req_header] = f"NTLM {ntlm.create_NTLM_NEGOTIATE_MESSAGE(self.rawuser)}"
- log.debug("Request headers: %s", headers)
- conn.request("GET", self.authurl, None, headers)
- res = conn.getresponse()
- reshdr = dict(res.getheaders())
- log.debug("Response status: %s %s", res.status, res.reason)
- log.debug("Response headers: %s", reshdr)
- log.debug("Response data: %s [...]", res.read(100))
-
- # Remove the reference to the socket, so that it can not be closed by
- # the response object (we want to keep the socket open)
- res.fp = None # type: ignore
-
- # Server should respond with a challenge message
- auth_header_values = reshdr[resp_header].split(", ")
- auth_header_value = None
- for s in auth_header_values:
- if s[:5] == "NTLM ":
- auth_header_value = s[5:]
- if auth_header_value is None:
- raise Exception(
- f"Unexpected {resp_header} response header: {reshdr[resp_header]}"
- )
-
- # Send authentication message
- ServerChallenge, NegotiateFlags = ntlm.parse_NTLM_CHALLENGE_MESSAGE(
- auth_header_value
- )
- auth_msg = ntlm.create_NTLM_AUTHENTICATE_MESSAGE(
- ServerChallenge, self.user, self.domain, self.pw, NegotiateFlags
- )
- headers[req_header] = f"NTLM {auth_msg}"
- log.debug("Request headers: %s", headers)
- conn.request("GET", self.authurl, None, headers)
- res = conn.getresponse()
- log.debug("Response status: %s %s", res.status, res.reason)
- log.debug("Response headers: %s", dict(res.getheaders()))
- log.debug("Response data: %s [...]", res.read()[:100])
- if res.status != 200:
- if res.status == 401:
- raise Exception("Server rejected request: wrong username or password")
- raise Exception(f"Wrong server response: {res.status} {res.reason}")
-
- res.fp = None # type: ignore
- log.debug("Connection established")
- return conn
-
- def urlopen( # type: ignore
- self,
- method: str,
- url: str,
- body: Optional[_TYPE_BODY] = None,
- headers: Optional[Dict[str, str]] = None,
- retries: Union[Retry, bool, int] = 3,
- redirect: bool = True,
- assert_same_host: bool = True,
- ) -> BaseHTTPResponse:
- if headers is None:
- headers = {}
- headers["Connection"] = "Keep-Alive"
- return super().urlopen(
- method, url, body, headers, retries, redirect, assert_same_host
- )

Remove the deprecated urllib3.contrib.ntlmpool module