Merge pull request #6710 from nateprewitt/api_rename
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Move _get_connection to get_connection_with_tls_context
authored by Nate Prewitt · committed by GitHub · parents 970e8ce, 92075b3 · Browse files · 1 file·+31 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+31 added−6 removed
- other:+31 added−6 removed
Provenance
- Commit
c98e4d1- Tree
255454d- Author
Nate Prewitt <nate.prewitt@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
970e8ce- Parent 2
92075b3
1 file changed+31 added−6 removed
modified:src/requests/adapters.py+31 added-6 removed
7 unmodified lines8 9 import os.path10 import socket # noqa: F40111 import typing12+import warnings13 14 from urllib3.exceptions import ClosedPoolError, ConnectTimeoutError15 from urllib3.exceptions import HTTPError as _HTTPError16 from urllib3.exceptions import InvalidHeader as _InvalidHeader357 unmodified lines374 response.connection = self375 376 return response377 377- def _get_connection(self, request, verify, proxies=None, cert=None):378- # Replace the existing get_connection without breaking things and379- # ensure that TLS settings are considered when we interact with380- # urllib3 HTTP Pools378+ def get_connection_with_tls_context(self, request, verify, proxies=None, cert=None):379+ """Returns a urllib3 connection for the given request and TLS settings.380+ This should not be called from user code, and is only exposed for use381+ when subclassing the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.382+383+ :param request: The :class:`PreparedRequest <PreparedRequest>` object384+ to be sent over the connection.385+ :param verify: Either a boolean, in which case it controls whether386+ we verify the server's TLS certificate, or a string, in which case it387+ must be a path to a CA bundle to use.388+ :param proxies: (optional) The proxies dictionary to apply to the request.389+ :param cert: (optional) Any user-provided SSL certificate to be trusted.390+ :rtype: urllib3.ConnectionPool391+ """392 proxy = select_proxy(request.url, proxies)393 try:394 host_params, pool_kwargs = _urllib3_request_context(request, verify, cert)395 except ValueError as e:18 unmodified lines414 415 return conn416 417 def get_connection(self, url, proxies=None):418+ """DEPRECATED: Users should move to `get_connection_with_tls_context`419+ for all subclasses of HTTPAdapter using Requests>=2.32.2.420+407- """Returns a urllib3 connection for the given URL. This should not be421+ Returns a urllib3 connection for the given URL. This should not be422 called from user code, and is only exposed for use when subclassing the423 :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.424 425 :param url: The URL to connect to.426 :param proxies: (optional) A Requests-style dictionary of proxies used on this request.427 :rtype: urllib3.ConnectionPool428 """429+ warnings.warn(430+ (431+ "`get_connection` has been deprecated in favor of "432+ "`get_connection_with_tls_context`. Custom HTTPAdapter subclasses "433+ "will need to migrate for Requests>=2.32.2. Please see "434+ "https://github.com/psf/requests/pull/6710 for more details."435+ ),436+ DeprecationWarning,437+ )438 proxy = select_proxy(url, proxies)439 440 if proxy:441 proxy = prepend_scheme_if_needed(proxy, "http")109 unmodified lines551 :rtype: requests.Response552 """553 554 try:532- conn = self._get_connection(request, verify, proxies=proxies, cert=cert)555+ conn = self.get_connection_with_tls_context(556+ request, verify, proxies=proxies, cert=cert557+ )558 except LocationValueError as e:559 raise InvalidURL(e, request=request)560 561 self.cert_verify(conn, request.url, verify, cert)80 unmodified lines