(mech, source, user, passwd, extra)
Build and return a mechanism specific credentials tuple.
Build and return a mechanism specific credentials tuple.
Build and return a mechanism specific credentials tuple .
def _build_credentials_tuple(mech, source, user, passwd, extra):
    """Build and return a mechanism specific credentials tuple.
    """
    user = _unicode(user) if user is not None else None
    password = passwd if passwd is None else _unicode(passwd)
    if mech == 'GSSAPI':
        properties = extra.get('authmechanismproperties', {})
        service_name = properties.get('SERVICE_NAME', 'mongodb')
        canonicalize = properties.get('CANONICALIZE_HOST_NAME', False)
        service_realm = properties.get('SERVICE_REALM')
        props = GSSAPIProperties(service_name=service_name,
                                 canonicalize_host_name=canonicalize,
                                 service_realm=service_realm)
        # Source is always $external.
        return MongoCredential(mech, '$external', user, password, props)
    elif mech == 'MONGODB-X509':
        # user can be None.
        return MongoCredential(mech, '$external', user, None, None)
    else:
        if passwd is None:
            raise ConfigurationError("A password is required.")
        return MongoCredential(mech, source, user, password, None)
def _build_credentials_tuple ( mech , source , user , passwd , extra ) : user = _unicode ( user ) if user is not None else None password = passwd if passwd is None else _unicode ( passwd ) if mech == 'GSSAPI' : properties = extra . get ( 'authmechanismproperties' , { } ) service_name = properties . get ( 'SERVICE_NAME' , 'mongodb' ) canonicalize = properties . get ( 'CANONICALIZE_HOST_NAME' , False ) service_realm = properties . get ( 'SERVICE_REALM' ) props = GSSAPIProperties ( service_name = service_name , canonicalize_host_name = canonicalize , service_realm = service_realm ) # Source is always $external. return MongoCredential ( mech , '$external' , user , password , props ) elif mech == 'MONGODB-X509' : # user can be None. return MongoCredential ( mech , '$external' , user , None , None ) else : if passwd is None : raise ConfigurationError ( "A password is required." ) return MongoCredential ( mech , source , user , password , None )