Skip to content

Commit 1c337cd

Browse files
author
CommanderKeynes
committed
Fix formatting
1 parent b1a723b commit 1c337cd

File tree

2 files changed

+125
-125
lines changed

2 files changed

+125
-125
lines changed

asyncpg/connect_utils.py

+87-88
Original file line numberDiff line numberDiff line change
@@ -305,98 +305,97 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
305305
else:
306306
connection_service_file = None
307307
else:
308-
connection_service_file = pathlib.Path(connection_service_file)
308+
connection_service_file = pathlib.Path(connection_service_file)
309309

310310
if connection_service_file is not None and service is not None:
311311
pg_service = configparser.ConfigParser()
312312
pg_service.read(connection_service_file)
313313
if service in pg_service.sections():
314-
service_params = pg_service[service]
315-
if 'port' in service_params:
316-
val = service_params.pop('port')
317-
if not port and val:
318-
port = [int(p) for p in val.split(',')]
319-
320-
if 'host' in service_params:
321-
val = service_params.pop('host')
322-
if not host and val:
323-
host, port = _parse_hostlist(val, port)
324-
325-
if 'dbname' in service_params:
326-
val = service_params.pop('dbname')
327-
if database is None:
328-
database = val
329-
330-
if 'database' in service_params:
331-
val = service_params.pop('database')
332-
if database is None:
333-
database = val
334-
335-
if 'user' in service_params:
336-
val = service_params.pop('user')
337-
if user is None:
338-
user = val
339-
340-
if 'password' in service_params:
341-
val = service_params.pop('password')
342-
if password is None:
343-
password = val
344-
345-
if 'passfile' in service_params:
346-
val = service_params.pop('passfile')
347-
if passfile is None:
348-
passfile = val
349-
350-
if 'sslmode' in service_params:
351-
val = service_params.pop('sslmode')
352-
if ssl is None:
353-
ssl = val
354-
355-
if 'sslcert' in service_params:
356-
sslcert = service_params.pop('sslcert')
357-
358-
if 'sslkey' in service_params:
359-
sslkey = service_params.pop('sslkey')
360-
361-
if 'sslrootcert' in service_params:
362-
sslrootcert = service_params.pop('sslrootcert')
363-
364-
if 'sslnegotiation' in service_params:
365-
sslnegotiation = service_params.pop('sslnegotiation')
366-
367-
if 'sslcrl' in service_params:
368-
sslcrl = service_params.pop('sslcrl')
369-
370-
if 'sslpassword' in service_params:
371-
sslpassword = service_params.pop('sslpassword')
372-
373-
if 'ssl_min_protocol_version' in service_params:
374-
ssl_min_protocol_version = service_params.pop(
375-
'ssl_min_protocol_version'
376-
)
377-
378-
if 'ssl_max_protocol_version' in service_params:
379-
ssl_max_protocol_version = service_params.pop(
380-
'ssl_max_protocol_version'
381-
)
382-
383-
if 'target_session_attrs' in service_params:
384-
dsn_target_session_attrs = service_params.pop(
385-
'target_session_attrs'
386-
)
387-
if target_session_attrs is None:
388-
target_session_attrs = dsn_target_session_attrs
389-
390-
if 'krbsrvname' in service_params:
391-
val = service_params.pop('krbsrvname')
392-
if krbsrvname is None:
393-
krbsrvname = val
394-
395-
if 'gsslib' in service_params:
396-
val = service_params.pop('gsslib')
397-
if gsslib is None:
398-
gsslib = val
314+
service_params = pg_service[service]
315+
if 'port' in service_params:
316+
val = service_params.pop('port')
317+
if not port and val:
318+
port = [int(p) for p in val.split(',')]
319+
320+
if 'host' in service_params:
321+
val = service_params.pop('host')
322+
if not host and val:
323+
host, port = _parse_hostlist(val, port)
324+
325+
if 'dbname' in service_params:
326+
val = service_params.pop('dbname')
327+
if database is None:
328+
database = val
329+
330+
if 'database' in service_params:
331+
val = service_params.pop('database')
332+
if database is None:
333+
database = val
334+
335+
if 'user' in service_params:
336+
val = service_params.pop('user')
337+
if user is None:
338+
user = val
339+
340+
if 'password' in service_params:
341+
val = service_params.pop('password')
342+
if password is None:
343+
password = val
344+
345+
if 'passfile' in service_params:
346+
val = service_params.pop('passfile')
347+
if passfile is None:
348+
passfile = val
349+
350+
if 'sslmode' in service_params:
351+
val = service_params.pop('sslmode')
352+
if ssl is None:
353+
ssl = val
354+
355+
if 'sslcert' in service_params:
356+
sslcert = service_params.pop('sslcert')
357+
358+
if 'sslkey' in service_params:
359+
sslkey = service_params.pop('sslkey')
360+
361+
if 'sslrootcert' in service_params:
362+
sslrootcert = service_params.pop('sslrootcert')
363+
364+
if 'sslnegotiation' in service_params:
365+
sslnegotiation = service_params.pop('sslnegotiation')
366+
367+
if 'sslcrl' in service_params:
368+
sslcrl = service_params.pop('sslcrl')
369+
370+
if 'sslpassword' in service_params:
371+
sslpassword = service_params.pop('sslpassword')
372+
373+
if 'ssl_min_protocol_version' in service_params:
374+
ssl_min_protocol_version = service_params.pop(
375+
'ssl_min_protocol_version'
376+
)
377+
378+
if 'ssl_max_protocol_version' in service_params:
379+
ssl_max_protocol_version = service_params.pop(
380+
'ssl_max_protocol_version'
381+
)
399382

