1.1 --- a/libxml2dom/soap.py Sat Sep 29 22:42:56 2007 +0000
1.2 +++ b/libxml2dom/soap.py Sun Sep 30 00:55:20 2007 +0000
1.3 @@ -229,7 +229,16 @@
1.4 "A SOAP subcode element."
1.5
1.6 def _value(self):
1.7 - return self.xpath("./env:Value")[0]
1.8 + return self.xpath("./env:Value")[0].textContent.strip()
1.9 +
1.10 + def _setValue(self, value):
1.11 + nodes = self.xpath("./env:Value")
1.12 + v = self.createValue()
1.13 + if nodes:
1.14 + self.replaceChild(v, nodes[0])
1.15 + else:
1.16 + self.appendChild(v)
1.17 + v.value = value
1.18
1.19 def createValue(self, value=None):
1.20 code_value = self.ownerDocument.createElementNS(SOAP_ENVELOPE_NAMESPACE, "env:Value")
1.21 @@ -237,7 +246,7 @@
1.22 code_value.value = code
1.23 return code_value
1.24
1.25 - value = property(_value)
1.26 + value = property(_value, _setValue)
1.27
1.28 class SOAPCodeElement(SOAPSubcodeElement):
1.29
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/libxml2dom/xmlrpc.py Sun Sep 30 00:55:20 2007 +0000
2.3 @@ -0,0 +1,256 @@
2.4 +#!/usr/bin/env python
2.5 +
2.6 +"""
2.7 +XML-RPC support using libxml2dom.
2.8 +
2.9 +See: http://www.xmlrpc.com/spec
2.10 +
2.11 +Copyright (C) 2007 Paul Boddie <paul@boddie.org.uk>
2.12 +
2.13 +This program is free software; you can redistribute it and/or modify it under
2.14 +the terms of the GNU Lesser General Public License as published by the Free
2.15 +Software Foundation; either version 3 of the License, or (at your option) any
2.16 +later version.
2.17 +
2.18 +This program is distributed in the hope that it will be useful, but WITHOUT
2.19 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
2.20 +FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
2.21 +details.
2.22 +
2.23 +You should have received a copy of the GNU Lesser General Public License along
2.24 +with this program. If not, see <http://www.gnu.org/licenses/>.
2.25 +
2.26 +--------
2.27 +
2.28 +The sending and receiving of XML-RPC messages can be done using traditional HTTP
2.29 +libraries.
2.30 +
2.31 +See tests/xmlrpc_test.py for more details.
2.32 +"""
2.33 +
2.34 +import libxml2dom
2.35 +from libxml2dom.macrolib import *
2.36 +from libxml2dom.macrolib import \
2.37 + createDocument as Node_createDocument
2.38 +
2.39 +class XMLRPCImplementation(libxml2dom.Implementation):
2.40 +
2.41 + "Contains an XML-RPC-specific implementation."
2.42 +
2.43 + # Wrapping of documents.
2.44 +
2.45 + def adoptDocument(self, node):
2.46 + return XMLRPCDocument(node, self)
2.47 +
2.48 + # Factory functions.
2.49 +
2.50 + def get_node(self, _node, context_node):
2.51 +
2.52 + """
2.53 + Get a libxml2dom node for the given low-level '_node' and libxml2dom
2.54 + 'context_node'.
2.55 + """
2.56 +
2.57 + if Node_nodeType(_node) == context_node.ELEMENT_NODE:
2.58 +
2.59 + # Make special elements.
2.60 +
2.61 + if Node_localName(_node) in ("methodCall", "methodResponse"):
2.62 + return XMLRPCMethodElement(_node, self, context_node.ownerDocument)
2.63 + elif Node_localName(_node) == "methodName":
2.64 + return XMLRPCMethodNameElement(_node, self, context_node.ownerDocument)
2.65 + elif Node_localName(_node) == "fault":
2.66 + return XMLRPCFaultElement(_node, self, context_node.ownerDocument)
2.67 + elif Node_localName(_node) == "string":
2.68 + return XMLRPCStringElement(_node, self, context_node.ownerDocument)
2.69 + elif Node_localName(_node) in ("int", "i4"):
2.70 + return XMLRPCIntegerElement(_node, self, context_node.ownerDocument)
2.71 + elif Node_localName(_node) == "boolean":
2.72 + return XMLRPCBooleanElement(_node, self, context_node.ownerDocument)
2.73 + elif Node_localName(_node) == "double":
2.74 + return XMLRPCDoubleElement(_node, self, context_node.ownerDocument)
2.75 + elif Node_localName(_node) == "dateTime.iso8601":
2.76 + return XMLRPCDateTimeElement(_node, self, context_node.ownerDocument)
2.77 + elif Node_localName(_node) == "base64":
2.78 + return XMLRPCBase64Element(_node, self, context_node.ownerDocument)
2.79 + elif Node_localName(_node) == "struct":
2.80 + return XMLRPCStructElement(_node, self, context_node.ownerDocument)
2.81 + elif Node_localName(_node) == "member":
2.82 + return XMLRPCMemberElement(_node, self, context_node.ownerDocument)
2.83 +
2.84 + # Otherwise, make generic XML-RPC elements.
2.85 +
2.86 + return XMLRPCElement(_node, self, context_node.ownerDocument)
2.87 +
2.88 + else:
2.89 + return libxml2dom.Implementation.get_node(self, _node, context_node)
2.90 +
2.91 + # Convenience functions.
2.92 +
2.93 + def createXMLRPCMessage(self, namespaceURI, localName):
2.94 +
2.95 + "Create a new XML-RPC message document (fragment)."
2.96 +
2.97 + return XMLRPCDocument(Node_createDocument(namespaceURI, localName, None), self).documentElement
2.98 +
2.99 +# Node classes.
2.100 +
2.101 +class XMLRPCNode(libxml2dom.Node):
2.102 +
2.103 + "Convenience modifications to nodes specific to libxml2dom.xmlrpc."
2.104 +
2.105 + pass
2.106 +
2.107 +class XMLRPCDocument(libxml2dom._Document, XMLRPCNode):
2.108 +
2.109 + "An XML-RPC document fragment."
2.110 +
2.111 + def _method(self):
2.112 + return self.xpath("./methodCall|./methodResponse")[0]
2.113 +
2.114 + method = property(_method)
2.115 +
2.116 +class XMLRPCElement(XMLRPCNode):
2.117 +
2.118 + "An XML-RPC element."
2.119 +
2.120 + pass
2.121 +
2.122 +class XMLRPCMethodElement(XMLRPCNode):
2.123 +
2.124 + "An XML-RPC method element."
2.125 +
2.126 + def _fault(self):
2.127 + return self.xpath("./fault")[0]
2.128 +
2.129 + def _methodName(self):
2.130 + return self.xpath("./methodName")[0]
2.131 +
2.132 + def _parameters(self):
2.133 + return self.xpath("./params/param/value//*[not(./*)]")
2.134 +
2.135 + def _parameterValues(self):
2.136 + values = {}
2.137 + for parameter in self.parameters:
2.138 + values[(parameter.namespaceURI, parameter.localName)] = parameter.textContent.strip()
2.139 + return values
2.140 +
2.141 + def createFault(self):
2.142 + return self.ownerDocument.createElement("fault")
2.143 +
2.144 + fault = property(_fault)
2.145 + methodName = property(_methodName)
2.146 + parameters = property(_parameters)
2.147 + parameterValues = property(_parameterValues)
2.148 +
2.149 +class XMLRPCStringElement(XMLRPCNode):
2.150 +
2.151 + "An XML-RPC string element."
2.152 +
2.153 + def _value(self):
2.154 + return self.textContent.strip()
2.155 +
2.156 + def _setValue(self, value):
2.157 + for node in self.childNodes:
2.158 + self.removeChild(node)
2.159 + text = self.ownerDocument.createTextNode(value)
2.160 + self.appendChild(text)
2.161 +
2.162 + value = property(_value, _setValue)
2.163 +
2.164 +class XMLRPCMethodNameElement(XMLRPCStringElement):
2.165 +
2.166 + "An XML-RPC method element."
2.167 +
2.168 + pass
2.169 +
2.170 +class XMLRPCIntegerElement(XMLRPCStringElement):
2.171 +
2.172 + "An XML-RPC integer element."
2.173 +
2.174 + pass
2.175 +
2.176 +class XMLRPCBooleanElement(XMLRPCStringElement):
2.177 +
2.178 + "An XML-RPC boolean element."
2.179 +
2.180 + pass
2.181 +
2.182 +class XMLRPCDoubleElement(XMLRPCStringElement):
2.183 +
2.184 + "An XML-RPC double floating point number element."
2.185 +
2.186 + pass
2.187 +
2.188 +class XMLRPCDateTimeElement(XMLRPCStringElement):
2.189 +
2.190 + "An XML-RPC date/time element."
2.191 +
2.192 + pass
2.193 +
2.194 +class XMLRPCBase64Element(XMLRPCStringElement):
2.195 +
2.196 + "An XML-RPC integer element."
2.197 +
2.198 + pass
2.199 +
2.200 +class XMLRPCStructElement(XMLRPCNode):
2.201 +
2.202 + "An XML-RPC structure element."
2.203 +
2.204 + def _members(self):
2.205 + return self.xpath("./member")
2.206 +
2.207 + members = property(_members)
2.208 +
2.209 +class XMLRPCMemberElement(XMLRPCNode):
2.210 +
2.211 + "An XML-RPC structure member element."
2.212 +
2.213 + def _name(self):
2.214 + return self.xpath("./name")[0].textContent.strip()
2.215 +
2.216 + def _value(self):
2.217 + return self.xpath("./value")[0]
2.218 +
2.219 + name = property(_name)
2.220 + value = property(_value)
2.221 +
2.222 +class XMLRPCFaultElement(XMLRPCNode):
2.223 +
2.224 + "An XML-RPC fault element."
2.225 +
2.226 + def _code(self):
2.227 + return self.xpath("./value/struct/member[./name/text() = 'faultCode']/value/int")[0]
2.228 +
2.229 + def _reason(self):
2.230 + return self.xpath("./value/struct/member[./name/text() = 'faultString']/value/string")[0]
2.231 +
2.232 + code = property(_code)
2.233 + reason = property(_reason)
2.234 +
2.235 +# Utility functions.
2.236 +
2.237 +createDocument = libxml2dom.createDocument
2.238 +createDocumentType = libxml2dom.createDocumentType
2.239 +
2.240 +def createXMLRPCMessage(namespaceURI, localName):
2.241 + return default_impl.createXMLRPCMessage(namespaceURI, localName)
2.242 +
2.243 +def parse(stream_or_string, html=0, htmlencoding=None, unfinished=0, impl=None):
2.244 + return libxml2dom.parse(stream_or_string, html=html, htmlencoding=htmlencoding, unfinished=unfinished, impl=(impl or default_impl))
2.245 +
2.246 +def parseFile(filename, html=0, htmlencoding=None, unfinished=0, impl=None):
2.247 + return libxml2dom.parseFile(filename, html=html, htmlencoding=htmlencoding, unfinished=unfinished, impl=(impl or default_impl))
2.248 +
2.249 +def parseString(s, html=0, htmlencoding=None, unfinished=0, impl=None):
2.250 + return libxml2dom.parseString(s, html=html, htmlencoding=htmlencoding, unfinished=unfinished, impl=(impl or default_impl))
2.251 +
2.252 +def parseURI(uri, html=0, htmlencoding=None, unfinished=0, impl=None):
2.253 + return libxml2dom.parseURI(uri, html=html, htmlencoding=htmlencoding, unfinished=unfinished, impl=(impl or default_impl))
2.254 +
2.255 +# Single instance of the implementation.
2.256 +
2.257 +default_impl = XMLRPCImplementation()
2.258 +
2.259 +# vim: tabstop=4 expandtab shiftwidth=4