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

Method _async_mongo_client

test/__init__.py:1009–1037  ·  view source on GitHub ↗

Create a new client over SSL/TLS if necessary.

(self, host, port, authenticate=True, directConnection=None, **kwargs)

Source from the content-addressed store, hash-verified

1007 return client
1008
1009 def _async_mongo_client(self, host, port, authenticate=True, directConnection=None, **kwargs):
1010 """Create a new client over SSL/TLS if necessary."""
1011 host = host or client_context.host
1012 port = port or client_context.port
1013 client_options: dict = client_context.default_client_options.copy()
1014 if client_context.replica_set_name and not directConnection:
1015 client_options["replicaSet"] = client_context.replica_set_name
1016 if directConnection is not None:
1017 client_options["directConnection"] = directConnection
1018 client_options.update(kwargs)
1019
1020 uri = _connection_string(host)
1021 auth_mech = kwargs.get("authMechanism", "")
1022 if client_context.auth_enabled and authenticate and auth_mech != "MONGODB-OIDC":
1023 # Only add the default username or password if one is not provided.
1024 res = parse_uri(uri)
1025 if (
1026 not res["username"]
1027 and not res["password"]
1028 and "username" not in client_options
1029 and "password" not in client_options
1030 ):
1031 client_options["username"] = db_user
1032 client_options["password"] = db_pwd
1033 client = MongoClient(uri, port, **client_options)
1034 if client._options.connect:
1035 client._connect()
1036 self.addCleanup(client.close)
1037 return client
1038
1039 @classmethod
1040 def unmanaged_single_client_noauth(

Callers 6

single_client_noauthMethod · 0.95
single_clientMethod · 0.95
rs_client_noauthMethod · 0.95
rs_clientMethod · 0.95
rs_or_single_clientMethod · 0.95

Calls 8

_connectMethod · 0.95
addCleanupMethod · 0.95
parse_uriFunction · 0.90
MongoClientClass · 0.90
copyMethod · 0.80
_connection_stringFunction · 0.70
updateMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected