Skip to content

Commit ae843a2

Browse files
author
CommanderKeynes
committed
Add servicefile as parameter
1 parent c99ad22 commit ae843a2

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

asyncpg/connect_utils.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ def _dot_postgresql_path(filename) -> typing.Optional[pathlib.Path]:
272272

273273

274274
def _parse_connect_dsn_and_args(*, dsn, host, port, user,
275-
password, passfile, database, ssl, service,
275+
password, passfile, database, ssl,
276+
service, servicefile,
276277
direct_tls, server_settings,
277278
target_session_attrs, krbsrvname, gsslib):
278279
# `auth_hosts` is the version of host information for the purposes
@@ -297,7 +298,11 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
297298
if not service and val:
298299
service = val
299300

300-
connection_service_file = os.getenv('PGSERVICEFILE')
301+
connection_service_file = servicefile
302+
303+
if connection_service_file is None:
304+
connection_service_file = os.getenv('PGSERVICEFILE')
305+
301306
if connection_service_file is None:
302307
homedir = compat.get_pg_home_directory()
303308
if homedir:
@@ -859,7 +864,7 @@ def _parse_connect_arguments(*, dsn, host, port, user, password, passfile,
859864
max_cacheable_statement_size,
860865
ssl, direct_tls, server_settings,
861866
target_session_attrs, krbsrvname, gsslib,
862-
service):
867+
service, servicefile):
863868
local_vars = locals()
864869
for var_name in {'max_cacheable_statement_size',
865870
'max_cached_statement_lifetime',
@@ -889,7 +894,8 @@ def _parse_connect_arguments(*, dsn, host, port, user, password, passfile,
889894
direct_tls=direct_tls, database=database,
890895
server_settings=server_settings,
891896
target_session_attrs=target_session_attrs,
892-
krbsrvname=krbsrvname, gsslib=gsslib, service=service)
897+
krbsrvname=krbsrvname, gsslib=gsslib,
898+
service=service, servicefile=servicefile)
893899

894900
config = _ClientConfiguration(
895901
command_timeout=command_timeout,

asyncpg/connection.py

+9
Original file line numberDiff line numberDiff line change
@@ -2075,6 +2075,7 @@ async def connect(dsn=None, *,
20752075
host=None, port=None,
20762076
user=None, password=None, passfile=None,
20772077
service=None,
2078+
servicefile=None,
20782079
database=None,
20792080
loop=None,
20802081
timeout=60,
@@ -2188,6 +2189,10 @@ async def connect(dsn=None, *,
21882189
The name of the postgres connection service stored in the postgres
21892190
connection service file.
21902191
2192+
:param servicefile:
2193+
The location of the connnection service file used to store
2194+
connection parameters.
2195+
21912196
:param loop:
21922197
An asyncio event loop instance. If ``None``, the default
21932198
event loop will be used.
@@ -2400,6 +2405,9 @@ async def connect(dsn=None, *,
24002405
.. versionchanged:: 0.30.0
24012406
Added the *krbsrvname* and *gsslib* parameters.
24022407
2408+
.. versionchanged:: 0.31.0
2409+
Added the *servicefile* and *service* parameters.
2410+
24032411
.. _SSLContext: https://docs.python.org/3/library/ssl.html#ssl.SSLContext
24042412
.. _create_default_context:
24052413
https://docs.python.org/3/library/ssl.html#ssl.create_default_context
@@ -2434,6 +2442,7 @@ async def connect(dsn=None, *,
24342442
password=password,
24352443
passfile=passfile,
24362444
service=service,
2445+
servicefile=servicefile,
24372446
ssl=ssl,
24382447
direct_tls=direct_tls,
24392448
database=database,

tests/test_connect.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,7 @@ def run_testcase(self, testcase):
11341134
krbsrvname = testcase.get('krbsrvname')
11351135
gsslib = testcase.get('gsslib')
11361136
service = testcase.get('service')
1137+
servicefile = testcase.get('servicefile')
11371138

11381139
expected = testcase.get('result')
11391140
expected_error = testcase.get('error')
@@ -1159,7 +1160,8 @@ def run_testcase(self, testcase):
11591160
direct_tls=direct_tls,
11601161
server_settings=server_settings,
11611162
target_session_attrs=target_session_attrs,
1162-
krbsrvname=krbsrvname, gsslib=gsslib, service=service)
1163+
krbsrvname=krbsrvname, gsslib=gsslib,
1164+
service=service, servicefile=servicefile)
11631165

11641166
params = {
11651167
k: v for k, v in params._asdict().items()

0 commit comments

Comments
 (0)