def setBody(self, body, title='', is_error=0, bogus_str_search=None): if isinstance(body, Fault): # Convert Fault object to SOAP response. body = body.AsSOAP() else: # Marshall our body as an SOAP response. Strings will be sent # strings, integers as integers, etc. We do *not* convert # everything to a string first. try: target = self._method body = premarshal(body) result = body if hasattr(result, 'typecode'): tc = result.typecode else: tc = TC.Any(aslist=1, pname=target + 'Response') result = [result] sw = SoapWriter(nsdict={}, header=True, outputclass=None, encodingStyle=None) body = str(sw.serialize(result, tc)) Node.unlink(sw.dom.node) Node.unlink(sw.body.node) del sw.dom.node del sw.body.node del sw.dom del sw.body except: self.exception() return # Set our body to the message, and fix our MIME type. self._real.setBody(body) self._setHeader() return self
def setBody(self, body): """Sets the body of the response""" # A SOAP view can return a Fault directly to indicate an error. if isinstance(body, Fault): self._error = body if not self._error: try: target = self._request._target body = premarshal(body) output = StringIO() result = body if hasattr(result, 'typecode'): tc = result.typecode else: tc = TC.Any(aslist=1, pname=target + 'Response') result = [result] SoapWriter(output).serialize(result, tc) output.seek(0) if not self._status_set: self.setStatus(200) self.setHeader('content-type', 'text/xml') self._body = output.read() self._updateContentLength() return except Exception, e: self._error = ZSI.FaultFromException(e, 0)