From ce218c340d169e51ea7c2b46f1ad9695f0322bbe Mon Sep 17 00:00:00 2001 From: Chris Jerdonek Date: Tue, 20 Aug 2019 12:58:31 -0700 Subject: [PATCH] Rename the insecure_hosts argument to trusted_hosts. --- src/pip/_internal/cli/req_command.py | 2 +- src/pip/_internal/download.py | 6 +++--- tests/unit/test_download.py | 16 ++++++++-------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/pip/_internal/cli/req_command.py b/src/pip/_internal/cli/req_command.py index bc994738812..361182abc07 100644 --- a/src/pip/_internal/cli/req_command.py +++ b/src/pip/_internal/cli/req_command.py @@ -62,7 +62,7 @@ def _build_session(self, options, retries=None, timeout=None): if options.cache_dir else None ), retries=retries if retries is not None else options.retries, - insecure_hosts=options.trusted_hosts, + trusted_hosts=options.trusted_hosts, index_urls=self._get_index_urls(options), ) diff --git a/src/pip/_internal/download.py b/src/pip/_internal/download.py index 08522788ca2..670cb5cc4a4 100644 --- a/src/pip/_internal/download.py +++ b/src/pip/_internal/download.py @@ -573,12 +573,12 @@ class PipSession(requests.Session): def __init__(self, *args, **kwargs): """ - :param insecure_hosts: Domains not to emit warnings for when not using + :param trusted_hosts: Domains not to emit warnings for when not using HTTPS. """ retries = kwargs.pop("retries", 0) cache = kwargs.pop("cache", None) - insecure_hosts = kwargs.pop("insecure_hosts", []) # type: List[str] + trusted_hosts = kwargs.pop("trusted_hosts", []) # type: List[str] index_urls = kwargs.pop("index_urls", None) super(PipSession, self).__init__(*args, **kwargs) @@ -652,7 +652,7 @@ def __init__(self, *args, **kwargs): # Enable file:// urls self.mount("file://", LocalFSAdapter()) - for host in insecure_hosts: + for host in trusted_hosts: self.add_trusted_host(host, suppress_logging=True) def add_trusted_host(self, host, source=None, suppress_logging=False): diff --git a/tests/unit/test_download.py b/tests/unit/test_download.py index c75871e39fa..42265f327ea 100644 --- a/tests/unit/test_download.py +++ b/tests/unit/test_download.py @@ -618,7 +618,7 @@ def test_http_cache_is_not_enabled(self, tmpdir): def test_insecure_host_adapter(self, tmpdir): session = PipSession( cache=tmpdir.joinpath("test-cache"), - insecure_hosts=["example.com"], + trusted_hosts=["example.com"], ) assert "https://example.com/" in session.adapters @@ -630,7 +630,7 @@ def test_insecure_host_adapter(self, tmpdir): def test_add_trusted_host(self): # Leave a gap to test how the ordering is affected. trusted_hosts = ['host1', 'host3'] - session = PipSession(insecure_hosts=trusted_hosts) + session = PipSession(trusted_hosts=trusted_hosts) insecure_adapter = session._insecure_adapter prefix2 = 'https://host2/' prefix3 = 'https://host3/' @@ -658,7 +658,7 @@ def test_add_trusted_host__logging(self, caplog): Test logging when add_trusted_host() is called. """ trusted_hosts = ['host0', 'host1'] - session = PipSession(insecure_hosts=trusted_hosts) + session = PipSession(trusted_hosts=trusted_hosts) with caplog.at_level(logging.INFO): # Test adding an existing host. session.add_trusted_host('host1', source='somewhere') @@ -677,7 +677,7 @@ def test_add_trusted_host__logging(self, caplog): def test_iter_secure_origins(self): trusted_hosts = ['host1', 'host2'] - session = PipSession(insecure_hosts=trusted_hosts) + session = PipSession(trusted_hosts=trusted_hosts) actual = list(session.iter_secure_origins()) assert len(actual) == 8 @@ -688,11 +688,11 @@ def test_iter_secure_origins(self): ('*', 'host2', '*'), ] - def test_iter_secure_origins__insecure_hosts_empty(self): + def test_iter_secure_origins__trusted_hosts_empty(self): """ - Test iter_secure_origins() after passing insecure_hosts=[]. + Test iter_secure_origins() after passing trusted_hosts=[]. """ - session = PipSession(insecure_hosts=[]) + session = PipSession(trusted_hosts=[]) actual = list(session.iter_secure_origins()) assert len(actual) == 6 @@ -723,7 +723,7 @@ def __init__(self): def warning(self, *args, **kwargs): self.called = True - session = PipSession(insecure_hosts=trusted) + session = PipSession(trusted_hosts=trusted) actual = session.is_secure_origin(location) assert actual == expected