From fed1877433c68caedcbc47832a3becef9649a448 Mon Sep 17 00:00:00 2001 From: Sylvain Hellegouarch Date: Tue, 6 Aug 2019 10:57:45 +0200 Subject: [PATCH] Do not look for a port in a Unix socket domain path Contributes to MagicStack/asyncpg#419 Signed-off-by: Sylvain Hellegouarch --- asyncpg/connect_utils.py | 8 ++++++-- tests/test_connect.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/asyncpg/connect_utils.py b/asyncpg/connect_utils.py index 3b5b725e..c3a9670c 100644 --- a/asyncpg/connect_utils.py +++ b/asyncpg/connect_utils.py @@ -179,9 +179,13 @@ def _parse_hostlist(hostlist, port): port = _validate_port_spec(hostspecs, port) for i, hostspec in enumerate(hostspecs): - addr, _, hostspec_port = hostspec.partition(':') - hosts.append(addr) + if not hostspec.startswith('/'): + addr, _, hostspec_port = hostspec.partition(':') + else: + addr = hostspec + hostspec_port = '' + hosts.append(addr) if not port: if hostspec_port: hostlist_ports.append(int(hostspec_port)) diff --git a/tests/test_connect.py b/tests/test_connect.py index 145a5d26..abb30647 100644 --- a/tests/test_connect.py +++ b/tests/test_connect.py @@ -475,6 +475,36 @@ class TestConnectParams(tb.TestCase): } ) }, + { + 'dsn': 'postgres:///db?host=/cloudsql/' + 'project:region:instance-name&user=spam', + 'result': ( + [os.path.join( + '/cloudsql/project:region:instance-name', + '.s.PGSQL.5432' + )], { + 'user': 'spam', + 'database': 'db' + } + ) + }, + { + 'dsn': 'postgres:///db?host=127.0.0.1:5432,/cloudsql/' + 'project:region:instance-name,localhost:5433&user=spam', + 'result': ( + [ + ('127.0.0.1', 5432), + os.path.join( + '/cloudsql/project:region:instance-name', + '.s.PGSQL.5432' + ), + ('localhost', 5433) + ], { + 'user': 'spam', + 'database': 'db' + } + ) + }, ] @contextlib.contextmanager