'Save a set of authentication credentials.
The credentials are used to login a socket whenever one is created.
If `connect` is True, verify the credentials on the server first.'

def _cache_credentials(self, source, credentials, connect=False):

    all_credentials = self.__all_credentials.copy()
    if (source in all_credentials):
        if (credentials == all_credentials[source]):
            return
        raise OperationFailure('Another    user    is    already    authenticated    to    this    database.    You    must    logout    first.')
    if connect:
        server = self._get_topology().select_server(writable_preferred_server_selector)
        with server.get_socket(all_credentials) as sock_info:
            sock_info.authenticate(credentials)
    self.__all_credentials[source] = credentials
