From 0176fa171f9bb5a4453ceb2abe1cdff1696bee59 Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Thu, 2 Jun 2016 18:21:29 -0700 Subject: [PATCH] Update parse_host and tests Signed-off-by: Joffrey F --- docker/client.py | 5 +++-- docker/utils/utils.py | 4 ++-- tests/unit/utils_test.py | 7 +++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docker/client.py b/docker/client.py index 2da355a5..b96a78ce 100644 --- a/docker/client.py +++ b/docker/client.py @@ -14,7 +14,6 @@ import json import struct -import sys import requests import requests.exceptions @@ -63,7 +62,9 @@ class Client( self._auth_configs = auth.load_config() - base_url = utils.parse_host(base_url, sys.platform, tls=bool(tls)) + base_url = utils.parse_host( + base_url, constants.IS_WINDOWS_PLATFORM, tls=bool(tls) + ) if base_url.startswith('http+unix://'): self._custom_adapter = UnixAdapter(base_url, timeout) self.mount('http+docker://', self._custom_adapter) diff --git a/docker/utils/utils.py b/docker/utils/utils.py index ab0fdf94..4a56829d 100644 --- a/docker/utils/utils.py +++ b/docker/utils/utils.py @@ -383,13 +383,13 @@ def parse_repository_tag(repo_name): # fd:// protocol unsupported (for obvious reasons) # Added support for http and https # Protocol translation: tcp -> http, unix -> http+unix -def parse_host(addr, platform=None, tls=False): +def parse_host(addr, is_win32=False, tls=False): proto = "http+unix" host = DEFAULT_HTTP_HOST port = None path = '' - if not addr and platform == 'win32': + if not addr and is_win32: addr = '{0}:{1}'.format(DEFAULT_HTTP_HOST, 2375) if not addr or addr.strip() == 'unix://': diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py index ef927d36..ae821fd3 100644 --- a/tests/unit/utils_test.py +++ b/tests/unit/utils_test.py @@ -388,6 +388,7 @@ class ParseHostTest(base.BaseTestCase): 'somehost.net:80/service/swarm': ( 'http://somehost.net:80/service/swarm' ), + 'npipe:////./pipe/docker_engine': 'npipe:////./pipe/docker_engine', } for host in invalid_hosts: @@ -402,10 +403,8 @@ class ParseHostTest(base.BaseTestCase): tcp_port = 'http://127.0.0.1:2375' for val in [None, '']: - for platform in ['darwin', 'linux2', None]: - assert parse_host(val, platform) == unix_socket - - assert parse_host(val, 'win32') == tcp_port + assert parse_host(val, is_win32=False) == unix_socket + assert parse_host(val, is_win32=True) == tcp_port def test_parse_host_tls(self): host_value = 'myhost.docker.net:3348'