'Set values in the knowledge base based on responses.'

def SetKBValue(self, artifact_name, responses):

    artifact_obj = artifact_registry.REGISTRY.GetArtifact(artifact_name)
    if (not responses):
        return None
    provided = set()
    for response in responses:
        if isinstance(response, anomaly.Anomaly):
            logging.error('Artifact    %s    returned    an    Anomaly:    %s', artifact_name, response)
            continue
        if isinstance(response, rdf_client.User):
            (attrs_provided, merge_conflicts) = self.state.knowledge_base.MergeOrAddUser(response)
            provided.update(attrs_provided)
            for (key, old_val, val) in merge_conflicts:
                self.Log('User    merge    conflict    in    %s.    Old    value:    %s,    Newly    written    value:    %s', key, old_val, val)
        else:
            artifact_provides = artifact_obj.provides
            if isinstance(response, rdf_protodict.Dict):
                kb_dict = response.ToDict()
            elif (len(artifact_provides) == 1):
                kb_dict = {artifact_provides[0]: response}
            else:
                raise RuntimeError(('Attempt    to    set    a    knowledge    base    value    with    multiple    provides    clauses    without    using    Dict.:    %s' % artifact_obj))
            for (provides, value) in kb_dict.iteritems():
                if (provides not in artifact_provides):
                    raise RuntimeError(('Attempt    to    provide    knowledge    base    value    %s    without    this    being    set    in    the    artifact    provides    setting:    %s' % (provides, artifact_obj)))
                if isinstance(value, rdfvalue.RDFString):
                    value = utils.SmartStr(value)
                elif hasattr(value, 'registry_data'):
                    value = value.registry_data.GetValue()
                if value:
                    logging.debug('Set    KB    %s    to    %s', provides, value)
                    self.state.knowledge_base.Set(provides, value)
                    provided.add(provides)
                else:
                    logging.debug('Empty    KB    return    value    for    %s', provides)
    return provided
