Skip to content

Commit 90aeec9

Browse files
authored
Merge pull request #7147 from chrahunt/refactor/move-requests-init
Move some initialization out of __init__
2 parents 7497203 + 3eda51f commit 90aeec9

File tree

3 files changed

+33
-26
lines changed

3 files changed

+33
-26
lines changed

src/pip/_internal/__init__.py

-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,2 @@
11
#!/usr/bin/env python
2-
from __future__ import absolute_import
3-
4-
import warnings
5-
6-
# We ignore certain warnings from urllib3, since they are not relevant to pip's
7-
# usecases.
8-
from pip._vendor.urllib3.exceptions import InsecureRequestWarning
9-
102
import pip._internal.utils.inject_securetransport # noqa
11-
12-
# Raised when using --trusted-host.
13-
warnings.filterwarnings("ignore", category=InsecureRequestWarning)

src/pip/_internal/network/session.py

+6
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
import os
1313
import platform
1414
import sys
15+
import warnings
1516

1617
from pip._vendor import requests, six, urllib3
1718
from pip._vendor.cachecontrol import CacheControlAdapter
1819
from pip._vendor.requests.adapters import BaseAdapter, HTTPAdapter
1920
from pip._vendor.requests.models import Response
2021
from pip._vendor.requests.structures import CaseInsensitiveDict
2122
from pip._vendor.six.moves.urllib import parse as urllib_parse
23+
from pip._vendor.urllib3.exceptions import InsecureRequestWarning
2224

2325
from pip import __version__
2426
from pip._internal.network.auth import MultiDomainBasicAuth
@@ -48,6 +50,10 @@
4850
logger = logging.getLogger(__name__)
4951

5052

53+
# Ignore warning raised when using --trusted-host.
54+
warnings.filterwarnings("ignore", category=InsecureRequestWarning)
55+
56+
5157
SECURE_ORIGINS = [
5258
# protocol, hostname, port
5359
# Taken from Chrome's list of secure origins (See: http://bit.ly/1qrySKC)

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)