1 #!/usr/bin/env python 2 3 """ 4 Conversion functions and data used by XML-RPC and SOAP. 5 6 Copyright (C) 2007 Paul Boddie <paul@boddie.org.uk> 7 8 This program is free software; you can redistribute it and/or modify it under 9 the terms of the GNU Lesser General Public License as published by the Free 10 Software Foundation; either version 3 of the License, or (at your option) any 11 later version. 12 13 This program is distributed in the hope that it will be useful, but WITHOUT 14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 16 details. 17 18 You should have received a copy of the GNU Lesser General Public License along 19 with this program. If not, see <http://www.gnu.org/licenses/>. 20 """ 21 22 converters = { 23 "string" : unicode, 24 "int" : int, 25 "i4" : int, 26 "double" : float, 27 "boolean" : boolean, # see the module globals 28 "dateTime.iso8601" : iso8601, # see the module globals 29 "base64" : str 30 } 31 32 def from_string(typename, value): 33 return converters.get(typename, str)(value) 34 35 # Utility functions. 36 37 def boolean(s): 38 if s.lower() == "true": 39 return True 40 elif s.lower() == "false": 41 return False 42 else: 43 raise ValueError, "String value %s not convertable to boolean." % repr(s) 44 45 def iso8601(s): 46 # NOTE: To be written. 47 return s 48 49 # vim: tabstop=4 expandtab shiftwidth=4