prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Deprecate NTLMConnectionPool in 1.26.x
  As was mentioned in https://github.com/urllib3/urllib3/pull/2278#issuecomment-864414599 and https://github.com/urllib3/urllib3/pull/2278#issuecomment-864450016 we're moving to remove `NTLMConnectionPool` and the `urllib3.contrib.nltmpool` module from urllib3 in v2.0 if we don't find a new maintainer for the module (perhaps as a third-party package ie `urllib3-ntlmpool`?)
  
  - The module is not covered by our test suite.
  - It is not clear even which pypi package is needed for it.
  - It has fallen into disrepair (e.g. timeout/ssl/other options not being respected).
  - According to Wikipedia, "Since 2010, Microsoft no longer recommends NTLM in applications"
  - Seems like it's not used often, if at all.
  
  In the `1.26.x` branch we should unconditionally raise a `DeprecationWarning` when the module is imported. Should link to this issue with a call to action to comment in the issue if they are a user. This should help us better discover who (if any) our users are here so we can better make a decision.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `src/urllib3/contrib/ntlmpool.py`
  Content:
  ```
  1 """
  2 NTLM authenticating pool, contributed by erikcederstran
  3 
  4 Issue #10, see: http://code.google.com/p/urllib3/issues/detail?id=10
  5 """
  6 from __future__ import absolute_import
  7 
  8 from logging import getLogger
  9 
  10 from ntlm import ntlm
  11 
  12 from .. import HTTPSConnectionPool
  13 from ..packages.six.moves.http_client import HTTPSConnection
  14 
  15 log = getLogger(__name__)
  16 
  17 
  18 class NTLMConnectionPool(HTTPSConnectionPool):
  19     """
  20     Implements an NTLM authentication version of an urllib3 connection pool
  21     """
  22 
  23     scheme = "https"
  24 
  25     def __init__(self, user, pw, authurl, *args, **kwargs):
  26         """
  27         authurl is a random URL on the server that is protected by NTLM.
  28         user is the Windows user, probably in the DOMAIN\\username format.
  29         pw is the password for the user.
  30         """
  31         super(NTLMConnectionPool, self).__init__(*args, **kwargs)
  32         self.authurl = authurl
  33         self.rawuser = user
  34         user_parts = user.split("\\", 1)
  35         self.domain = user_parts[0].upper()
  36         self.user = user_parts[1]
  37         self.pw = pw
  38 
  39     def _new_conn(self):
  40         # Performs the NTLM handshake that secures the connection. The socket
  41         # must be kept open while requests are performed.
  42         self.num_connections += 1
  43         log.debug(
  44             "Starting NTLM HTTPS connection no. %d: https://%s%s",
  45             self.num_connections,
  46             self.host,
  47             self.authurl,
  48         )
  49 
  50         headers = {"Connection": "Keep-Alive"}
  51         req_header = "Authorization"
  52         resp_header = "www-authenticate"
  53 
  54         conn = HTTPSConnection(host=self.host, port=self.port)
  55 
  56         # Send negotiation message
  57         headers[req_header] = "NTLM %s" % ntlm.create_NTLM_NEGOTIATE_MESSAGE(
  58             self.rawuser
  59         )
  60         log.debug("Request headers: %s", headers)
  61         conn.request("GET", self.authurl, None, headers)
  62         res = conn.getresponse()
  63         reshdr = dict(res.getheaders())
  64         log.debug("Response status: %s %s", res.status, res.reason)
  65         log.debug("Response headers: %s", reshdr)
  66         log.debug("Response data: %s [...]", res.read(100))
  67 
  68         # Remove the reference to the socket, so that it can not be closed by
  69         # the response object (we want to keep the socket open)
  70         res.fp = None
  71 
  72         # Server should respond with a challenge message
  73         auth_header_values = reshdr[resp_header].split(", ")
  74         auth_header_value = None
  75         for s in auth_header_values:
  76             if s[:5] == "NTLM ":
  77                 auth_header_value = s[5:]
  78         if auth_header_value is None:
  79             raise Exception(
  80                 "Unexpected %s response header: %s" % (resp_header, reshdr[resp_header])
  81             )
  82 
  83         # Send authentication message
  84         ServerChallenge, NegotiateFlags = ntlm.parse_NTLM_CHALLENGE_MESSAGE(
  85             auth_header_value
  86         )
  87         auth_msg = ntlm.create_NTLM_AUTHENTICATE_MESSAGE(
  88             ServerChallenge, self.user, self.domain, self.pw, NegotiateFlags
  89         )
  90         headers[req_header] = "NTLM %s" % auth_msg
  91         log.debug("Request headers: %s", headers)
  92         conn.request("GET", self.authurl, None, headers)
  93         res = conn.getresponse()
  94         log.debug("Response status: %s %s", res.status, res.reason)
  95         log.debug("Response headers: %s", dict(res.getheaders()))
  96         log.debug("Response data: %s [...]", res.read()[:100])
  97         if res.status != 200:
  98             if res.status == 401:
  99                 raise Exception("Server rejected request: wrong username or password")
  100             raise Exception("Wrong server response: %s %s" % (res.status, res.reason))
  101 
  102         res.fp = None
  103         log.debug("Connection established")
  104         return conn
  105 
  106     def urlopen(
  107         self,
  108         method,
  109         url,
  110         body=None,
  111         headers=None,
  112         retries=3,
  113         redirect=True,
  114         assert_same_host=True,
  115     ):
  116         if headers is None:
  117             headers = {}
  118         headers["Connection"] = "Keep-Alive"
  119         return super(NTLMConnectionPool, self).urlopen(
  120             method, url, body, headers, retries, redirect, assert_same_host
  121         )
  122
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/src/urllib3/contrib/ntlmpool.py b/src/urllib3/contrib/ntlmpool.py
  --- a/src/urllib3/contrib/ntlmpool.py
  +++ b/src/urllib3/contrib/ntlmpool.py
  @@ -5,6 +5,7 @@
   """
   from __future__ import absolute_import
   
  +import warnings
   from logging import getLogger
   
   from ntlm import ntlm
  @@ -12,6 +13,14 @@
   from .. import HTTPSConnectionPool
   from ..packages.six.moves.http_client import HTTPSConnection
   
  +warnings.warn(
  +    "The 'urllib3.contrib.ntlmpool' module is deprecated and will be removed "
  +    "in urllib3 v2.0 release, urllib3 is not able to support it properly due "
  +    "to reasons listed in issue: https://github.com/urllib3/urllib3/issues/2282. "
  +    "If you are a user of this module please comment in the mentioned issue.",
  +    DeprecationWarning,
  +)
  +
   log = getLogger(__name__)
  
verification_info: {"golden_diff": "diff --git a/src/urllib3/contrib/ntlmpool.py b/src/urllib3/contrib/ntlmpool.py\n--- a/src/urllib3/contrib/ntlmpool.py\n+++ b/src/urllib3/contrib/ntlmpool.py\n@@ -5,6 +5,7 @@\n \"\"\"\n from __future__ import absolute_import\n \n+import warnings\n from logging import getLogger\n \n from ntlm import ntlm\n@@ -12,6 +13,14 @@\n from .. import HTTPSConnectionPool\n from ..packages.six.moves.http_client import HTTPSConnection\n \n+warnings.warn(\n+    \"The 'urllib3.contrib.ntlmpool' module is deprecated and will be removed \"\n+    \"in urllib3 v2.0 release, urllib3 is not able to support it properly due \"\n+    \"to reasons listed in issue: https://github.com/urllib3/urllib3/issues/2282. \"\n+    \"If you are a user of this module please comment in the mentioned issue.\",\n+    DeprecationWarning,\n+)\n+\n log = getLogger(__name__)\n", "issue": "Deprecate NTLMConnectionPool in 1.26.x\nAs was mentioned in https://github.com/urllib3/urllib3/pull/2278#issuecomment-864414599 and https://github.com/urllib3/urllib3/pull/2278#issuecomment-864450016 we're moving to remove `NTLMConnectionPool` and the `urllib3.contrib.nltmpool` module from urllib3 in v2.0 if we don't find a new maintainer for the module (perhaps as a third-party package ie `urllib3-ntlmpool`?)\r\n\r\n- The module is not covered by our test suite.\r\n- It is not clear even which pypi package is needed for it.\r\n- It has fallen into disrepair (e.g. timeout/ssl/other options not being respected).\r\n- According to Wikipedia, \"Since 2010, Microsoft no longer recommends NTLM in applications\"\r\n- Seems like it's not used often, if at all.\r\n\r\nIn the `1.26.x` branch we should unconditionally raise a `DeprecationWarning` when the module is imported. Should link to this issue with a call to action to comment in the issue if they are a user. This should help us better discover who (if any) our users are here so we can better make a decision.\n", "before_files": [{"content": "\"\"\"\nNTLM authenticating pool, contributed by erikcederstran\n\nIssue #10, see: http://code.google.com/p/urllib3/issues/detail?id=10\n\"\"\"\nfrom __future__ import absolute_import\n\nfrom logging import getLogger\n\nfrom ntlm import ntlm\n\nfrom .. import HTTPSConnectionPool\nfrom ..packages.six.moves.http_client import HTTPSConnection\n\nlog = getLogger(__name__)\n\n\nclass NTLMConnectionPool(HTTPSConnectionPool):\n    \"\"\"\n    Implements an NTLM authentication version of an urllib3 connection pool\n    \"\"\"\n\n    scheme = \"https\"\n\n    def __init__(self, user, pw, authurl, *args, **kwargs):\n        \"\"\"\n        authurl is a random URL on the server that is protected by NTLM.\n        user is the Windows user, probably in the DOMAIN\\\\username format.\n        pw is the password for the user.\n        \"\"\"\n        super(NTLMConnectionPool, self).__init__(*args, **kwargs)\n        self.authurl = authurl\n        self.rawuser = user\n        user_parts = user.split(\"\\\\\", 1)\n        self.domain = user_parts[0].upper()\n        self.user = user_parts[1]\n        self.pw = pw\n\n    def _new_conn(self):\n        # Performs the NTLM handshake that secures the connection. The socket\n        # must be kept open while requests are performed.\n        self.num_connections += 1\n        log.debug(\n            \"Starting NTLM HTTPS connection no. %d: https://%s%s\",\n            self.num_connections,\n            self.host,\n            self.authurl,\n        )\n\n        headers = {\"Connection\": \"Keep-Alive\"}\n        req_header = \"Authorization\"\n        resp_header = \"www-authenticate\"\n\n        conn = HTTPSConnection(host=self.host, port=self.port)\n\n        # Send negotiation message\n        headers[req_header] = \"NTLM %s\" % ntlm.create_NTLM_NEGOTIATE_MESSAGE(\n            self.rawuser\n        )\n        log.debug(\"Request headers: %s\", headers)\n        conn.request(\"GET\", self.authurl, None, headers)\n        res = conn.getresponse()\n        reshdr = dict(res.getheaders())\n        log.debug(\"Response status: %s %s\", res.status, res.reason)\n        log.debug(\"Response headers: %s\", reshdr)\n        log.debug(\"Response data: %s [...]\", res.read(100))\n\n        # Remove the reference to the socket, so that it can not be closed by\n        # the response object (we want to keep the socket open)\n        res.fp = None\n\n        # Server should respond with a challenge message\n        auth_header_values = reshdr[resp_header].split(\", \")\n        auth_header_value = None\n        for s in auth_header_values:\n            if s[:5] == \"NTLM \":\n                auth_header_value = s[5:]\n        if auth_header_value is None:\n            raise Exception(\n                \"Unexpected %s response header: %s\" % (resp_header, reshdr[resp_header])\n            )\n\n        # Send authentication message\n        ServerChallenge, NegotiateFlags = ntlm.parse_NTLM_CHALLENGE_MESSAGE(\n            auth_header_value\n        )\n        auth_msg = ntlm.create_NTLM_AUTHENTICATE_MESSAGE(\n            ServerChallenge, self.user, self.domain, self.pw, NegotiateFlags\n        )\n        headers[req_header] = \"NTLM %s\" % auth_msg\n        log.debug(\"Request headers: %s\", headers)\n        conn.request(\"GET\", self.authurl, None, headers)\n        res = conn.getresponse()\n        log.debug(\"Response status: %s %s\", res.status, res.reason)\n        log.debug(\"Response headers: %s\", dict(res.getheaders()))\n        log.debug(\"Response data: %s [...]\", res.read()[:100])\n        if res.status != 200:\n            if res.status == 401:\n                raise Exception(\"Server rejected request: wrong username or password\")\n            raise Exception(\"Wrong server response: %s %s\" % (res.status, res.reason))\n\n        res.fp = None\n        log.debug(\"Connection established\")\n        return conn\n\n    def urlopen(\n        self,\n        method,\n        url,\n        body=None,\n        headers=None,\n        retries=3,\n        redirect=True,\n        assert_same_host=True,\n    ):\n        if headers is None:\n            headers = {}\n        headers[\"Connection\"] = \"Keep-Alive\"\n        return super(NTLMConnectionPool, self).urlopen(\n            method, url, body, headers, retries, redirect, assert_same_host\n        )\n", "path": "src/urllib3/contrib/ntlmpool.py"}], "after_files": [{"content": "\"\"\"\nNTLM authenticating pool, contributed by erikcederstran\n\nIssue #10, see: http://code.google.com/p/urllib3/issues/detail?id=10\n\"\"\"\nfrom __future__ import absolute_import\n\nimport warnings\nfrom logging import getLogger\n\nfrom ntlm import ntlm\n\nfrom .. import HTTPSConnectionPool\nfrom ..packages.six.moves.http_client import HTTPSConnection\n\nwarnings.warn(\n    \"The 'urllib3.contrib.ntlmpool' module is deprecated and will be removed \"\n    \"in urllib3 v2.0 release, urllib3 is not able to support it properly due \"\n    \"to reasons listed in issue: https://github.com/urllib3/urllib3/issues/2282. \"\n    \"If you are a user of this module please comment in the mentioned issue.\",\n    DeprecationWarning,\n)\n\nlog = getLogger(__name__)\n\n\nclass NTLMConnectionPool(HTTPSConnectionPool):\n    \"\"\"\n    Implements an NTLM authentication version of an urllib3 connection pool\n    \"\"\"\n\n    scheme = \"https\"\n\n    def __init__(self, user, pw, authurl, *args, **kwargs):\n        \"\"\"\n        authurl is a random URL on the server that is protected by NTLM.\n        user is the Windows user, probably in the DOMAIN\\\\username format.\n        pw is the password for the user.\n        \"\"\"\n        super(NTLMConnectionPool, self).__init__(*args, **kwargs)\n        self.authurl = authurl\n        self.rawuser = user\n        user_parts = user.split(\"\\\\\", 1)\n        self.domain = user_parts[0].upper()\n        self.user = user_parts[1]\n        self.pw = pw\n\n    def _new_conn(self):\n        # Performs the NTLM handshake that secures the connection. The socket\n        # must be kept open while requests are performed.\n        self.num_connections += 1\n        log.debug(\n            \"Starting NTLM HTTPS connection no. %d: https://%s%s\",\n            self.num_connections,\n            self.host,\n            self.authurl,\n        )\n\n        headers = {\"Connection\": \"Keep-Alive\"}\n        req_header = \"Authorization\"\n        resp_header = \"www-authenticate\"\n\n        conn = HTTPSConnection(host=self.host, port=self.port)\n\n        # Send negotiation message\n        headers[req_header] = \"NTLM %s\" % ntlm.create_NTLM_NEGOTIATE_MESSAGE(\n            self.rawuser\n        )\n        log.debug(\"Request headers: %s\", headers)\n        conn.request(\"GET\", self.authurl, None, headers)\n        res = conn.getresponse()\n        reshdr = dict(res.getheaders())\n        log.debug(\"Response status: %s %s\", res.status, res.reason)\n        log.debug(\"Response headers: %s\", reshdr)\n        log.debug(\"Response data: %s [...]\", res.read(100))\n\n        # Remove the reference to the socket, so that it can not be closed by\n        # the response object (we want to keep the socket open)\n        res.fp = None\n\n        # Server should respond with a challenge message\n        auth_header_values = reshdr[resp_header].split(\", \")\n        auth_header_value = None\n        for s in auth_header_values:\n            if s[:5] == \"NTLM \":\n                auth_header_value = s[5:]\n        if auth_header_value is None:\n            raise Exception(\n                \"Unexpected %s response header: %s\" % (resp_header, reshdr[resp_header])\n            )\n\n        # Send authentication message\n        ServerChallenge, NegotiateFlags = ntlm.parse_NTLM_CHALLENGE_MESSAGE(\n            auth_header_value\n        )\n        auth_msg = ntlm.create_NTLM_AUTHENTICATE_MESSAGE(\n            ServerChallenge, self.user, self.domain, self.pw, NegotiateFlags\n        )\n        headers[req_header] = \"NTLM %s\" % auth_msg\n        log.debug(\"Request headers: %s\", headers)\n        conn.request(\"GET\", self.authurl, None, headers)\n        res = conn.getresponse()\n        log.debug(\"Response status: %s %s\", res.status, res.reason)\n        log.debug(\"Response headers: %s\", dict(res.getheaders()))\n        log.debug(\"Response data: %s [...]\", res.read()[:100])\n        if res.status != 200:\n            if res.status == 401:\n                raise Exception(\"Server rejected request: wrong username or password\")\n            raise Exception(\"Wrong server response: %s %s\" % (res.status, res.reason))\n\n        res.fp = None\n        log.debug(\"Connection established\")\n        return conn\n\n    def urlopen(\n        self,\n        method,\n        url,\n        body=None,\n        headers=None,\n        retries=3,\n        redirect=True,\n        assert_same_host=True,\n    ):\n        if headers is None:\n            headers = {}\n        headers[\"Connection\"] = \"Keep-Alive\"\n        return super(NTLMConnectionPool, self).urlopen(\n            method, url, body, headers, retries, redirect, assert_same_host\n        )\n", "path": "src/urllib3/contrib/ntlmpool.py"}]}