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

Function __connect_addr

asyncpg/connect_utils.py:1127–1198  ·  view source on GitHub ↗
(
    params,
    retry,
    addr,
    loop,
    config,
    connection_class,
    record_class,
    params_input,
)

Source from the content-addressed store, hash-verified

1125
1126
1127async def __connect_addr(
1128 params,
1129 retry,
1130 addr,
1131 loop,
1132 config,
1133 connection_class,
1134 record_class,
1135 params_input,
1136):
1137 connected = _create_future(loop)
1138
1139 proto_factory = lambda: protocol.Protocol(
1140 addr, connected, params, record_class, loop)
1141
1142 if isinstance(addr, str):
1143 # UNIX socket
1144 connector = loop.create_unix_connection(proto_factory, addr)
1145
1146 elif params.ssl and params.ssl_negotiation is SSLNegotiation.direct:
1147 # if ssl and ssl_negotiation is `direct`, skip STARTTLS and perform
1148 # direct SSL connection
1149 connector = loop.create_connection(
1150 proto_factory, *addr, ssl=params.ssl
1151 )
1152
1153 elif params.ssl:
1154 connector = _create_ssl_connection(
1155 proto_factory, *addr, loop=loop, ssl_context=params.ssl,
1156 ssl_is_advisory=params.sslmode == SSLMode.prefer,
1157 retry=retry and params.sslmode == SSLMode.prefer)
1158 else:
1159 connector = loop.create_connection(proto_factory, *addr)
1160
1161 try:
1162 tr, pr = await connector
1163 except (Exception, asyncio.CancelledError):
1164 # The protocol can exist before create_connection() returns. If
1165 # that operation is cancelled, nobody will await authentication.
1166 if not connected.done():
1167 connected.cancel()
1168 elif not connected.cancelled():
1169 connected.exception()
1170 raise
1171
1172 try:
1173 await connected
1174 except exceptions.PostgresError as exc:
1175 tr.close()
1176
1177 if not pr._auth_received and isinstance(
1178 exc, exceptions.CannotConnectNowError
1179 ):
1180 raise _NextHostSignal() from exc
1181
1182 # Only retry before AuthenticationOk, and only if the other transport
1183 # has not been tried. This includes ConnectionDoesNotExistError,
1184 # which is needed for Windows compatibility.

Callers 1

_connect_addrFunction · 0.85

Calls 6

_create_futureFunction · 0.85
_create_ssl_connectionFunction · 0.85
_NextHostSignalClass · 0.85
_RetryConnectSignalClass · 0.85
cancelMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected