1.1 --- a/libxml2dom/rpc.py Sat Oct 06 19:33:47 2007 +0000
1.2 +++ b/libxml2dom/rpc.py Sat Oct 06 20:46:13 2007 +0000
1.3 @@ -32,8 +32,7 @@
1.4 self.name = name
1.5
1.6 def __eq__(self, other):
1.7 - other_ns, other_name = other
1.8 - return self.ns, to_localName(self.name) == other_ns, to_localName(other_name)
1.9 + return self.ns, to_localName(self.name) == other.ns, to_localName(other.name)
1.10
1.11 def __hash__(self):
1.12 return hash(self.ns + to_localName(self.name))
1.13 @@ -41,40 +40,51 @@
1.14 def __repr__(self):
1.15 return "ParameterName(%s, %s)" % (repr(self.ns), repr(self.name or None))
1.16
1.17 +class ParameterValue(object):
1.18 +
1.19 + "A method parameter value."
1.20 +
1.21 + def __init__(self, name, value):
1.22 + self.name = name
1.23 + self.value = value
1.24 +
1.25 + def convert(self, converters=None):
1.26 + conv = default_converters
1.27 + conv.update(converters or {})
1.28 + typename = self.name.ns
1.29 + localName = to_localName(self.name.name)
1.30 + if isinstance(self.value, list):
1.31 + return [item.convert(converters) for item in self.value]
1.32 + else:
1.33 + functions = conv.get(typename, {})
1.34 + function = functions.get(localName) or functions.get(None, unicode)
1.35 + return function(self.value)
1.36 +
1.37 + def _data(self):
1.38 + return self.convert()
1.39 +
1.40 + data = property(_data)
1.41 +
1.42 + def __eq__(self, other):
1.43 + return self.name == other.name and self.value == other.value
1.44 +
1.45 + def __hash__(self):
1.46 + return hash(self.value)
1.47 +
1.48 + def __repr__(self):
1.49 + return "ParameterValue(%s, %s)" % (repr(self.name), repr(self.value))
1.50 +
1.51 # Sequence emulation.
1.52
1.53 def __len__(self):
1.54 - return 2
1.55 + return len(self.value)
1.56
1.57 def __getitem__(self, i):
1.58 - return (self.ns, self.name)[i]
1.59 + return self.value[i]
1.60
1.61 def to_localName(name):
1.62 return (name or "").split(":")[-1] or None
1.63
1.64 -def convert(parameters, converters=None):
1.65 -
1.66 - """
1.67 - Convert the 'parameters', returning a list of name, value items where the
1.68 - names are the plain names for each parameter, and the values may be
1.69 - converted from strings to other data types.
1.70 - """
1.71 -
1.72 - conv = default_converters
1.73 - conv.update(converters or {})
1.74 - results = []
1.75 - for parameter_name, parameter_value in parameters:
1.76 - typename, name = parameter_name
1.77 - localName = to_localName(name)
1.78 - if isinstance(parameter_value, list):
1.79 - value = convert(parameter_value, converters)
1.80 - else:
1.81 - functions = conv.get(typename, {})
1.82 - function = functions.get(localName) or functions.get(None, unicode)
1.83 - value = function(parameter_value)
1.84 - results.append((localName, value))
1.85 - return results
1.86 -
1.87 # Utility functions.
1.88
1.89 def boolean(s):