276aa79bb81356cdca73af0a5851b448707784a4
[SubU] /
1 """A helper module that injects SecureTransport, on import.
2
3 The import should be done as early as possible, to ensure all requests and
4 sessions (or whatever) are created after injecting SecureTransport.
5
6 Note that we only do the injection on macOS, when the linked OpenSSL is too
7 old to handle TLSv1.2.
8 """
9
10 import sys
11
12
13 def inject_securetransport() -> None:
14     # Only relevant on macOS
15     if sys.platform != "darwin":
16         return
17
18     try:
19         import ssl
20     except ImportError:
21         return
22
23     # Checks for OpenSSL 1.0.1
24     if ssl.OPENSSL_VERSION_NUMBER >= 0x1000100F:
25         return
26
27     try:
28         from pip._vendor.urllib3.contrib import securetransport
29     except (ImportError, OSError):
30         return
31
32     securetransport.inject_into_urllib3()
33
34
35 inject_securetransport()