Skip to content

Commit

Permalink
Merge pull request #7147 from chrahunt/refactor/move-requests-init
Browse files Browse the repository at this point in the history
Move some initialization out of __init__
  • Loading branch information
chrahunt authored Oct 8, 2019
2 parents 7497203 + 3eda51f commit 90aeec9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
11 changes: 0 additions & 11 deletions src/pip/_internal/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,2 @@
#!/usr/bin/env python
from __future__ import absolute_import

import warnings

# We ignore certain warnings from urllib3, since they are not relevant to pip's
# usecases.
from pip._vendor.urllib3.exceptions import InsecureRequestWarning

import pip._internal.utils.inject_securetransport # noqa

# Raised when using --trusted-host.
warnings.filterwarnings("ignore", category=InsecureRequestWarning)
6 changes: 6 additions & 0 deletions src/pip/_internal/network/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
import os
import platform
import sys
import warnings

from pip._vendor import requests, six, urllib3
from pip._vendor.cachecontrol import CacheControlAdapter
from pip._vendor.requests.adapters import BaseAdapter, HTTPAdapter
from pip._vendor.requests.models import Response
from pip._vendor.requests.structures import CaseInsensitiveDict
from pip._vendor.six.moves.urllib import parse as urllib_parse
from pip._vendor.urllib3.exceptions import InsecureRequestWarning

from pip import __version__
from pip._internal.network.auth import MultiDomainBasicAuth
Expand Down Expand Up @@ -48,6 +50,10 @@
logger = logging.getLogger(__name__)


# Ignore warning raised when using --trusted-host.
warnings.filterwarnings("ignore", category=InsecureRequestWarning)


SECURE_ORIGINS = [
# protocol, hostname, port
# Taken from Chrome's list of secure origins (See: http://bit.ly/1qrySKC)
Expand Down
42 changes: 27 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,30 @@
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():
# type: () -> None
# 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 90aeec9

Please sign in to comment.