Skip to content

Commit 3eda51f

Browse files
committed
Conditionally import ssl
Saves >=10ms on irrelevant platforms.
1 parent f315671 commit 3eda51f

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

src/pip/_internal/utils/inject_securetransport.py

+27-15
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,30 @@
77
old to handle TLSv1.2.
88
"""
99

10-
try:
11-
import ssl
12-
except ImportError:
13-
pass
14-
else:
15-
import sys
16-
17-
# Checks for OpenSSL 1.0.1 on MacOS
18-
if sys.platform == "darwin" and ssl.OPENSSL_VERSION_NUMBER < 0x1000100f:
19-
try:
20-
from pip._vendor.urllib3.contrib import securetransport
21-
except (ImportError, OSError):
22-
pass
23-
else:
24-
securetransport.inject_into_urllib3()
10+
import sys
11+
12+
13+
def inject_securetransport():
14+
# type: () -> None
15+
# Only relevant on macOS
16+
if sys.platform != "darwin":
17+
return
18+
19+
try:
20+
import ssl
21+
except ImportError:
22+
return
23+
24+
# Checks for OpenSSL 1.0.1
25+
if ssl.OPENSSL_VERSION_NUMBER >= 0x1000100f:
26+
return
27+
28+
try:
29+
from pip._vendor.urllib3.contrib import securetransport
30+
except (ImportError, OSError):
31+
return
32+
33+
securetransport.inject_into_urllib3()
34+
35+
36+
inject_securetransport()

0 commit comments

Comments
 (0)