Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move some initialization out of __init__ #7147

Merged
merged 2 commits into from
Oct 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()