1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/libxml2dom/conversions.py Mon Oct 01 23:26:37 2007 +0000
1.3 @@ -0,0 +1,49 @@
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 +converters = {
1.26 + "string" : unicode,
1.27 + "int" : int,
1.28 + "i4" : int,
1.29 + "double" : float,
1.30 + "boolean" : boolean, # see the module globals
1.31 + "dateTime.iso8601" : iso8601, # see the module globals
1.32 + "base64" : str
1.33 + }
1.34 +
1.35 +def from_string(typename, value):
1.36 + return converters.get(typename, str)(value)
1.37 +
1.38 +# Utility functions.
1.39 +
1.40 +def boolean(s):
1.41 + if s.lower() == "true":
1.42 + return True
1.43 + elif s.lower() == "false":
1.44 + return False
1.45 + else:
1.46 + raise ValueError, "String value %s not convertable to boolean." % repr(s)
1.47 +
1.48 +def iso8601(s):
1.49 + # NOTE: To be written.
1.50 + return s
1.51 +
1.52 +# vim: tabstop=4 expandtab shiftwidth=4