Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/httpx/_compat.py: 54%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2The _compat module is used for code which requires branching between different
3Python environments. It is excluded from the code coverage checks.
4"""
5import ssl
6import sys
8# Brotli support is optional
9# 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 brotli
13except ImportError: # pragma: no cover
14 try:
15 import brotli
16 except ImportError:
17 brotli = None
19if sys.version_info >= (3, 10) or ssl.OPENSSL_VERSION_INFO >= (1, 1, 0, 7):
21 def set_minimum_tls_version_1_2(context: ssl.SSLContext) -> None:
22 # The OP_NO_SSL* and OP_NO_TLS* become deprecated in favor of
23 # 'SSLContext.minimum_version' from Python 3.7 onwards, however
24 # this attribute is not available unless the ssl module is compiled
25 # with OpenSSL 1.1.0g or newer.
26 # https://docs.python.org/3.10/library/ssl.html#ssl.SSLContext.minimum_version
27 # https://docs.python.org/3.7/library/ssl.html#ssl.SSLContext.minimum_version
28 context.minimum_version = ssl.TLSVersion.TLSv1_2
30else:
32 def set_minimum_tls_version_1_2(context: ssl.SSLContext) -> None:
33 # If 'minimum_version' isn't available, we configure these options with
34 # the older deprecated variants.
35 context.options |= ssl.OP_NO_SSLv2
36 context.options |= ssl.OP_NO_SSLv3
37 context.options |= ssl.OP_NO_TLSv1
38 context.options |= ssl.OP_NO_TLSv1_1
41__all__ = ["brotli", "set_minimum_tls_version_1_2"]