Skip to content

Commit

Permalink
Conditionally import ssl
Browse files Browse the repository at this point in the history
Saves >=10ms on irrelevant platforms.
  • Loading branch information
chrahunt committed Oct 8, 2019
1 parent f315671 commit 02c92da
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions src/pip/_internal/utils/inject_securetransport.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,29 @@
old to handle TLSv1.2.
"""

try:
import ssl
except ImportError:
pass
else:
import sys

# Checks for OpenSSL 1.0.1 on MacOS
if sys.platform == "darwin" and ssl.OPENSSL_VERSION_NUMBER < 0x1000100f:
try:
from pip._vendor.urllib3.contrib import securetransport
except (ImportError, OSError):
pass
else:
securetransport.inject_into_urllib3()
import sys


def inject_securetransport():
# Only relevant on macOS
if sys.platform != "darwin":
return

try:
import ssl
except ImportError:
return

# Checks for OpenSSL 1.0.1
if ssl.OPENSSL_VERSION_NUMBER >= 0x1000100f:
return

try:
from pip._vendor.urllib3.contrib import securetransport
except (ImportError, OSError):
return

securetransport.inject_into_urllib3()


inject_securetransport()

0 comments on commit 02c92da

Please sign in to comment.