def process_reply(self, client, operation, response): """Process the XML reply from the server. :param client: The client with which the operation was called :type client: zeep.client.Client :param operation: The operation object from which this is a reply :type operation: zeep.wsdl.definitions.Operation :param response: The response object returned by the remote server :type response: requests.Response """ if response.status_code != 200 and not response.content: raise TransportError( u'Server returned HTTP status %d (no content available)' % response.status_code) content = self.handle_xop(client, operation, response) try: doc = parse_xml(content, recover=True) except XMLSyntaxError: raise TransportError( u'Server returned HTTP status %d (%s)' % (response.status_code, content)) if client.wsse: client.wsse.verify(doc) doc, http_headers = plugins.apply_ingress( client, doc, response.headers, operation) if response.status_code != 200: return self.process_error(doc) return operation.process_reply(doc)
def process_reply(self, client, operation, response): """Process the XML reply from the server. :param client: The client with which the operation was called :type client: zeep.client.Client :param operation: The operation object from which this is a reply :type operation: zeep.wsdl.definitions.Operation :param response: The response object returned by the remote server :type response: requests.Response """ if response.status_code != 200 and not response.content: raise TransportError( u'Server returned HTTP status %d (no content available)' % response.status_code) try: doc = parse_xml(response.content, recover=True) except XMLSyntaxError: raise TransportError( u'Server returned HTTP status %d (%s)' % (response.status_code, response.content)) if client.wsse: client.wsse.verify(doc) doc, http_headers = plugins.apply_ingress( client, doc, response.headers, operation) if response.status_code != 200: return self.process_error(doc) return operation.process_reply(doc)
def process_reply(self, client, operation, response): """Process the XML reply from the server. :param client: The client with which the operation was called :type client: zeep.client.Client :param operation: The operation object from which this is a reply :type operation: zeep.wsdl.definitions.Operation :param response: The response object returned by the remote server :type response: requests.Response """ if response.status_code != 200 and not response.content: raise TransportError( u'Server returned HTTP status %d (no content available)' % response.status_code) content_type = response.headers.get('Content-Type', 'text/xml') media_type = get_media_type(content_type) if media_type == 'multipart/related': decoder = MultipartDecoder( response.content, content_type, response.encoding) content = decoder.parts[0].content if len(decoder.parts) > 1: message_pack = MessagePack(parts=decoder.parts[1:]) else: content = response.content message_pack = None try: doc = parse_xml(content, xml_huge_tree=client.xml_huge_tree) except XMLSyntaxError: raise TransportError( u'Server returned HTTP status %d (%s)' % (response.status_code, response.content)) if client.wsse: client.wsse.verify(doc) doc, http_headers = plugins.apply_ingress( client, doc, response.headers, operation) # If the response code is not 200 or if there is a Fault node available # then assume that an error occured. fault_node = doc.find( 'soap-env:Body/soap-env:Fault', namespaces=self.nsmap) if response.status_code != 200 or fault_node is not None: return self.process_error(doc, operation) result = operation.process_reply(doc) if message_pack: message_pack._set_root(result) return message_pack return result
def __init__(self, filename): self.types = {} self.schema_references = {} if filename.startswith(('http://', 'https://')): response = requests.get(filename) doc = parse_xml(response.content, self.schema_references) else: with open(filename) as fh: doc = parse_xml(fh.read(), self.schema_references) self.target_namespace = doc.get('targetNamespace') self.nsmap = doc.nsmap self.types = self.parse_types(doc) self.messages = self.parse_messages(doc) self.ports = self.parse_ports(doc) self.bindings = self.parse_binding(doc) self.services = self.parse_service(doc)
def _load_content(self, location): """Load the XML content from the given location and return an lxml.Element object. :param location: The URL of the document to load :type location: string """ if hasattr(location, 'read'): return parse_xml(location.read()) return load_external(location, self.transport, self.location)
def _parse_content(self, content, base_url=None): """Parse the content as XML and return the document. :param content: content to parse as XML :param content: string, file :param base_url: base url for loading referenced documents :param base_url: string """ return parse_xml( content, self.transport, self._parser_context, base_url)
def test_huge_text(): # libxml2>=2.7.3 has XML_MAX_TEXT_LENGTH 10000000 without XML_PARSE_HUGE tree = parse_xml(u""" <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Body> <HugeText xmlns="http://hugetext">%s</HugeText> </s:Body> </s:Envelope> """ % (u'\u00e5' * 10000001), xml_huge_tree=True) assert tree[0][0].text == u'\u00e5' * 10000001
def _parse_content(self, content, base_url=None): """Parse the content as XML and return the document. :param content: content to parse as XML :param content: string, file :param base_url: base url for loading referenced documents :param base_url: string """ return parse_xml(content, self.transport, self._parser_context, base_url)
def process_reply(self, client, operation, response): """Process the XML reply from the server. :param client: The client with which the operation was called :type client: zeep.client.Client :param operation: The operation object from which this is a reply :type operation: zeep.wsdl.definitions.Operation :param response: The response object returned by the remote server :type response: requests.Response """ if response.status_code != 200 and not response.content: raise TransportError( u'Server returned HTTP status %d (no content available)' % response.status_code) try: doc = parse_xml(response.content, recover=True) except XMLSyntaxError: raise TransportError( u'Server returned HTTP status %d (%s)' % (response.status_code, response.content)) if client.wsse: client.wsse.verify(doc) doc, http_headers = plugins.apply_ingress( client, doc, response.headers, operation) # If the response code is not 200 or if there is a Fault node available # then assume that an error occured. fault_node = doc.find( 'soap-env:Body/soap-env:Fault', namespaces=self.nsmap) if response.status_code != 200 or fault_node is not None: return self.process_error(doc, operation) return operation.process_reply(doc)
def _parse_content(self, content): return parse_xml(content, self.transport, self.schema_references)
def _parse_content(self, content, base_url=None): return parse_xml( content, self.transport, self._parser_context, base_url)
def _parse_content(self, content, base_url=None): return parse_xml(content, self.transport, self._parser_context, base_url)