1.1 --- a/libxml2dom/rpc.py Sat Oct 06 20:46:13 2007 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,112 +0,0 @@
1.4 -#!/usr/bin/env python
1.5 -
1.6 -"""
1.7 -Conversion functions and data used by XML-RPC and SOAP.
1.8 -
1.9 -Copyright (C) 2007 Paul Boddie <paul@boddie.org.uk>
1.10 -
1.11 -This program is free software; you can redistribute it and/or modify it under
1.12 -the terms of the GNU Lesser General Public License as published by the Free
1.13 -Software Foundation; either version 3 of the License, or (at your option) any
1.14 -later version.
1.15 -
1.16 -This program is distributed in the hope that it will be useful, but WITHOUT
1.17 -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.18 -FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
1.19 -details.
1.20 -
1.21 -You should have received a copy of the GNU Lesser General Public License along
1.22 -with this program. If not, see <http://www.gnu.org/licenses/>.
1.23 -"""
1.24 -
1.25 -import datetime
1.26 -
1.27 -# Utility classes.
1.28 -
1.29 -class ParameterName(object):
1.30 -
1.31 - "A method parameter name."
1.32 -
1.33 - def __init__(self, ns, name):
1.34 - self.ns = ns
1.35 - self.name = name
1.36 -
1.37 - def __eq__(self, other):
1.38 - return self.ns, to_localName(self.name) == other.ns, to_localName(other.name)
1.39 -
1.40 - def __hash__(self):
1.41 - return hash(self.ns + to_localName(self.name))
1.42 -
1.43 - def __repr__(self):
1.44 - return "ParameterName(%s, %s)" % (repr(self.ns), repr(self.name or None))
1.45 -
1.46 -class ParameterValue(object):
1.47 -
1.48 - "A method parameter value."
1.49 -
1.50 - def __init__(self, name, value):
1.51 - self.name = name
1.52 - self.value = value
1.53 -
1.54 - def convert(self, converters=None):
1.55 - conv = default_converters
1.56 - conv.update(converters or {})
1.57 - typename = self.name.ns
1.58 - localName = to_localName(self.name.name)
1.59 - if isinstance(self.value, list):
1.60 - return [item.convert(converters) for item in self.value]
1.61 - else:
1.62 - functions = conv.get(typename, {})
1.63 - function = functions.get(localName) or functions.get(None, unicode)
1.64 - return function(self.value)
1.65 -
1.66 - def _data(self):
1.67 - return self.convert()
1.68 -
1.69 - data = property(_data)
1.70 -
1.71 - def __eq__(self, other):
1.72 - return self.name == other.name and self.value == other.value
1.73 -
1.74 - def __hash__(self):
1.75 - return hash(self.value)
1.76 -
1.77 - def __repr__(self):
1.78 - return "ParameterValue(%s, %s)" % (repr(self.name), repr(self.value))
1.79 -
1.80 - # Sequence emulation.
1.81 -
1.82 - def __len__(self):
1.83 - return len(self.value)
1.84 -
1.85 - def __getitem__(self, i):
1.86 - return self.value[i]
1.87 -
1.88 -def to_localName(name):
1.89 - return (name or "").split(":")[-1] or None
1.90 -
1.91 -# Utility functions.
1.92 -
1.93 -def boolean(s):
1.94 - if s.lower() == "true":
1.95 - return True
1.96 - elif s.lower() == "false":
1.97 - return False
1.98 - else:
1.99 - raise ValueError, "String value %s not convertable to boolean." % repr(s)
1.100 -
1.101 -def iso8601(s):
1.102 - # NOTE: To be written.
1.103 - return s
1.104 -
1.105 -default_converters = {
1.106 - "string" : {None : unicode},
1.107 - "int" : {None : int},
1.108 - "i4" : {None : int},
1.109 - "double" : {None : float},
1.110 - "boolean" : {None : boolean},
1.111 - "dateTime.iso8601" : {None : iso8601},
1.112 - "base64" : {None : str}
1.113 - }
1.114 -
1.115 -# vim: tabstop=4 expandtab shiftwidth=4