MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / _hello

Method _hello

pymongo/asynchronous/pool.py:249–333  ·  view source on GitHub ↗
(
        self,
        topology_version: Optional[Any],
        heartbeat_frequency: Optional[int],
    )

Source from the content-addressed store, hash-verified

247 return await self._hello(None, None)
248
249 async def _hello(
250 self,
251 topology_version: Optional[Any],
252 heartbeat_frequency: Optional[int],
253 ) -> Hello[dict[str, Any]]:
254 cmd = self.hello_cmd()
255 performing_handshake = not self.performed_handshake
256 awaitable = False
257 cmd["backpressure"] = True
258 if performing_handshake:
259 self.performed_handshake = True
260 cmd["client"] = self.opts.metadata
261 if self.compression_settings:
262 cmd["compression"] = self.compression_settings.compressors
263 if self.opts.load_balanced:
264 cmd["loadBalanced"] = True
265 elif topology_version is not None:
266 cmd["topologyVersion"] = topology_version
267 assert heartbeat_frequency is not None
268 cmd["maxAwaitTimeMS"] = int(heartbeat_frequency * 1000)
269 awaitable = True
270 # If connect_timeout is None there is no timeout.
271 if self.opts.connect_timeout:
272 self.set_conn_timeout(self.opts.connect_timeout + heartbeat_frequency)
273
274 creds = self.opts._credentials
275 if creds:
276 if creds.mechanism == "DEFAULT" and creds.username:
277 cmd["saslSupportedMechs"] = creds.source + "." + creds.username
278 from pymongo.asynchronous import auth
279
280 auth_ctx = auth._AuthContext.from_credentials(creds, self.address)
281 if auth_ctx:
282 speculative_authenticate = auth_ctx.speculate_command()
283 if speculative_authenticate is not None:
284 cmd["speculativeAuthenticate"] = speculative_authenticate
285 else:
286 auth_ctx = None
287
288 if performing_handshake:
289 start = time.monotonic()
290 doc = await self.command("admin", cmd, publish_events=False, exhaust_allowed=awaitable)
291 if performing_handshake:
292 self.connect_rtt = time.monotonic() - start
293 hello = Hello(doc, awaitable=awaitable)
294 self.is_writable = hello.is_writable
295 self.max_wire_version = hello.max_wire_version
296 self.max_bson_size = hello.max_bson_size
297 self.max_message_size = hello.max_message_size
298 self.max_write_batch_size = hello.max_write_batch_size
299 self.supports_sessions = (
300 hello.logical_session_timeout_minutes is not None and hello.is_readable
301 )
302 self.logical_session_timeout_minutes: Optional[int] = hello.logical_session_timeout_minutes
303 self.hello_ok = hello.hello_ok
304 self.is_repl = hello.server_type in (
305 SERVER_TYPE.RSPrimary,
306 SERVER_TYPE.RSSecondary,

Callers 2

helloMethod · 0.95
_check_with_socketMethod · 0.45

Calls 11

hello_cmdMethod · 0.95
set_conn_timeoutMethod · 0.95
commandMethod · 0.95
HelloClass · 0.90
ConfigurationErrorClass · 0.90
from_credentialsMethod · 0.45
speculate_commandMethod · 0.45
parse_responseMethod · 0.45
speculate_succeededMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected