':param name_id: The NameID that specifies the principal
:param name_id_policy: The NameIDPolicy of the requester
:return: If an old name_id exists that match the name-id policy
that is return otherwise if a new one can be created it
will be and returned. If no old matching exists and a new
is not allowed to be created None is returned.'

def handle_name_id_mapping_request(self, name_id, name_id_policy):

    _id = self.find_local_id(name_id)
    if (not _id):
        raise Unknown('Unknown    entity')
    for val in self.db[_id].split('    '):
        _nid = decode(val)
        if (_nid.format == name_id_policy.format):
            if (_nid.sp_name_qualifier == name_id_policy.sp_name_qualifier):
                return _nid
    if (name_id_policy.allow_create == 'false'):
        raise PolicyError('Not    allowed    to    create    new    identifier')
    return self.construct_nameid(_id, name_id_policy=name_id_policy)
