예제 #1
0
    def _createReturnsComplexType(self, result):
        """ Private method to generate the xml document with the response. 
		    Return an SoapMessage() with XML document.
		"""
        response = xml.dom.minidom.parseString(result.toXML())

        soapResponse = soap.SoapMessage()
        soapResponse.setBody(response)
        return soapResponse
예제 #2
0
def soapfault(faultstring):
    """ Method for generate a soap fault
	    soapfault() return a SoapMessage() object with a message 
	    for Soap Envelope
	 """
    fault = soap.SoapMessage()
    faultmsg = b'<soapenv:Fault xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope">\n'
    faultmsg += b'<faultcode></faultcode>\n'
    faultmsg += b'<faultstring>%s</faultstring>\n' % faultstring
    faultmsg += b'</soapenv:Fault>\n'
    fault.setBody(xml.dom.minidom.parseString(faultmsg))
    return fault
예제 #3
0
	def _parseSoap(self,xmldoc):
		""" Private method parse a message soap from a xmldoc like string
		    _parseSoap() return a soap.SoapMessage().
		"""
		xmldoc = xmldoc.replace('\n',' ').replace('\t',' ').replace('\r',' ')
		document = xml.dom.minidom.parseString(xmldoc)
		prefix = document.documentElement.prefix
		namespace = document.documentElement.namespaceURI
		
		header = self._getElementFromMessage('Header',document)
		body   = self._getElementFromMessage('Body',document)

		header_elements = self._parseXML(header)
		body_elements = self._parseXML(body)
		
		soapMsg = soap.SoapMessage()
		for h in header_elements:
			soapMsg.setHeader(h)
		for b in body_elements:
			soapMsg.setBody(b)
		return soapMsg
예제 #4
0
    def _createReturns(self, result, is_array):
        """ Private method to generate the xml document with the response. 
		    Return an SoapMessage().
		"""
        xmlresponse = b''
        if isinstance(result, list):
            xmlresponse = b'<returns>\n'
            i = 1
            for r in result:
                if is_array == True:
                    xmlresponse += b'<value>%s</value>\n' % str(r)
                else:
                    xmlresponse += b'<value%d>%s</value%d>\n' % (i, str(r), i)
                i += 1
            xmlresponse += b'</returns>\n'
        else:
            xmlresponse = b'<returns>%s</returns>\n' % str(result)

        response = xml.dom.minidom.parseString(xmlresponse)

        soapResponse = soap.SoapMessage()
        soapResponse.setBody(response)
        return soapResponse