def make_soap_enveloped_saml_thingy(thingy, header_parts=None):
 envelope = ElementTree.Element('')
 envelope.tag = ('{%s}Envelope' % NAMESPACE)
 if header_parts:
  header = ElementTree.Element('')
  header.tag = ('{%s}Header' % NAMESPACE)
  envelope.append(header)
  for part in header_parts:
   part.become_child_element_of(header)
 body = ElementTree.Element('')
 body.tag = ('{%s}Body' % NAMESPACE)
 envelope.append(body)
 if isinstance(thingy, basestring):
  logger.debug(('thingy0: %s' % thingy))
  _part = thingy.split('\n')
  thingy = ''.join(_part[1:])
  thingy = thingy.replace(PREFIX, '')
  logger.debug(('thingy: %s' % thingy))
  _child = ElementTree.Element('')
  _child.tag = ('{%s}FuddleMuddle' % DUMMY_NAMESPACE)
  body.append(_child)
  _str = ElementTree.tostring(envelope, encoding='UTF-8')
  logger.debug(('SOAP precursor: %s' % _str))
  i = _str.find(DUMMY_NAMESPACE)
  j = _str.rfind('xmlns:', 0, i)
  cut1 = _str[j:((i + len(DUMMY_NAMESPACE)) + 1)]
  _str = _str.replace(cut1, '')
  first = _str.find(('<%s:FuddleMuddle' % (cut1[6:9],)))
  last = _str.find('>', (first + 14))
  cut2 = _str[first:(last + 1)]
  return _str.replace(cut2, thingy)
 else:
  thingy.become_child_element_of(body)
  return ElementTree.tostring(envelope, encoding='UTF-8')

def make_soap_enveloped_saml_thingy ( thingy , header_parts = None ) : envelope = ElementTree . Element ( '' ) envelope . tag = ( '{%s}Envelope' % NAMESPACE ) if header_parts : header = ElementTree . Element ( '' ) header . tag = ( '{%s}Header' % NAMESPACE ) envelope . append ( header ) for part in header_parts : part . become_child_element_of ( header ) body = ElementTree . Element ( '' ) body . tag = ( '{%s}Body' % NAMESPACE ) envelope . append ( body ) if isinstance ( thingy , basestring ) : logger . debug ( ( 'thingy0: %s' % thingy ) ) _part = thingy . split ( '\n' ) thingy = '' . join ( _part [ 1 : ] ) thingy = thingy . replace ( PREFIX , '' ) logger . debug ( ( 'thingy: %s' % thingy ) ) _child = ElementTree . Element ( '' ) _child . tag = ( '{%s}FuddleMuddle' % DUMMY_NAMESPACE ) body . append ( _child ) _str = ElementTree . tostring ( envelope , encoding = 'UTF-8' ) logger . debug ( ( 'SOAP precursor: %s' % _str ) ) i = _str . find ( DUMMY_NAMESPACE ) j = _str . rfind ( 'xmlns:' , 0 , i ) cut1 = _str [ j : ( ( i + len ( DUMMY_NAMESPACE ) ) + 1 ) ] _str = _str . replace ( cut1 , '' ) first = _str . find ( ( '<%s:FuddleMuddle' % ( cut1 [ 6 : 9 ] , ) ) ) last = _str . find ( '>' , ( first + 14 ) ) cut2 = _str [ first : ( last + 1 ) ] return _str . replace ( cut2 , thingy ) else : thingy . become_child_element_of ( body ) return ElementTree . tostring ( envelope , encoding = 'UTF-8' )
returns a soap envelope containing a saml request as a text string .