@staticmethod<EOL><INDENT>def parse(<EOL>idp_metadata,<EOL>required_sso_binding=OneLogin_Saml2_Constants.BINDING_HTTP_REDIRECT,<EOL>required_slo_binding=OneLogin_Saml2_Constants.BINDING_HTTP_REDIRECT,<EOL>entity_id=None):<DEDENT>
data = {}<EOL>dom = OneLogin_Saml2_XML.to_etree(idp_metadata)<EOL>idp_entity_id = want_authn_requests_signed = idp_name_id_format = idp_sso_url = idp_slo_url = certs = None<EOL>entity_desc_path = '<STR_LIT>'<EOL>if entity_id:<EOL><INDENT>entity_desc_path += "<STR_LIT>" % entity_id<EOL><DEDENT>entity_descriptor_nodes = OneLogin_Saml2_XML.query(dom, entity_desc_path)<EOL>if len(entity_descriptor_nodes) > <NUM_LIT:0>:<EOL><INDENT>entity_descriptor_node = entity_descriptor_nodes[<NUM_LIT:0>]<EOL>idp_descriptor_nodes = OneLogin_Saml2_XML.query(entity_descriptor_node, '<STR_LIT>')<EOL>if len(idp_descriptor_nodes) > <NUM_LIT:0>:<EOL><INDENT>idp_descriptor_node = idp_descriptor_nodes[<NUM_LIT:0>]<EOL>idp_entity_id = entity_descriptor_node.get('<STR_LIT>', None)<EOL>want_authn_requests_signed = entity_descriptor_node.get('<STR_LIT>', None)<EOL>name_id_format_nodes = OneLogin_Saml2_XML.query(idp_descriptor_node, '<STR_LIT>')<EOL>if len(name_id_format_nodes) > <NUM_LIT:0>:<EOL><INDENT>idp_name_id_format = OneLogin_Saml2_XML.element_text(name_id_format_nodes[<NUM_LIT:0>])<EOL><DEDENT>sso_nodes = OneLogin_Saml2_XML.query(<EOL>idp_descriptor_node,<EOL>"<STR_LIT>" % required_sso_binding<EOL>)<EOL>if len(sso_nodes) > <NUM_LIT:0>:<EOL><INDENT>idp_sso_url = sso_nodes[<NUM_LIT:0>].get('<STR_LIT>', None)<EOL><DEDENT>slo_nodes = OneLogin_Saml2_XML.query(<EOL>idp_descriptor_node,<EOL>"<STR_LIT>" % required_slo_binding<EOL>)<EOL>if len(slo_nodes) > <NUM_LIT:0>:<EOL><INDENT>idp_slo_url = slo_nodes[<NUM_LIT:0>].get('<STR_LIT>', None)<EOL><DEDENT>signing_nodes = OneLogin_Saml2_XML.query(idp_descriptor_node, "<STR_LIT>")<EOL>encryption_nodes = OneLogin_Saml2_XML.query(idp_descriptor_node, "<STR_LIT>")<EOL>if len(signing_nodes) > <NUM_LIT:0> or len(encryption_nodes) > <NUM_LIT:0>:<EOL><INDENT>certs = {}<EOL>if len(signing_nodes) > <NUM_LIT:0>:<EOL><INDENT>certs['<STR_LIT>'] = []<EOL>for cert_node in signing_nodes:<EOL><INDENT>certs['<STR_LIT>'].append('<STR_LIT>'.join(OneLogin_Saml2_XML.element_text(cert_node).split()))<EOL><DEDENT><DEDENT>if len(encryption_nodes) > <NUM_LIT:0>:<EOL><INDENT>certs['<STR_LIT>'] = []<EOL>for cert_node in encryption_nodes:<EOL><INDENT>certs['<STR_LIT>'].append('<STR_LIT>'.join(OneLogin_Saml2_XML.element_text(cert_node).split()))<EOL><DEDENT><DEDENT><DEDENT>data['<STR_LIT>'] = {}<EOL>if idp_entity_id is not None:<EOL><INDENT>data['<STR_LIT>']['<STR_LIT>'] = idp_entity_id<EOL><DEDENT>if idp_sso_url is not None:<EOL><INDENT>data['<STR_LIT>']['<STR_LIT>'] = {}<EOL>data['<STR_LIT>']['<STR_LIT>']['<STR_LIT:url>'] = idp_sso_url<EOL>data['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] = required_sso_binding<EOL><DEDENT>if idp_slo_url is not None:<EOL><INDENT>data['<STR_LIT>']['<STR_LIT>'] = {}<EOL>data['<STR_LIT>']['<STR_LIT>']['<STR_LIT:url>'] = idp_slo_url<EOL>data['<STR_LIT>']['<STR_LIT>']['<STR_LIT>'] = required_slo_binding<EOL><DEDENT>if want_authn_requests_signed is not None:<EOL><INDENT>data['<STR_LIT>'] = {}<EOL>data['<STR_LIT>']['<STR_LIT>'] = want_authn_requests_signed<EOL><DEDENT>if idp_name_id_format:<EOL><INDENT>data['<STR_LIT>'] = {}<EOL>data['<STR_LIT>']['<STR_LIT>'] = idp_name_id_format<EOL><DEDENT>if certs is not None:<EOL><INDENT>if (len(certs) == <NUM_LIT:1> and<EOL>(('<STR_LIT>' in certs and len(certs['<STR_LIT>']) == <NUM_LIT:1>) or<EOL>('<STR_LIT>' in certs and len(certs['<STR_LIT>']) == <NUM_LIT:1>))) or(('<STR_LIT>' in certs and len(certs['<STR_LIT>']) == <NUM_LIT:1>) and<EOL>('<STR_LIT>' in certs and len(certs['<STR_LIT>']) == <NUM_LIT:1> and<EOL>certs['<STR_LIT>'][<NUM_LIT:0>] == certs['<STR_LIT>'][<NUM_LIT:0>])):<EOL><INDENT>if '<STR_LIT>' in certs:<EOL><INDENT>data['<STR_LIT>']['<STR_LIT>'] = certs['<STR_LIT>'][<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>data['<STR_LIT>']['<STR_LIT>'] = certs['<STR_LIT>'][<NUM_LIT:0>]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>data['<STR_LIT>']['<STR_LIT>'] = certs<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return data<EOL>
Parses the Identity Provider metadata and return a dict with extracted data.

If there are multiple <IDPSSODescriptor> tags, parse only the first.

Parses only those SSO endpoints with the same binding as given by
the `required_sso_binding` parameter.

Parses only those SLO endpoints with the same binding as given by
the `required_slo_binding` parameter.

If the metadata specifies multiple SSO endpoints with the required
binding, extract only the first (the same holds true for SLO
endpoints).

:param idp_metadata: XML of the Identity Provider Metadata.
:type idp_metadata: string

:param required_sso_binding: Parse only POST or REDIRECT SSO endpoints.
:type required_sso_binding: one of OneLogin_Saml2_Constants.BINDING_HTTP_REDIRECT
    or OneLogin_Saml2_Constants.BINDING_HTTP_POST

:param required_slo_binding: Parse only POST or REDIRECT SLO endpoints.
:type required_slo_binding: one of OneLogin_Saml2_Constants.BINDING_HTTP_REDIRECT
    or OneLogin_Saml2_Constants.BINDING_HTTP_POST

:param entity_id: Specify the entity_id of the EntityDescriptor that you want to parse a XML
                  that contains multiple EntityDescriptor.
:type entity_id: string

:returns: settings dict with extracted data
:rtype: dict