Skip to content

Commit b773912

Browse files
Lawouachelprans
authored andcommitted
Do not look for a port in a Unix socket domain path
Contributes to #419 Signed-off-by: Sylvain Hellegouarch <[email protected]>
1 parent ae5a89d commit b773912

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

Diff for: asyncpg/connect_utils.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,13 @@ def _parse_hostlist(hostlist, port):
179179
port = _validate_port_spec(hostspecs, port)
180180

181181
for i, hostspec in enumerate(hostspecs):
182-
addr, _, hostspec_port = hostspec.partition(':')
183-
hosts.append(addr)
182+
if not hostspec.startswith('/'):
183+
addr, _, hostspec_port = hostspec.partition(':')
184+
else:
185+
addr = hostspec
186+
hostspec_port = ''
184187

188+
hosts.append(addr)
185189
if not port:
186190
if hostspec_port:
187191
hostlist_ports.append(int(hostspec_port))

Diff for: tests/test_connect.py

+30
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,36 @@ class TestConnectParams(tb.TestCase):
475475
}
476476
)
477477
},
478+
{
479+
'dsn': 'postgres:///db?host=/cloudsql/'
480+
'project:region:instance-name&user=spam',
481+
'result': (
482+
[os.path.join(
483+
'/cloudsql/project:region:instance-name',
484+
'.s.PGSQL.5432'
485+
)], {
486+
'user': 'spam',
487+
'database': 'db'
488+
}
489+
)
490+
},
491+
{
492+
'dsn': 'postgres:///db?host=127.0.0.1:5432,/cloudsql/'
493+
'project:region:instance-name,localhost:5433&user=spam',
494+
'result': (
495+
[
496+
('127.0.0.1', 5432),
497+
os.path.join(
498+
'/cloudsql/project:region:instance-name',
499+
'.s.PGSQL.5432'
500+
),
501+
('localhost', 5433)
502+
], {
503+
'user': 'spam',
504+
'database': 'db'
505+
}
506+
)
507+
},
478508
]
479509

480510
@contextlib.contextmanager

0 commit comments

Comments
 (0)