Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/httpx/_compat.py: 54%

13 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 07:19 +0000

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 

7 

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 

18 

19if sys.version_info >= (3, 10) or ( 

20 sys.version_info >= (3, 7) and ssl.OPENSSL_VERSION_INFO >= (1, 1, 0, 7) 

21): 

22 

23 def set_minimum_tls_version_1_2(context: ssl.SSLContext) -> None: 

24 # The OP_NO_SSL* and OP_NO_TLS* become deprecated in favor of 

25 # 'SSLContext.minimum_version' from Python 3.7 onwards, however 

26 # this attribute is not available unless the ssl module is compiled 

27 # with OpenSSL 1.1.0g or newer. 

28 # https://docs.python.org/3.10/library/ssl.html#ssl.SSLContext.minimum_version 

29 # https://docs.python.org/3.7/library/ssl.html#ssl.SSLContext.minimum_version 

30 context.minimum_version = ssl.TLSVersion.TLSv1_2 

31 

32else: 

33 

34 def set_minimum_tls_version_1_2(context: ssl.SSLContext) -> None: 

35 # If 'minimum_version' isn't available, we configure these options with 

36 # the older deprecated variants. 

37 context.options |= ssl.OP_NO_SSLv2 

38 context.options |= ssl.OP_NO_SSLv3 

39 context.options |= ssl.OP_NO_TLSv1 

40 context.options |= ssl.OP_NO_TLSv1_1 

41 

42 

43__all__ = ["brotli", "set_minimum_tls_version_1_2"]