2

I have a system where the code sits on a driver accessing a remote system. I'm using the SimpleXmlRpcServer implementation of xmlrpcserver and it works quite well. Functions and instances can be registered, but i dont think entire modules can be registered. In particular, id like to register the os module. Is this a possibility with simplexmlrpcserver or are there any other implementations that allow for this ?

gangof4
  • 85
  • 7

1 Answers1

2

One approach would be to iterate over the methods in the module and register each of them with register_instance.

For example, using this SimpleXMLRPCServer example as a starting point and this Stackoverflow answer for iterating over functions in a module:

Server

from SimpleXMLRPCServer import SimpleXMLRPCServer
import os

server = SimpleXMLRPCServer(('localhost', 9000))

def list_contents(dir_name):
    return os.listdir(dir_name)
for name, val in os.__dict__.items():
    if callable(val):
        print "Registering " +  name
        server.register_function(val, name)

try:
    print 'Use Control-C to exit'
    server.serve_forever()
except KeyboardInterrupt:
    print 'Exiting'

Client

import xmlrpclib

proxy = xmlrpclib.ServerProxy('http://localhost:9000')
print 'os.listdir():', proxy.listdir('.')
Community
  • 1
  • 1
softwariness
  • 4,022
  • 4
  • 33
  • 41