paulb@302 | 1 | #!/usr/bin/env python |
paulb@302 | 2 | |
paulb@302 | 3 | """ |
paulb@318 | 4 | SOAP support using libxml2dom. Support for the archaic SOAP namespaces is also |
paulb@318 | 5 | provided. |
paulb@302 | 6 | |
paulb@302 | 7 | See: http://www.w3.org/TR/2007/REC-soap12-part0-20070427/ |
paulb@302 | 8 | |
paul@366 | 9 | Copyright (C) 2007, 2008, 2014 Paul Boddie <paul@boddie.org.uk> |
paulb@302 | 10 | |
paulb@302 | 11 | This program is free software; you can redistribute it and/or modify it under |
paulb@302 | 12 | the terms of the GNU Lesser General Public License as published by the Free |
paulb@302 | 13 | Software Foundation; either version 3 of the License, or (at your option) any |
paulb@302 | 14 | later version. |
paulb@302 | 15 | |
paulb@302 | 16 | This program is distributed in the hope that it will be useful, but WITHOUT |
paulb@302 | 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paulb@302 | 18 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
paulb@302 | 19 | details. |
paulb@302 | 20 | |
paulb@302 | 21 | You should have received a copy of the GNU Lesser General Public License along |
paulb@302 | 22 | with this program. If not, see <http://www.gnu.org/licenses/>. |
paulb@302 | 23 | |
paulb@302 | 24 | -------- |
paulb@302 | 25 | |
paulb@302 | 26 | The sending and receiving of SOAP messages can be done using traditional HTTP |
paulb@302 | 27 | libraries. |
paulb@302 | 28 | |
paul@345 | 29 | See tests/test_soap.py for more details. |
paulb@302 | 30 | """ |
paulb@302 | 31 | |
paulb@302 | 32 | import libxml2dom |
paulb@302 | 33 | from libxml2dom.macrolib import * |
paulb@302 | 34 | from libxml2dom.macrolib import \ |
paulb@302 | 35 | createDocument as Node_createDocument |
paul@345 | 36 | from libxml2dom.values import ContentValue, SequenceValue |
paulb@302 | 37 | |
paulb@302 | 38 | # SOAP-related namespaces. |
paulb@302 | 39 | |
paulb@302 | 40 | SOAP_ENVELOPE_NAMESPACE = "http://www.w3.org/2003/05/soap-envelope" |
paulb@302 | 41 | SOAP_ENCODING_NAMESPACE = "http://www.w3.org/2003/05/soap-encoding" |
paulb@302 | 42 | SOAP_RPC_NAMESPACE = "http://www.w3.org/2003/05/soap-rpc" |
paulb@302 | 43 | XS_NAMESPACE = "http://www.w3.org/2001/XMLSchema" |
paulb@302 | 44 | XSI_NAMESPACE = "http://www.w3.org/2001/XMLSchema-instance" |
paulb@302 | 45 | |
paulb@318 | 46 | # Archaic namespaces. |
paulb@318 | 47 | |
paulb@318 | 48 | OLD_SOAP_ENVELOPE_NAMESPACE = "http://schemas.xmlsoap.org/soap/envelope/" |
paulb@318 | 49 | OLD_SOAP_ENCODING_NAMESPACE = "http://schemas.xmlsoap.org/soap/encoding/" |
paulb@318 | 50 | |
paulb@302 | 51 | # Default namespace bindings for XPath. |
paulb@302 | 52 | |
paulb@302 | 53 | default_ns = { |
paulb@302 | 54 | "env" : SOAP_ENVELOPE_NAMESPACE, |
paulb@302 | 55 | "enc" : SOAP_ENCODING_NAMESPACE, |
paulb@302 | 56 | "rpc" : SOAP_RPC_NAMESPACE, |
paulb@302 | 57 | "xs" : XS_NAMESPACE, |
paulb@318 | 58 | "xsi" : XSI_NAMESPACE, |
paulb@318 | 59 | "SOAP-ENV" : OLD_SOAP_ENVELOPE_NAMESPACE, |
paulb@318 | 60 | "SOAP-ENC" : OLD_SOAP_ENCODING_NAMESPACE |
paulb@302 | 61 | } |
paulb@302 | 62 | |
paulb@302 | 63 | # Node classes. |
paulb@302 | 64 | |
paulb@302 | 65 | class SOAPNode(libxml2dom.Node): |
paulb@302 | 66 | |
paulb@302 | 67 | "Convenience modifications to nodes specific to libxml2dom.soap." |
paulb@302 | 68 | |
paul@345 | 69 | def add_or_replace_element(self, new_element): |
paul@345 | 70 | |
paul@345 | 71 | """ |
paul@345 | 72 | Add or replace the given 'new_element', using its localName to find any |
paul@345 | 73 | element to be replaced. |
paul@345 | 74 | """ |
paul@345 | 75 | |
paul@345 | 76 | elements = self.xpath(new_element.localName) |
paul@345 | 77 | if elements: |
paul@345 | 78 | self.replaceChild(new_element, elements[0]) |
paul@345 | 79 | else: |
paul@345 | 80 | self.appendChild(new_element) |
paul@345 | 81 | |
paul@345 | 82 | class SOAPElement(ContentValue, SequenceValue, SOAPNode): |
paul@345 | 83 | |
paul@345 | 84 | "A SOAP element." |
paulb@315 | 85 | |
paulb@315 | 86 | def convert(self, node): |
paulb@315 | 87 | return node.textContent.strip() |
paulb@315 | 88 | |
paul@345 | 89 | def values(self): |
paul@345 | 90 | return [v.contents for v in self.xpath("*")] |
paul@345 | 91 | |
paulb@315 | 92 | def _contents(self): |
paulb@318 | 93 | # NOTE: Should check whether this should be a leaf element. |
paulb@315 | 94 | if not self.xpath("*"): |
paulb@315 | 95 | return (self.localName, getattr(self.ownerDocument, "convert", self.convert)(self)) |
paulb@315 | 96 | else: |
paul@345 | 97 | return (self.localName, self) |
paulb@315 | 98 | |
paulb@315 | 99 | def __len__(self): |
paul@345 | 100 | if not self.xpath("*"): |
paul@345 | 101 | return 2 |
paul@345 | 102 | else: |
paul@345 | 103 | return SequenceValue.__len__(self) |
paulb@315 | 104 | |
paulb@315 | 105 | def __eq__(self, other): |
paul@345 | 106 | if not self.xpath("*"): |
paul@345 | 107 | return ContentValue.__eq__(self, other) |
paulb@315 | 108 | else: |
paul@345 | 109 | return SequenceValue.__eq__(self, other) |
paul@345 | 110 | |
paul@345 | 111 | def __ne__(self, other): |
paul@345 | 112 | if not self.xpath("*"): |
paul@345 | 113 | return ContentValue.__ne__(self, other) |
paul@345 | 114 | else: |
paul@345 | 115 | return SequenceValue.__ne__(self, other) |
paul@345 | 116 | |
paul@345 | 117 | def __repr__(self): |
paul@345 | 118 | if self.contents[1] is self: |
paul@345 | 119 | return "<%s: %r>" % (self.__class__.__name__, self.values()) |
paul@345 | 120 | else: |
paul@345 | 121 | return "<%s: %r>" % (self.__class__.__name__, self.contents) |
paulb@315 | 122 | |
paulb@318 | 123 | # Node construction methods. |
paulb@318 | 124 | |
paul@348 | 125 | def createSOAPElement(self, localName): |
paulb@318 | 126 | |
paulb@318 | 127 | "Create an element with the appropriate namespace and prefix." |
paulb@318 | 128 | |
paulb@318 | 129 | ref_element = self.ownerDocument.documentElement |
paulb@318 | 130 | prefix = ref_element.prefix |
paulb@318 | 131 | if prefix: |
paulb@318 | 132 | name = prefix + ":" + localName |
paulb@318 | 133 | else: |
paulb@318 | 134 | name = localName |
paul@348 | 135 | return self.createElementNS(ref_element.namespaceURI, name) |
paul@348 | 136 | |
paul@348 | 137 | def makeSOAPElement(self, localName): |
paul@348 | 138 | |
paul@348 | 139 | """ |
paul@348 | 140 | Create and insert an element with the appropriate namespace and prefix. |
paul@348 | 141 | """ |
paul@348 | 142 | |
paul@348 | 143 | element = self.createSOAPElement(localName) |
paul@348 | 144 | self.appendChild(element) |
paul@345 | 145 | return element |
paulb@318 | 146 | |
paulb@315 | 147 | contents = property(_contents) |
paulb@315 | 148 | |
paulb@302 | 149 | class SOAPDocument(libxml2dom._Document, SOAPNode): |
paulb@302 | 150 | |
paulb@302 | 151 | "A SOAP document fragment." |
paulb@302 | 152 | |
paul@366 | 153 | def __init__(self, node, impl, namespaces=None): |
paul@366 | 154 | |
paul@366 | 155 | """ |
paul@366 | 156 | Initialise the document with the given 'node', implementation 'impl', |
paul@366 | 157 | and 'namespaces' details. |
paul@366 | 158 | """ |
paul@366 | 159 | |
paul@366 | 160 | libxml2dom._Document.__init__(self, node, impl, None) |
paul@366 | 161 | self._update_namespaces([default_ns, namespaces]) |
paul@366 | 162 | |
paulb@302 | 163 | def _envelope(self): |
paul@345 | 164 | return (self.xpath("env:Envelope|SOAP-ENV:Envelope") or [None])[0] |
paulb@302 | 165 | |
paulb@302 | 166 | envelope = property(_envelope) |
paulb@302 | 167 | |
paulb@307 | 168 | # Convenience methods and properties. |
paulb@307 | 169 | |
paulb@307 | 170 | def _fault(self): |
paul@345 | 171 | if self.envelope is not None: |
paul@345 | 172 | return self.envelope.fault |
paul@345 | 173 | else: |
paul@345 | 174 | return None |
paulb@307 | 175 | |
paulb@309 | 176 | def _method(self): |
paul@345 | 177 | if self.envelope is not None: |
paul@345 | 178 | return self.envelope.method |
paul@345 | 179 | else: |
paul@345 | 180 | return None |
paulb@309 | 181 | |
paulb@307 | 182 | fault = property(_fault) |
paulb@309 | 183 | method = property(_method) |
paulb@307 | 184 | |
paul@345 | 185 | class SOAPEnvelopeElement(SOAPElement): |
paulb@302 | 186 | |
paulb@302 | 187 | "A SOAP envelope element." |
paulb@302 | 188 | |
paulb@302 | 189 | def _body(self): |
paul@345 | 190 | return (self.xpath("env:Body|SOAP-ENV:Body") or [None])[0] |
paulb@302 | 191 | |
paulb@302 | 192 | def _setBody(self, body): |
paulb@302 | 193 | self.appendChild(body) |
paulb@302 | 194 | |
paulb@302 | 195 | def _delBody(self): |
paulb@302 | 196 | self.removeChild(self.body) |
paulb@302 | 197 | |
paul@345 | 198 | # Convenience methods and properties. |
paul@345 | 199 | |
paul@345 | 200 | def _fault(self): |
paul@345 | 201 | if self.body is not None: |
paul@345 | 202 | return self.body.fault |
paul@345 | 203 | else: |
paul@345 | 204 | return None |
paul@345 | 205 | |
paul@345 | 206 | def _method(self): |
paul@345 | 207 | if self.body is not None: |
paul@345 | 208 | return self.body.method |
paul@345 | 209 | else: |
paul@345 | 210 | return None |
paul@345 | 211 | |
paul@345 | 212 | fault = property(_fault) |
paul@345 | 213 | method = property(_method) |
paul@345 | 214 | |
paul@345 | 215 | # Node construction methods. |
paul@345 | 216 | |
paul@348 | 217 | def createBody(self): |
paul@348 | 218 | return self.createSOAPElement("Body") |
paul@348 | 219 | |
paul@348 | 220 | def makeBody(self): |
paul@348 | 221 | element = self.createBody() |
paul@348 | 222 | self.add_or_replace_element(element) |
paul@345 | 223 | return element |
paulb@302 | 224 | |
paulb@302 | 225 | body = property(_body, _setBody, _delBody) |
paulb@302 | 226 | |
paul@345 | 227 | class SOAPHeaderElement(SOAPElement): |
paulb@302 | 228 | |
paulb@302 | 229 | "A SOAP header element." |
paulb@302 | 230 | |
paulb@302 | 231 | pass |
paulb@302 | 232 | |
paul@345 | 233 | class SOAPBodyElement(SOAPElement): |
paulb@302 | 234 | |
paulb@302 | 235 | "A SOAP body element." |
paulb@302 | 236 | |
paulb@302 | 237 | def _fault(self): |
paulb@318 | 238 | return (self.xpath("env:Fault|SOAP-ENV:Fault") or [None])[0] |
paulb@302 | 239 | |
paulb@302 | 240 | def _method(self): |
paulb@318 | 241 | if self.namespaceURI == SOAP_ENVELOPE_NAMESPACE: |
paulb@318 | 242 | return (self.xpath("*[@env:encodingStyle = '%s']" % SOAP_ENCODING_NAMESPACE) or [None])[0] |
paulb@318 | 243 | else: |
paulb@318 | 244 | return (self.xpath("*") or [None])[0] |
paulb@302 | 245 | |
paulb@309 | 246 | # Node construction methods. |
paulb@309 | 247 | |
paul@348 | 248 | def createMethod(self, namespaceURI, name): |
paul@345 | 249 | if self.method is not None: |
paul@345 | 250 | self.removeChild(self.method) |
paul@345 | 251 | element = self.createElementNS(namespaceURI, name) |
paul@345 | 252 | element.setAttributeNS(SOAP_ENVELOPE_NAMESPACE, "env:encodingStyle", SOAP_ENCODING_NAMESPACE) |
paul@348 | 253 | return element |
paul@348 | 254 | |
paul@348 | 255 | def makeMethod(self, namespaceURI, name): |
paul@348 | 256 | element = self.createMethod(namespaceURI, name) |
paul@345 | 257 | self.appendChild(element) |
paul@345 | 258 | return element |
paul@345 | 259 | |
paul@348 | 260 | def createFault(self): |
paul@348 | 261 | return self.createSOAPElement("Fault") |
paul@348 | 262 | |
paul@348 | 263 | def makeFault(self): |
paul@348 | 264 | element = self.createFault() |
paul@348 | 265 | self.add_or_replace_element(element) |
paul@345 | 266 | return element |
paulb@309 | 267 | |
paulb@309 | 268 | fault = property(_fault) |
paulb@309 | 269 | method = property(_method) |
paulb@309 | 270 | |
paul@345 | 271 | class SOAPMethodElement(SOAPElement): |
paulb@309 | 272 | |
paulb@309 | 273 | "A SOAP method element." |
paulb@309 | 274 | |
paulb@302 | 275 | def _methodName(self): |
paulb@309 | 276 | return self.localName |
paulb@302 | 277 | |
paulb@302 | 278 | def _resultParameter(self): |
paulb@309 | 279 | return (self.xpath(".//rpc:result") or [None])[0] |
paulb@302 | 280 | |
paulb@302 | 281 | def _resultParameterValue(self): |
paulb@307 | 282 | if self.resultParameter: |
paulb@307 | 283 | name = self.resultParameter.textContent.strip() |
paulb@315 | 284 | result = self.xpath(".//" + name, namespaces={self.prefix : self.namespaceURI}) |
paulb@307 | 285 | if result: |
paulb@307 | 286 | return result[0].textContent.strip() |
paulb@307 | 287 | else: |
paulb@307 | 288 | return None |
paulb@307 | 289 | else: |
paulb@307 | 290 | return None |
paulb@302 | 291 | |
paul@345 | 292 | def _parameters(self): |
paul@345 | 293 | return self.xpath("*") |
paul@345 | 294 | |
paulb@314 | 295 | def _parameterValues(self): |
paul@345 | 296 | return self.values() |
paul@345 | 297 | |
paul@345 | 298 | def __repr__(self): |
paul@345 | 299 | return "<SOAPMethodElement: %r>" % self.parameters |
paulb@302 | 300 | |
paulb@302 | 301 | methodName = property(_methodName) |
paulb@302 | 302 | resultParameter = property(_resultParameter) |
paulb@302 | 303 | resultParameterValue = property(_resultParameterValue) |
paulb@315 | 304 | parameterValues = property(_parameterValues) |
paul@345 | 305 | parameters = property(_parameters) |
paulb@302 | 306 | |
paul@345 | 307 | class SOAPFaultElement(SOAPElement): |
paulb@302 | 308 | |
paulb@302 | 309 | "A SOAP fault element." |
paulb@302 | 310 | |
paulb@302 | 311 | def _code(self): |
paulb@318 | 312 | code = self.xpath("env:Code|SOAP-ENV:Code") |
paulb@307 | 313 | if code: |
paulb@307 | 314 | return code[0].value |
paulb@307 | 315 | else: |
paulb@307 | 316 | return None |
paulb@307 | 317 | |
paulb@307 | 318 | def _subcode(self): |
paulb@318 | 319 | subcode = self.xpath("./env:Code/env:Subcode|./SOAP-ENV:Code/SOAP-ENV:Subcode") |
paulb@307 | 320 | if subcode: |
paulb@307 | 321 | return subcode[0].value |
paulb@307 | 322 | else: |
paulb@307 | 323 | return None |
paulb@302 | 324 | |
paulb@302 | 325 | def _reason(self): |
paulb@318 | 326 | return (self.xpath("env:Reason|SOAP-ENV:Reason") or [None])[0] |
paulb@302 | 327 | |
paulb@302 | 328 | def _detail(self): |
paulb@318 | 329 | return (self.xpath("env:Detail|SOAP-ENV:Detail") or [None])[0] |
paulb@302 | 330 | |
paul@345 | 331 | # Node construction methods. |
paul@345 | 332 | |
paul@348 | 333 | def createCode(self): |
paul@348 | 334 | return self.createSOAPElement("Code") |
paul@348 | 335 | |
paul@348 | 336 | def makeCode(self): |
paul@348 | 337 | element = self.createCode() |
paul@348 | 338 | self.add_or_replace_element(element) |
paul@345 | 339 | return element |
paulb@302 | 340 | |
paulb@302 | 341 | code = property(_code) |
paulb@307 | 342 | subcode = property(_subcode) |
paulb@302 | 343 | reason = property(_reason) |
paulb@302 | 344 | detail = property(_detail) |
paulb@302 | 345 | |
paul@345 | 346 | class SOAPSubcodeElement(SOAPElement): |
paulb@302 | 347 | |
paulb@302 | 348 | "A SOAP subcode element." |
paulb@302 | 349 | |
paulb@302 | 350 | def _value(self): |
paulb@318 | 351 | value = self.xpath("env:Value|SOAP-ENV:Value") |
paulb@307 | 352 | if value: |
paulb@307 | 353 | return value[0].textContent.strip() |
paulb@307 | 354 | else: |
paulb@307 | 355 | return None |
paulb@304 | 356 | |
paulb@304 | 357 | def _setValue(self, value): |
paulb@318 | 358 | nodes = self.xpath("env:Value|SOAP-ENV:Value") |
paulb@304 | 359 | v = self.createValue() |
paulb@304 | 360 | if nodes: |
paulb@304 | 361 | self.replaceChild(v, nodes[0]) |
paulb@304 | 362 | else: |
paulb@304 | 363 | self.appendChild(v) |
paulb@304 | 364 | v.value = value |
paulb@302 | 365 | |
paul@345 | 366 | # Node construction methods. |
paul@345 | 367 | |
paul@348 | 368 | def createValue(self, value=None): |
paulb@318 | 369 | code_value = self.createSOAPElement("Value") |
paulb@302 | 370 | if value is not None: |
paulb@302 | 371 | code_value.value = code |
paul@348 | 372 | return code_value |
paul@348 | 373 | |
paul@348 | 374 | def makeValue(self, value=None): |
paul@348 | 375 | code_value = self.createValue(value) |
paul@348 | 376 | self.add_or_replace_element(code_value) |
paulb@302 | 377 | return code_value |
paulb@302 | 378 | |
paulb@304 | 379 | value = property(_value, _setValue) |
paulb@302 | 380 | |
paulb@302 | 381 | class SOAPCodeElement(SOAPSubcodeElement): |
paulb@302 | 382 | |
paulb@302 | 383 | "A SOAP code element." |
paulb@302 | 384 | |
paulb@302 | 385 | def _subcode(self): |
paulb@318 | 386 | return (self.xpath("env:Subcode|SOAP-ENV:Subcode") or [None])[0] |
paulb@302 | 387 | |
paul@345 | 388 | # Node construction methods. |
paul@345 | 389 | |
paul@348 | 390 | def createSubcode(self): |
paul@348 | 391 | return self.createSOAPElement("Subcode") |
paul@348 | 392 | |
paul@348 | 393 | def makeSubcode(self): |
paul@348 | 394 | element = self.createSubcode() |
paul@348 | 395 | self.add_or_replace_element(element) |
paul@345 | 396 | return element |
paulb@302 | 397 | |
paulb@302 | 398 | subcode = property(_subcode) |
paulb@302 | 399 | |
paul@345 | 400 | class SOAPValueElement(SOAPElement): |
paulb@302 | 401 | |
paulb@302 | 402 | "A SOAP value element." |
paulb@302 | 403 | |
paulb@302 | 404 | def _value(self): |
paulb@302 | 405 | return self.textContent |
paulb@302 | 406 | |
paulb@302 | 407 | def _setValue(self, value): |
paulb@302 | 408 | for node in self.childNodes: |
paulb@302 | 409 | self.removeChild(node) |
paulb@302 | 410 | text = self.ownerDocument.createTextNode(value) |
paulb@302 | 411 | self.appendChild(text) |
paulb@302 | 412 | |
paulb@302 | 413 | value = property(_value, _setValue) |
paulb@302 | 414 | |
paulb@302 | 415 | class SOAPTextElement(SOAPValueElement): |
paulb@302 | 416 | |
paulb@302 | 417 | "A SOAP text element." |
paulb@302 | 418 | |
paulb@302 | 419 | def _lang(self): |
paulb@302 | 420 | return self.getAttributeNS(libxml2dom.XML_NAMESPACE, "lang") |
paulb@302 | 421 | |
paulb@302 | 422 | def _setLang(self, value): |
paulb@302 | 423 | self.setAttributeNS(libxml2dom.XML_NAMESPACE, "xml:lang", value) |
paulb@302 | 424 | |
paulb@302 | 425 | lang = property(_lang, _setLang) |
paulb@302 | 426 | |
paul@345 | 427 | # Implementation-related functionality. |
paul@345 | 428 | |
paul@345 | 429 | class SOAPImplementation(libxml2dom.Implementation): |
paul@345 | 430 | |
paul@345 | 431 | "Contains a SOAP-specific implementation." |
paul@345 | 432 | |
paul@345 | 433 | # Mapping of element names to wrappers. |
paul@345 | 434 | |
paul@345 | 435 | _class_for_name = { |
paul@345 | 436 | "Envelope" : SOAPEnvelopeElement, |
paul@345 | 437 | "Header" : SOAPHeaderElement, |
paul@345 | 438 | "Body" : SOAPBodyElement, |
paul@345 | 439 | "Fault" : SOAPFaultElement, |
paul@345 | 440 | "Code" : SOAPCodeElement, |
paul@345 | 441 | "Subcode" : SOAPSubcodeElement, |
paul@345 | 442 | "Value" : SOAPValueElement, |
paul@345 | 443 | "Text" : SOAPTextElement |
paul@345 | 444 | } |
paul@345 | 445 | |
paul@345 | 446 | # Wrapping of documents. |
paul@345 | 447 | |
paul@345 | 448 | def adoptDocument(self, node): |
paul@345 | 449 | return SOAPDocument(node, self) |
paul@345 | 450 | |
paul@345 | 451 | # Factory functions. |
paul@345 | 452 | |
paul@345 | 453 | def get_node(self, _node, context_node): |
paul@345 | 454 | |
paul@345 | 455 | """ |
paul@345 | 456 | Get a libxml2dom node for the given low-level '_node' and libxml2dom |
paul@345 | 457 | 'context_node'. |
paul@345 | 458 | """ |
paul@345 | 459 | |
paul@345 | 460 | if Node_nodeType(_node) == context_node.ELEMENT_NODE: |
paul@345 | 461 | |
paul@345 | 462 | # Make special envelope elements. |
paul@345 | 463 | |
paul@345 | 464 | if Node_namespaceURI(_node) in (SOAP_ENVELOPE_NAMESPACE, OLD_SOAP_ENVELOPE_NAMESPACE): |
paul@345 | 465 | cls = self._class_for_name[Node_localName(_node)] |
paul@345 | 466 | return cls(_node, self, context_node.ownerDocument) |
paul@345 | 467 | |
paul@345 | 468 | # Detect the method element. |
paul@345 | 469 | |
paul@345 | 470 | if Node_parentNode(_node) and Node_localName(Node_parentNode(_node)) == "Body" and \ |
paul@345 | 471 | Node_namespaceURI(Node_parentNode(_node)) in (SOAP_ENVELOPE_NAMESPACE, OLD_SOAP_ENVELOPE_NAMESPACE): |
paul@345 | 472 | |
paul@345 | 473 | return SOAPMethodElement(_node, self, context_node.ownerDocument) |
paul@345 | 474 | |
paul@345 | 475 | # Otherwise, make generic SOAP elements. |
paul@345 | 476 | |
paul@345 | 477 | return SOAPElement(_node, self, context_node.ownerDocument) |
paul@345 | 478 | |
paul@345 | 479 | else: |
paul@345 | 480 | return libxml2dom.Implementation.get_node(self, _node, context_node) |
paul@345 | 481 | |
paul@345 | 482 | # Convenience functions. |
paul@345 | 483 | |
paul@345 | 484 | def createSOAPMessage(self): |
paul@345 | 485 | |
paul@345 | 486 | "Create a new SOAP message document (fragment)." |
paul@345 | 487 | |
paul@345 | 488 | return SOAPDocument(Node_createDocument(SOAP_ENVELOPE_NAMESPACE, "env:Envelope", None), self).documentElement |
paul@345 | 489 | |
paulb@302 | 490 | # Utility functions. |
paulb@302 | 491 | |
paulb@302 | 492 | createDocument = libxml2dom.createDocument |
paulb@302 | 493 | createDocumentType = libxml2dom.createDocumentType |
paulb@302 | 494 | |
paul@345 | 495 | def createSOAPMessage(): |
paul@345 | 496 | return default_impl.createSOAPMessage() |
paulb@302 | 497 | |
paulb@302 | 498 | def parse(stream_or_string, html=0, htmlencoding=None, unfinished=0, impl=None): |
paulb@302 | 499 | return libxml2dom.parse(stream_or_string, html=html, htmlencoding=htmlencoding, unfinished=unfinished, impl=(impl or default_impl)) |
paulb@302 | 500 | |
paulb@302 | 501 | def parseFile(filename, html=0, htmlencoding=None, unfinished=0, impl=None): |
paulb@302 | 502 | return libxml2dom.parseFile(filename, html=html, htmlencoding=htmlencoding, unfinished=unfinished, impl=(impl or default_impl)) |
paulb@302 | 503 | |
paulb@302 | 504 | def parseString(s, html=0, htmlencoding=None, unfinished=0, impl=None): |
paulb@302 | 505 | return libxml2dom.parseString(s, html=html, htmlencoding=htmlencoding, unfinished=unfinished, impl=(impl or default_impl)) |
paulb@302 | 506 | |
paulb@302 | 507 | def parseURI(uri, html=0, htmlencoding=None, unfinished=0, impl=None): |
paulb@302 | 508 | return libxml2dom.parseURI(uri, html=html, htmlencoding=htmlencoding, unfinished=unfinished, impl=(impl or default_impl)) |
paulb@302 | 509 | |
paulb@302 | 510 | # Single instance of the implementation. |
paulb@302 | 511 | |
paulb@302 | 512 | default_impl = SOAPImplementation() |
paulb@302 | 513 | |
paulb@302 | 514 | # vim: tabstop=4 expandtab shiftwidth=4 |