383+
if 'target_session_attrs' in service_params:
384+
dsn_target_session_attrs = service_params.pop(
385+
'target_session_attrs'
386+
)
387+
if target_session_attrs is None:
388+
target_session_attrs = dsn_target_session_attrs
389+
390+
if 'krbsrvname' in service_params:
391+
val = service_params.pop('krbsrvname')
392+
if krbsrvname is None:
393+
krbsrvname = val
394+
395+
if 'gsslib' in service_params:
396+
val = service_params.pop('gsslib')
397+
if gsslib is None:
398+
gsslib = val
400399

401400
if parsed.scheme not in {'postgresql', 'postgres'}:
402401
raise exceptions.ClientConfigurationError(
@@ -609,7 +608,6 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
609608
database=database, user=user,
610609
passfile=passfile)
611610

612-
613611
addrs = []
614612
have_tcp_addrs = False
615613
for h, p in zip(host, port):
@@ -843,7 +841,8 @@ def _parse_connect_arguments(*, dsn, host, port, user, password, passfile,
843841
max_cached_statement_lifetime,
844842
max_cacheable_statement_size,
845843
ssl, direct_tls, server_settings,
846-
target_session_attrs, krbsrvname, gsslib, service):
844+
target_session_attrs, krbsrvname, gsslib,
845+
service):
847846
local_vars = locals()
848847
for var_name in {'max_cacheable_statement_size',
849848
'max_cached_statement_lifetime',

tests/test_connect.py

+38-37
Original file line numberDiff line numberDiff line change
@@ -1239,8 +1239,9 @@ def test_connect_params(self):
12391239
self.run_testcase(testcase)
12401240

12411241
def test_connect_connection_service_file(self):
1242-
connection_service_file = tempfile.NamedTemporaryFile('w+t', delete=False)
1243-
connection_service_file.write(textwrap.dedent(f'''
1242+
connection_service_file = tempfile.NamedTemporaryFile(
1243+
'w+t', delete=False)
1244+
connection_service_file.write(textwrap.dedent('''
12441245
[test_service_dbname]
12451246
port=5433
12461247
host=somehost
@@ -1264,41 +1265,41 @@ def test_connect_connection_service_file(self):
12641265
connection_service_file.close()
12651266
os.chmod(connection_service_file.name, stat.S_IWUSR | stat.S_IRUSR)
12661267
try:
1267-
# passfile path in env
1268-
self.run_testcase({
1269-
'dsn': 'postgresql://?service=test_service_dbname',
1270-
'env': {
1271-
'PGSERVICEFILE': connection_service_file.name
1272-
},
1273-
'result': (
1274-
[('somehost', 5433)],
1275-
{
1276-
'user': 'admin',
1277-
'password': 'test_password',
1278-
'database': 'test_dbname',
1279-
'target_session_attrs': 'primary',
1280-
'krbsrvname': 'fakekrbsrvname',
1281-
'gsslib': 'sspi',
1282-
}
1283-
)
1284-
})
1285-
self.run_testcase({
1286-
'dsn': 'postgresql://?service=test_service_database',
1287-
'env': {
1288-
'PGSERVICEFILE': connection_service_file.name
1289-
},
1290-
'result': (
1291-
[('somehost', 5433)],
1292-
{
1293-
'user': 'admin',
1294-
'password': 'test_password',
1295-
'database': 'test_dbname',
1296-
'target_session_attrs': 'primary',
1297-
'krbsrvname': 'fakekrbsrvname',
1298-
'gsslib': 'sspi',
1299-
}
1300-
)
1301-
})
1268+
# passfile path in env
1269+
self.run_testcase({
1270+
'dsn': 'postgresql://?service=test_service_dbname',
1271+
'env': {
1272+
'PGSERVICEFILE': connection_service_file.name
1273+
},
1274+
'result': (
1275+
[('somehost', 5433)],
1276+
{
1277+
'user': 'admin',
1278+
'password': 'test_password',
1279+
'database': 'test_dbname',
1280+
'target_session_attrs': 'primary',
1281+
'krbsrvname': 'fakekrbsrvname',
1282+
'gsslib': 'sspi',
1283+
}
1284+
)
1285+
})
1286+
self.run_testcase({
1287+
'dsn': 'postgresql://?service=test_service_database',
1288+
'env': {
1289+
'PGSERVICEFILE': connection_service_file.name
1290+
},
1291+
'result': (
1292+
[('somehost', 5433)],
1293+
{
1294+
'user': 'admin',
1295+
'password': 'test_password',
1296+
'database': 'test_dbname',
1297+
'target_session_attrs': 'primary',
1298+
'krbsrvname': 'fakekrbsrvname',
1299+
'gsslib': 'sspi',
1300+
}
1301+
)
1302+
})
13021303
finally:
13031304
os.unlink(connection_service_file.name)
13041305

0 commit comments

Comments
 (0)