]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
check sys.version_info and ssl.OPENSSL_VERSION_INFO once (#1720)
authorThomas Grainger <tagrain@gmail.com>
Mon, 28 Jun 2021 12:20:32 +0000 (13:20 +0100)
committerGitHub <noreply@github.com>
Mon, 28 Jun 2021 12:20:32 +0000 (13:20 +0100)
httpx/_compat.py

index 0eeeef1988a4899e31ac2d198975b0a31a174ce7..a499322f97a1e3ca43eea078c46cff76b248ccfd 100644 (file)
@@ -12,11 +12,11 @@ try:
 except ImportError:
     from async_generator import asynccontextmanager  # type: ignore # noqa
 
+if sys.version_info >= (3, 10) or (
+    sys.version_info >= (3, 7) and ssl.OPENSSL_VERSION_INFO >= (1, 1, 0, 7)
+):
 
-def set_minimum_tls_version_1_2(context: ssl.SSLContext) -> None:
-    if sys.version_info >= (3, 10) or (
-        sys.version_info >= (3, 7) and ssl.OPENSSL_VERSION_INFO >= (1, 1, 0, 7)
-    ):
+    def set_minimum_tls_version_1_2(context: ssl.SSLContext) -> None:
         # The OP_NO_SSL* and OP_NO_TLS* become deprecated in favor of
         # 'SSLContext.minimum_version' from Python 3.7 onwards, however
         # this attribute is not available unless the ssl module is compiled
@@ -24,7 +24,11 @@ def set_minimum_tls_version_1_2(context: ssl.SSLContext) -> None:
         # https://docs.python.org/3.10/library/ssl.html#ssl.SSLContext.minimum_version
         # https://docs.python.org/3.7/library/ssl.html#ssl.SSLContext.minimum_version
         context.minimum_version = ssl.TLSVersion.TLSv1_2
-    else:
+
+
+else:
+
+    def set_minimum_tls_version_1_2(context: ssl.SSLContext) -> None:
         # If 'minimum_version' isn't available, we configure these options with
         # the older deprecated variants.
         context.options |= ssl.OP_NO_SSLv2