def parse_soap_enveloped_saml_thingy(text, expected_tags):
 envelope = ElementTree.fromstring(text)
 assert (envelope.tag == ('{%s}Envelope' % soapenv.NAMESPACE))
 assert (len(envelope) >= 1)
 body = None
 for part in envelope:
  if (part.tag == ('{%s}Body' % soapenv.NAMESPACE)):
   assert (len(part) == 1)
   body = part
   break
 if (body is None):
  return ''
 saml_part = body[0]
 if (saml_part.tag in expected_tags):
  return ElementTree.tostring(saml_part, encoding='UTF-8')
 else:
  raise WrongMessageType(("Was '%s' expected one of %s" % (saml_part.tag, expected_tags)))

def parse_soap_enveloped_saml_thingy ( text , expected_tags ) : envelope = ElementTree . fromstring ( text ) assert ( envelope . tag == ( '{%s}Envelope' % soapenv . NAMESPACE ) ) assert ( len ( envelope ) >= 1 ) body = None for part in envelope : if ( part . tag == ( '{%s}Body' % soapenv . NAMESPACE ) ) : assert ( len ( part ) == 1 ) body = part break if ( body is None ) : return '' saml_part = body [ 0 ] if ( saml_part . tag in expected_tags ) : return ElementTree . tostring ( saml_part , encoding = 'UTF-8' ) else : raise WrongMessageType ( ( "Was '%s' expected one of %s" % ( saml_part . tag , expected_tags ) ) )
parses a soap enveloped saml thing and returns the thing as a string .