def serialize(self, *args, **kwargs): """Create a SerializedMessage for this message""" nsmap = {'soap-env': self.nsmap['soap-env']} nsmap.update(self.wsdl.types._prefix_map_custom) soap = ElementMaker(namespace=self.nsmap['soap-env'], nsmap=nsmap) # Create the soap:header element headers_value = kwargs.pop('_soapheaders', None) header = self._serialize_header(headers_value, nsmap) # Create the soap:body element body = soap.Body() if self.body: body_value = self.body(*args, **kwargs) self.body.render(body, body_value) # Create the soap:envelope envelope = soap.Envelope() if header is not None: envelope.append(header) envelope.append(body) # XXX: This is only used in Soap 1.1 so should be moved to the the # Soap11Binding._set_http_headers(). But let's keep it like this for # now. headers = {'SOAPAction': '"%s"' % self.operation.soapaction} return SerializedMessage(path=None, headers=headers, content=envelope)
def serialize(self, *args, **kwargs): params = {key: None for key in self.abstract.parts.keys()} params.update(zip(self.abstract.parts.keys(), args)) params.update(kwargs) headers = {'Content-Type': 'text/xml; charset=utf-8'} return SerializedMessage(path=self.operation.location, headers=headers, content=params)
def serialize(self, *args, **kwargs): params = {key: None for key in self.abstract.parts.keys()} params.update(zip(self.abstract.parts.keys(), args)) params.update(kwargs) headers = {'Content-Type': 'text/xml; charset=utf-8'} path = self.operation.location for key, value in params.items(): path = path.replace('(%s)' % key, value if value is not None else '') return SerializedMessage(path=path, headers=headers, content='')
def serialize(self, *args, **kwargs): value = self.body(*args, **kwargs) headers = {"Content-Type": self.content_type} data = "" if self.content_type == "application/x-www-form-urlencoded": items = serialize_object(value) data = six.moves.urllib.parse.urlencode(items) elif self.content_type == "text/xml": document = etree.Element("root") self.body.render(document, value) data = etree_to_string(list(document)[0]) return SerializedMessage(path=self.operation.location, headers=headers, content=data)
def serialize(self, *args, **kwargs): value = self.body(*args, **kwargs) headers = {'Content-Type': self.content_type} data = '' if self.content_type == 'application/x-www-form-urlencoded': items = serialize_object(value) data = six.moves.urllib.parse.urlencode(items) elif self.content_type == 'text/xml': document = etree.Element('root') self.body.render(document, value) data = etree_to_string(document.getchildren()[0]) return SerializedMessage(path=self.operation.location, headers=headers, content=data)
def serialize(self, *args, **kwargs): """Create a SerializedMessage for this message""" if 'soap' not in self.wsdl.types._prefix_map_custom: nsmap = {"soap-env": self.nsmap["soap-env"]} else: nsmap = {} nsmap.update(self.wsdl.types._prefix_map_custom) soap = ElementMaker(namespace=self.nsmap["soap-env"], nsmap=nsmap) # Create the soap:envelope envelope = soap.Envelope() # Create the soap:header element headers_value = kwargs.pop("_soapheaders", None) header = self._serialize_header(headers_value, nsmap) if header is not None: envelope.append(header) # Create the soap:body element. The _is_body_wrapped attribute signals # that the self.body element is of type soap:body, so we don't have to # create it in that case. Otherwise we create a Element soap:body and # render the content into this. if self.body: body_value = self.body(*args, **kwargs) if self._is_body_wrapped: self.body.render(envelope, body_value) else: body = soap.Body() envelope.append(body) self.body.render(body, body_value) else: body = soap.Body() envelope.append(body) # XXX: This is only used in Soap 1.1 so should be moved to the the # Soap11Binding._set_http_headers(). But let's keep it like this for # now. headers = {"SOAPAction": '"%s"' % self.operation.soapaction} return SerializedMessage(path=None, headers=headers, content=envelope)