本文整理汇总了Python中SimpleXMLRPCServer.handle_request方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleXMLRPCServer.handle_request方法的具体用法?Python SimpleXMLRPCServer.handle_request怎么用?Python SimpleXMLRPCServer.handle_request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleXMLRPCServer
的用法示例。
在下文中一共展示了SimpleXMLRPCServer.handle_request方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Receptive_XML_RPC
# 需要导入模块: import SimpleXMLRPCServer [as 别名]
# 或者: from SimpleXMLRPCServer import handle_request [as 别名]
class Receptive_XML_RPC(Thread):
def __init__(self, my_host, my_port, GUI_functions):
Thread.__init__(self)
self.host = my_host
# server XMLRPC
i = 0
while 1:
try:
self.server = SimpleXMLRPCServer((self.host, my_port + i))
break
except:
i += 1
self.port = my_port + i
# functions callable by the GUI
self.server.register_instance(GUI_functions)
# getPort --------------------
def getPort(self):
return self.port
# getClass --------------------
def getClass(self, host, port):
return Emissive_XML_RPC(host, port)
# kill --------------------
def kill(self):
# Send a message to awake it.
try:
url = str(self.host) + ":"+str(self.port)
newServer = xmlrpclib.Server(url)
newServer.isAlive()
except :
pass
# run --------------------
def run(self):
""" Receive messages from the GUI and process them"""
while globalvars.ALIVE:
self.server.handle_request()
print "End of Xml connection..."
示例2: exec
# 需要导入模块: import SimpleXMLRPCServer [as 别名]
# 或者: from SimpleXMLRPCServer import handle_request [as 别名]
server.register_function(list_functions, "list_functions")
server.register_function(terminate, "terminate")
if SCRIPTS_PATH not in sys.path:
sys.path.append(SCRIPTS_PATH)
for s in [x[0] for x in os.walk(SCRIPTS_PATH)]:
if s.endswith(".sikuli") and not s.endswith("xmlrpc_server.sikuli"):
mdl_name = s.split(".")[0].split("\\")[-1]
exec ("import " + mdl_name)
exec ("l = getmembers(" + mdl_name + ", isfunction)")
for d in l:
if d[0].startswith("export_"):
registered_function_name = mdl_name + "_" + d[0].replace("export_", "")
modules.append(registered_function_name)
exec ("server.register_function(" + mdl_name + "." + d[0] + ", '" +
registered_function_name + "')")
print("Caster Sikuli Bridge\n\nlist of available commands " + str(modules))
# examples
def add(self, x, y):
return x + y
try:
while not quit:
server.handle_request()
except KeyboardInterrupt:
print('Exiting')
示例3: NodeCom
# 需要导入模块: import SimpleXMLRPCServer [as 别名]
# 或者: from SimpleXMLRPCServer import handle_request [as 别名]
class NodeCom(Thread):
""" class for communication with the node """
def __init__(self, my_node):
""" NodeCom initialization """
Thread.__init__(self)
# connected node
self.my_node = my_node
#-----Step 1: create TCP socket to signal presence to the node
#print "Step 1"
#f = file("Debug.txt", 'a')
#f.write("Step 1\n")
#f.close()
# connection
node_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
node_socket.connect( (self.my_node.node_host, int(self.my_node.node_port)) )
# create XMLRPC server
while 1:
try:
#self.server = SimpleXMLRPCServer( (self.my_node.my_host, self.my_node.my_port_node))
self.server = SimpleXMLRPCServer( addr=(self.my_node.my_host, self.my_node.my_port_node), logRequests=0)
#print "SimpleXMLRPCServer()"
#f = file("Debug.txt", 'a')
#f.write("SimpleXMLRPCServer() OK\n")
#f.close()
break
except:
# may be the port is already used
time.sleep(0.2)
self.my_node.my_port_node = random.randint(1000,25000)
#print "port for SimpleXMLRPCServer already used"
#f = file("Debug.txt", 'a')
#f.write("port for SimpleXMLRPCServer already used\n")
#f.close()
# send message
msg = "openGUI;XML_RPC;"+str(self.my_node.my_host)+";"+str(self.my_node.my_port_node)
node_socket.send(msg)
#print "send openGUI msg"
#f = file("Debug.txt", 'a')
#f.write("send openGUI msg\n")
#f.close()
# waiting for answer
answer = node_socket.recv(1024)
node_socket.close()
#-----Step 2: open an openGUI
#print "Step 2 : [%s]" %answer
#f = file("Debug.txt", 'a')
#f.write("Step 2 return [" + answer+"] \n")
#f.close()
if answer and answer <> "refuse":
# create client
port_XML_GUI = string.split(answer,';')[1]
host_XML_GUI = "http://" + self.my_node.node_host + ":" + port_XML_GUI
self.client = xmlrpclib.Server(host_XML_GUI)
#print "create xml rpc client (%s)" %host_XML_GUI
#-----Step 3: open an OpenMedia
#print "Step 3"
# connection
node_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
node_socket.connect( (self.my_node.node_host, int(self.my_node.node_port)) )
# send message
msg = "openMedia;module2d_Chat;XML_RPC;"+str(self.my_node.my_host)+";"+str(self.my_node.my_port_node)+";1"
node_socket.send(msg)
#print "openMedia msg"
# waiting for answer
answer = node_socket.recv(1024)
node_socket.close()
#print "answer received : [%s]" %answer
# ----------------------------------------
self.alive = (answer and answer <> "refuse")
def run(self):
# attribute CallableFunction to server
functions = CallableFunction(self.my_node)
self.server.register_instance(functions)
while self.alive:
self.server.handle_request()
#print 'End of XML Server ...'
# -----------------------------------------
def getInfos(self, id, var, addVar):
return self.client.getInfos(id, var, addVar)
#.........这里部分代码省略.........