yadyn/server/XmlRpcReceiver.py
Wolfgang Hottgenroth 7dc41ea9c0 fix
2007-11-18 21:33:17 +01:00

34 lines
914 B
Python

import threading
import time
import Event
from logger import Logger
from SimpleXMLRPCServer import SimpleXMLRPCServer
class XmlRpcServer(SimpleXMLRPCServer):
def _dispatch(self, method, params):
try:
# We are forcing the 'export_' prefix on methods that are
# callable through XML-RPC to prevent potential security
# problems
func = getattr(self, 'export_' + method)
except AttributeError:
raise Exception('method "%s" is not supported' % method)
else:
return func(*params)
def export_add(self, x, y):
return x + y
class XmlRpcReceiver(threading.Thread):
def __init__(self, xmlRpcRecvAddr):
threading.Thread.__init__(self)
self.xmlRpcRecvAddr = xmlRpcRecvAddr
self.setDaemon(True)
def run(self):
server = XmlRpcServer(self.xmlRpcAddr)
server.serve_forever()