I have built an XML-RPC interface in Python and I need to enforce some stricter typing. For example, passing string '10' instead of int 10. I can clean this up with some type casting and a little exception handling, but I am wondering if there is any other way of forcing type integrity such as something XML-RPC specific, a decorator, or something else.
A:
XML-RPC methods (at least in xmlrpclib
) are dispatched to Python functions or method, so you have to enforce type checking in them. There is a lot of recipes on doing this task with decorators: Type Enforcement (accepts/returns), typecheck module.
Note, that xmlrpclib
lacks proper error handling, so you probably would like to implement your own.
Denis Otkidach
2009-12-18 10:42:53
A:
I always just use the re.escape function eg.:
number = re.escape(number)
This way things always gets converted to strings
lithorus
2009-12-18 10:46:46