xmlrpclib mapping method names in dictionary
Brian Quinlan
brian at sweetapp.com
Fri Mar 14 16:41:27 EST 2003
> I figured this out: I had to use the _dispatch method
[snipped]
You should generate an exception in _dispatch in response to an invalid
command name (right now you are returning None, which is not a valid
XML-RPC type). I'd solve the problem like this (not tested):
class ShellCommand:
def __init__(self, command):
self.command = command
def do_command(self):
# Are you sure that you want to readlines?
return os.popen(self.command).readlines()
cmds={'ps':'ps -eaf',
'df':'df -k',
'uptime':'uptime',
'who':'who',
'last':'last',
'iostat':'iostat',
}
server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 9000))
for name, command in cmds.items():
server.register_function(ShellCommand(name).do_command, command)
server.serve_forever()
This way you don't have to use a custom dispatch method.
Cheers,
Brian
More information about the Python-list
mailing list