MCPcopy Create free account
hub / github.com/MagicStack/asyncpg / _parse_connect_dsn_and_args

Function _parse_connect_dsn_and_args

asyncpg/connect_utils.py:282–876  ·  view source on GitHub ↗
(*, dsn, host, port, user,
                                password, passfile, database, ssl,
                                service, servicefile,
                                direct_tls, server_settings,
                                target_session_attrs, krbsrvname, gsslib)

Source from the content-addressed store, hash-verified

280
281
282def _parse_connect_dsn_and_args(*, dsn, host, port, user,
283 password, passfile, database, ssl,
284 service, servicefile,
285 direct_tls, server_settings,
286 target_session_attrs, krbsrvname, gsslib):
287 # `auth_hosts` is the version of host information for the purposes
288 # of reading the pgpass file.
289 auth_hosts = None
290 sslcert = sslkey = sslrootcert = sslcrl = sslpassword = None
291 ssl_min_protocol_version = ssl_max_protocol_version = None
292 sslnegotiation = None
293
294 if dsn:
295 parsed = urllib.parse.urlparse(dsn)
296
297 query = None
298 if parsed.query:
299 query = urllib.parse.parse_qs(parsed.query, strict_parsing=True)
300 for key, val in query.items():
301 if isinstance(val, list):
302 query[key] = val[-1]
303
304 if 'service' in query:
305 val = query.pop('service')
306 if not service and val:
307 service = val
308
309 connection_service_file = servicefile
310
311 if connection_service_file is None:
312 connection_service_file = os.getenv('PGSERVICEFILE')
313
314 if connection_service_file is None:
315 homedir = compat.get_pg_home_directory()
316 if homedir:
317 connection_service_file = homedir / PG_SERVICEFILE
318 else:
319 connection_service_file = None
320 else:
321 connection_service_file = pathlib.Path(connection_service_file)
322
323 if parsed.scheme not in {'postgresql', 'postgres'}:
324 raise exceptions.ClientConfigurationError(
325 'invalid DSN: scheme is expected to be either '
326 '"postgresql" or "postgres", got {!r}'.format(parsed.scheme))
327
328 if parsed.netloc:
329 if '@' in parsed.netloc:
330 dsn_auth, _, dsn_hostspec = parsed.netloc.partition('@')
331 else:
332 dsn_hostspec = parsed.netloc
333 dsn_auth = ''
334 else:
335 dsn_auth = dsn_hostspec = ''
336
337 if dsn_auth:
338 dsn_user, _, dsn_password = dsn_auth.partition(':')
339 else:

Callers 1

_parse_connect_argumentsFunction · 0.85

Calls 9

_parse_hostlistFunction · 0.85
_validate_port_specFunction · 0.85
SSLNegotiationClass · 0.85
_dot_postgresql_pathFunction · 0.85
_parse_tls_versionFunction · 0.85
SessionAttributeClass · 0.85
getMethod · 0.80
parseMethod · 0.80

Tested by

no test coverage detected