Skip to content

Commit b1a723b

Browse files
author
CommanderKeynes
committed
Cosolidate if statements
1 parent 1f87efd commit b1a723b

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

asyncpg/connect_utils.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
284284

285285
if dsn:
286286
parsed = urllib.parse.urlparse(dsn)
287+
288+
query = None
287289
if parsed.query:
288290
query = urllib.parse.parse_qs(parsed.query, strict_parsing=True)
289291
for key, val in query.items():
@@ -306,7 +308,6 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
306308
connection_service_file = pathlib.Path(connection_service_file)
307309

308310
if connection_service_file is not None and service is not None:
309-
# TODO Open and parse connection service file
310311
pg_service = configparser.ConfigParser()
311312
pg_service.read(connection_service_file)
312313
if service in pg_service.sections():
@@ -396,8 +397,6 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
396397
if gsslib is None:
397398
gsslib = val
398399

399-
if dsn:
400-
parsed = urllib.parse.urlparse(dsn)
401400

402401
if parsed.scheme not in {'postgresql', 'postgres'}:
403402
raise exceptions.ClientConfigurationError(
@@ -433,11 +432,7 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
433432
if password is None and dsn_password:
434433
password = urllib.parse.unquote(dsn_password)
435434

436-
if parsed.query:
437-
query = urllib.parse.parse_qs(parsed.query, strict_parsing=True)
438-
for key, val in query.items():
439-
if isinstance(val, list):
440-
query[key] = val[-1]
435+
if query:
441436

442437
if 'port' in query:
443438
val = query.pop('port')

0 commit comments

Comments
 (0)