Skip to content
Myr

_compat.py

This file

Path

httpx/_compat.py

43 lines · 1.6 KiB · Python

Last changed by

Enable no_implicit_reexport (#2475)Martijn Pietersbefore adoption57aa5b0

History of this file

Take it

1"""2The _compat module is used for code which requires branching between different3Python environments. It is excluded from the code coverage checks.4"""5import ssl6import sys78# Brotli support is optional9# The C bindings in `brotli` are recommended for CPython.10# The CFFI bindings in `brotlicffi` are recommended for PyPy and everything else.11try:12    import brotlicffi as brotli13except ImportError:  # pragma: no cover14    try:15        import brotli16    except ImportError:17        brotli = None1819if sys.version_info >= (3, 10) or (20    sys.version_info >= (3, 7) and ssl.OPENSSL_VERSION_INFO >= (1, 1, 0, 7)21):2223    def set_minimum_tls_version_1_2(context: ssl.SSLContext) -> None:24        # The OP_NO_SSL* and OP_NO_TLS* become deprecated in favor of25        # 'SSLContext.minimum_version' from Python 3.7 onwards, however26        # this attribute is not available unless the ssl module is compiled27        # with OpenSSL 1.1.0g or newer.28        # https://docs.python.org/3.10/library/ssl.html#ssl.SSLContext.minimum_version29        # https://docs.python.org/3.7/library/ssl.html#ssl.SSLContext.minimum_version30        context.minimum_version = ssl.TLSVersion.TLSv1_23132else:3334    def set_minimum_tls_version_1_2(context: ssl.SSLContext) -> None:35        # If 'minimum_version' isn't available, we configure these options with36        # the older deprecated variants.37        context.options |= ssl.OP_NO_SSLv238        context.options |= ssl.OP_NO_SSLv339        context.options |= ssl.OP_NO_TLSv140        context.options |= ssl.OP_NO_TLSv1_1414243__all__ = ["brotli", "set_minimum_tls_version_1_2"]