(*, loop, connection_class, record_class, **kwargs)
| 1203 | |
| 1204 | |
| 1205 | async def _connect(*, loop, connection_class, record_class, **kwargs): |
| 1206 | if loop is None: |
| 1207 | loop = asyncio.get_event_loop() |
| 1208 | |
| 1209 | addrs, params, config = _parse_connect_arguments(**kwargs) |
| 1210 | target_attr = params.target_session_attrs |
| 1211 | |
| 1212 | candidates = [] |
| 1213 | chosen_connection = None |
| 1214 | last_error = None |
| 1215 | try: |
| 1216 | for addr in addrs: |
| 1217 | try: |
| 1218 | conn = await _connect_addr( |
| 1219 | addr=addr, |
| 1220 | loop=loop, |
| 1221 | params=params, |
| 1222 | config=config, |
| 1223 | connection_class=connection_class, |
| 1224 | record_class=record_class, |
| 1225 | ) |
| 1226 | candidates.append(conn) |
| 1227 | if await _can_use_connection(conn, target_attr): |
| 1228 | chosen_connection = conn |
| 1229 | break |
| 1230 | except OSError as ex: |
| 1231 | last_error = ex |
| 1232 | else: |
| 1233 | if target_attr == SessionAttribute.prefer_standby and candidates: |
| 1234 | chosen_connection = random.choice(candidates) |
| 1235 | finally: |
| 1236 | |
| 1237 | async def _close_candidates(conns, chosen): |
| 1238 | await asyncio.gather( |
| 1239 | *(c.close() for c in conns if c is not chosen), |
| 1240 | return_exceptions=True |
| 1241 | ) |
| 1242 | if candidates: |
| 1243 | asyncio.create_task( |
| 1244 | _close_candidates(candidates, chosen_connection)) |
| 1245 | |
| 1246 | if chosen_connection: |
| 1247 | return chosen_connection |
| 1248 | |
| 1249 | raise last_error or exceptions.TargetServerAttributeNotMatched( |
| 1250 | 'None of the hosts match the target attribute requirement ' |
| 1251 | '{!r}'.format(target_attr) |
| 1252 | ) |
| 1253 | |
| 1254 | |
| 1255 | async def _cancel(*, loop, addr, params: _ConnectionParameters, |
nothing calls this directly
no test coverage detected
searching dependent graphs…