Skip to content

Commit 0176fa1

Browse files
committed
Update parse_host and tests
Signed-off-by: Joffrey F <[email protected]>
1 parent d922713 commit 0176fa1

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

docker/client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import json
1616
import struct
17-
import sys
1817

1918
import requests
2019
import requests.exceptions
@@ -63,7 +62,9 @@ def __init__(self, base_url=None, version=None,
6362

6463
self._auth_configs = auth.load_config()
6564

66-
base_url = utils.parse_host(base_url, sys.platform, tls=bool(tls))
65+
base_url = utils.parse_host(
66+
base_url, constants.IS_WINDOWS_PLATFORM, tls=bool(tls)
67+
)
6768
if base_url.startswith('http+unix://'):
6869
self._custom_adapter = UnixAdapter(base_url, timeout)
6970
self.mount('http+docker://', self._custom_adapter)

docker/utils/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,13 @@ def parse_repository_tag(repo_name):
383383
# fd:// protocol unsupported (for obvious reasons)
384384
# Added support for http and https
385385
# Protocol translation: tcp -> http, unix -> http+unix
386-
def parse_host(addr, platform=None, tls=False):
386+
def parse_host(addr, is_win32=False, tls=False):
387387
proto = "http+unix"
388388
host = DEFAULT_HTTP_HOST
389389
port = None
390390
path = ''
391391

392-
if not addr and platform == 'win32':
392+
if not addr and is_win32:
393393
addr = '{0}:{1}'.format(DEFAULT_HTTP_HOST, 2375)
394394

395395
if not addr or addr.strip() == 'unix://':

tests/unit/utils_test.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ def test_parse_host(self):
388388
'somehost.net:80/service/swarm': (
389389
'http://somehost.net:80/service/swarm'
390390
),
391+
'npipe:////./pipe/docker_engine': 'npipe:////./pipe/docker_engine',
391392
}
392393

393394
for host in invalid_hosts:
@@ -402,10 +403,8 @@ def test_parse_host_empty_value(self):
402403
tcp_port = 'http://127.0.0.1:2375'
403404

404405
for val in [None, '']:
405-
for platform in ['darwin', 'linux2', None]:
406-
assert parse_host(val, platform) == unix_socket
407-
408-
assert parse_host(val, 'win32') == tcp_port
406+
assert parse_host(val, is_win32=False) == unix_socket
407+
assert parse_host(val, is_win32=True) == tcp_port
409408

410409
def test_parse_host_tls(self):
411410
host_value = 'myhost.docker.net:3348'

0 commit comments

Comments
 (0)