def parse_soap_enveloped_saml(text, body_class, header_class=None):
 envelope = ElementTree.fromstring(text)
 assert (envelope.tag == ('{%s}Envelope' % NAMESPACE))
 body = None
 header = {}
 for part in envelope:
  if (part.tag == ('{%s}Body' % NAMESPACE)):
   for sub in part:
    try:
     body = saml2.create_class_from_element_tree(body_class, sub)
    except Exception:
     raise Exception(('Wrong body type (%s) in SOAP envelope' % sub.tag))
  elif (part.tag == ('{%s}Header' % NAMESPACE)):
   if (not header_class):
    raise Exception("Header where I didn't expect one")
   for sub in part:
    for klass in header_class:
     if (sub.tag == ('{%s}%s' % (klass.c_namespace, klass.c_tag))):
      header[sub.tag] = saml2.create_class_from_element_tree(klass, sub)
      break
 return (body, header)

def parse_soap_enveloped_saml ( text , body_class , header_class = None ) : envelope = ElementTree . fromstring ( text ) assert ( envelope . tag == ( '{%s}Envelope' % NAMESPACE ) ) body = None header = { } for part in envelope : if ( part . tag == ( '{%s}Body' % NAMESPACE ) ) : for sub in part : try : body = saml2 . create_class_from_element_tree ( body_class , sub ) except Exception : raise Exception ( ( 'Wrong body type (%s) in SOAP envelope' % sub . tag ) ) elif ( part . tag == ( '{%s}Header' % NAMESPACE ) ) : if ( not header_class ) : raise Exception ( "Header where I didn't expect one" ) for sub in part : for klass in header_class : if ( sub . tag == ( '{%s}%s' % ( klass . c_namespace , klass . c_tag ) ) ) : header [ sub . tag ] = saml2 . create_class_from_element_tree ( klass , sub ) break return ( body , header )
parses a soap enveloped saml thing and returns header parts and body .