def _pick_idp(self, query, end_point_index):
            query_dict = {}
            if isinstance(query, six.string_types):
                query_dict = dict(parse_qs(query))
            else:
                for key, value in six.iteritems(query):
                    if isinstance(value, list):
                        query_dict[key] = value[0]
                    else:
                        query_dict[key] = value
                query = urlencode(query_dict)

            _cli = self.sp
            # Find all IdPs
            idps = self.sp.metadata.with_descriptor("idpsso")

            idp_entity_id = None

            if len(idps) == 1:
                # idps is a dictionary
                idp_entity_id = list(idps.keys())[0]

            if not idp_entity_id and query:
                try:
                    _idp_entity_id = query_dict[self.idp_query_param][0]
                    if _idp_entity_id in idps:
                        idp_entity_id = _idp_entity_id
                except KeyError:
                    logger.debug("No IdP entity ID in query: %s" % query)
                    pass

            if not idp_entity_id:
                cookie = self.create_cookie(
                    '{"' + self.CONST_QUERY + '": "' + base64.b64encode(query) +
                    '" , "' + self.CONST_HASIDP + '": "False" }',
                    self.CONST_SAML_COOKIE, self.CONST_SAML_COOKIE)
                if self.sp_conf.WAYF:
                    if query:
                        try:
                            wayf_selected = query_dict["wayf_selected"][0]
                        except KeyError:
                            return self._wayf_redirect(cookie)
                        idp_entity_id = wayf_selected
                    else:
                        return self._wayf_redirect(cookie)
                elif self.sp_conf.DISCOSRV:
                    if query:
                        idp_entity_id = _cli.parse_discovery_service_response(query=query)
                    if not idp_entity_id:
                        sid_ = sid()
                        self.cache_outstanding_queries[sid_] = self.verification_endpoint
                        eid = _cli.config.entityid

                        disco_end_point_index = end_point_index["disco_end_point_index"]
                        ret = _cli.config.getattr("endpoints", "sp")[
                            "discovery_response"][disco_end_point_index][0]
                        ret += "?sid=%s" % sid_
                        loc = _cli.create_discovery_service_request(
                            self.sp_conf.DISCOSRV, eid, **{"return": ret})
                        return -1, SeeOther(loc, headers=[cookie])
                elif not len(idps):
                    raise ServiceErrorException(
                        'Misconfiguration for the SAML Service Provider!')
                else:
                    return -1, NotImplemented("No WAYF or DS present!")
            return 0, idp_entity_id
Common function for setting error information for return dicts
dataset/ETHPy150Open rohe/pyoidc/src/oic/utils/authn/saml.py/SAMLAuthnMethod._pick_idp--crossover with--dataset/ETHPy150Open saltstack/salt/salt/modules/file.py/_error