Skip to content
Myr

use context.minimum_version in py3.7+ where available (#1714)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Thomas Grainger · committed by GitHub · parent 3d192ae · Browse files · 1 file+11 added−3 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+11 added−3 removed

  • other:+11 added−3 removed

1 file+11 added−3 removed

modified:httpx/_compat.py+11 added-3 removed
12 unmodified lines
13 from async_generator import asynccontextmanager # type: ignore # noqa141516def set_minimum_tls_version_1_2(context: ssl.SSLContext) -> None:17 if sys.version_info >= (3, 10):17 if sys.version_info >= (3, 10) or (18 sys.version_info >= (3, 7) and ssl.OPENSSL_VERSION_INFO >= (1, 1, 0, 7)19 ):20 # The OP_NO_SSL* and OP_NO_TLS* become deprecated in favor of21 # 'SSLContext.minimum_version' from Python 3.7 onwards, however22 # this attribute is not available unless the ssl module is compiled23 # with OpenSSL 1.1.0g or newer.24 # https://docs.python.org/3.10/library/ssl.html#ssl.SSLContext.minimum_version25 # https://docs.python.org/3.7/library/ssl.html#ssl.SSLContext.minimum_version26 context.minimum_version = ssl.TLSVersion.TLSv1_227 else:20 # These become deprecated in favor of 'context.minimum_version'21 # from Python 3.10 onwards.28 # If 'minimum_version' isn't available, we configure these options with29 # the older deprecated variants.30 context.options |= ssl.OP_NO_SSLv231 context.options |= ssl.OP_NO_SSLv332 context.options |= ssl.OP_NO_TLSv133 context.options |= ssl.OP_NO_TLSv1_1