本文整理汇总了Python中SimpleXMLRPCServer类的典型用法代码示例。如果您正苦于以下问题:Python SimpleXMLRPCServer类的具体用法?Python SimpleXMLRPCServer怎么用?Python SimpleXMLRPCServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SimpleXMLRPCServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DragonCorrectionDialog
class DragonCorrectionDialog():
def __init__(self, heard):
self.completed = False
self.setup_XMLRPC_server()
dlg = wx.TextEntryDialog(None, "Correct with...", caption="Correction Dialog", defaultValue=heard)
dlg.ShowModal()
self.correction = dlg.GetValue()
self.completed = True
# start server, tk main loop
def start_server():
while not self.server_quit:
self.server.handle_request()
Timer(1, start_server).start()
# backup plan in case for whatever reason Dragon doesn't shut it down:
Timer(60, self.xmlrpc_kill).start()
def setup_XMLRPC_server(self):
self.server_quit = 0
self.server = SimpleXMLRPCServer(("127.0.0.1", LISTENING_PORT), allow_none=True)
self.server.register_function(self.xmlrpc_get_message, "get_message")
self.server.register_function(self.xmlrpc_kill, "kill")
def xmlrpc_kill(self):
self.server_quit = 1
os.kill(os.getpid(), signal.SIGTERM)
def xmlrpc_get_message(self):
print "get message called"
if self.completed:
Timer(1, self.xmlrpc_kill).start()
return self.correction
else:
return None
示例2: main
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "hs:p:", ["help"])
serv = "localhost"
port = 8088
for opt, val in opts:
if opt in ("-h", "--help"):
usage()
sys.exit(0)
elif opt == "-s":
serv = val
elif opt == "-p":
port = int(val)
server = SimpleXMLRPCServer((serv, port), RequestHandler, True, True)
server.register_introspection_functions()
server.serve_forever()
except getopt.GetoptError as err:
print str(err)
usage()
sys.exit(1)
except ValueError:
usage()
sys.exit(1)
except KeyboardInterrupt:
sys.exit(0)
示例3: __init__
def __init__(self, registerInstance, server_address, keyFile=DEFAULTKEYFILE,
certFile=DEFAULTCERTFILE, caFile = DEFAULTCAFILE, logRequests=True):
"""Secure Documenting XML-RPC server.
It it very similar to DocXMLRPCServer but it uses HTTPS for transporting XML data.
"""
SimpleXMLRPCServer.__init__(self, server_address, SecureXMLRPCRequestHandler, logRequests)
self.logRequests = logRequests
self.register_introspection_functions()
# init stuff, handle different versions:
try:
SimpleXMLRPCDispatcher.__init__(self)
except TypeError:
# An exception is raised in Python 2.5 as the prototype of the __init__
# method has changed and now has 3 arguments (self, allow_none, encoding)
SimpleXMLRPCDispatcher.__init__(self, False, None)
SocketServer.BaseServer.__init__(self, server_address, SecureXMLRPCRequestHandler)
self.register_instance(registerInstance) # for some reason, have to register instance down here!
# SSL socket stuff
ctx = SSL.Context(SSL.SSLv23_METHOD)
ctx.use_privatekey_file(keyFile)
ctx.use_certificate_file(certFile)
# verify
ctx.load_verify_locations(caFile)
ctx.set_verify(SSL.VERIFY_PEER|SSL.VERIFY_FAIL_IF_NO_PEER_CERT, self._verify)
self.socket = SSL.Connection(ctx, socket.socket(self.address_family, self.socket_type))
self.server_bind()
self.server_activate()
# requests count and condition, to allow for keyboard quit via CTL-C
self.requests = 0
self.rCondition = Condition()
示例4: system_listMethods
def system_listMethods(self):
methods = self.funcs.keys()
if self.instance is not None:
if hasattr(self.instance, '_listMethods'):
methods = SimpleXMLRPCServer.remove_duplicates(
methods + list_public_methods(self.instance)
)
elif not hasattr(self.instance, '_dispatch'):
methods = SimpleXMLRPCServer.remove_duplicates(
methods + list_public_methods(self.instance))
示例5: __init__
def __init__(self, password, hostname, port, server_list):
self.password = password
self.myUrl = "http://" + hostname + ":" + port
self.server_list = server_list
servers = self.update_server_list()
if servers:
for server in self.aug_network(servers[0]):
self.aug_network(server)
server = SimpleXMLRPCServer((hostname, int(port)))
if not server.register_function(self.handle_request, "handle_request"):
utils.srv(server)
示例6: Receptive_XML_RPC
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..."
示例7: ServerThread
class ServerThread( threading.Thread ) :
def __init__( self, case ) :
self.case = case
threading.Thread.__init__( self )
print "starting local Ophidian server..."
self.ProblemServer = ophidian.ProblemServer()
self.ProblemServer.RunDir = 'RunDir'
# check the run directory for cached problems
self.ProblemServer.InitProblemList()
# load the first problem, if it exists, exit otherwise
if self.ProblemServer.ProblemList.__contains__(case) :
self.ProblemServer.ProblemList = [case]
print "Loading CUBE data for problem " + case
self.ProblemServer.LoadProblem( case )
print "Starting server..."
self.server = SimpleXMLRPCServer(('127.0.0.1', 8000 ))
self.server.register_function(self.ProblemServer.GetProblem)
self.server.register_function(self.ProblemServer.GetBlock)
self.server.register_function(self.ProblemServer.CheckInBlock)
else :
print "No problems found. Ophidian server shutting down."
def run( self ) :
print "Now serving problem " + self.ProblemServer.Problem.problemname
self.server.serve_forever()
示例8: _dispatch
def _dispatch(self, method, params):
func = None
try:
func = self.funcs[method]
except KeyError:
if self.instance is not None:
if hasattr(self.instance, "_dispatch"):
return self.instance._dispatch(method, params)
else:
try:
func = SimpleXMLRPCServer.resolve_dotted_attribute(self.instance, method, True)
except AttributeError:
pass
if func is not None:
try:
if type(params) is types.ListType:
# MODIFIED to pass service method name as well
response = func(method, *params)
else:
# MODIFIED to pass service method name as well
response = func(method, **params)
return response
except TypeError:
return Fault(-32602, "Invalid parameters.")
except:
err_lines = traceback.format_exc().splitlines()
trace_string = "%s | %s" % (err_lines[-3], err_lines[-1])
fault = jsonrpclib.Fault(-32603, "Server error: %s" % trace_string)
return fault
else:
return Fault(-32601, "Method %s not supported." % method)
示例9: _dispatch
def _dispatch(self, method, params):
func = None
try:
func = self.funcs[method]
except KeyError:
if self.instance is not None:
if hasattr(self.instance, '_dispatch'):
return self.instance._dispatch(method, params)
else:
try:
func = SimpleXMLRPCServer.resolve_dotted_attribute(
self.instance,
method,
True
)
except AttributeError:
pass
if func is not None:
try:
if type(params) is types.ListType:
response = func(*params)
else:
response = func(**params)
return response
except TypeError:
return Fault(-32602, 'Invalid parameters: ')
except:
err_lines = traceback.format_exc().splitlines()
trace_string = '%s | %s' % (err_lines[-3], err_lines[-1])
fault = jsonrpclib.Fault(-32603, 'Server error: %s' %
trace_string)
return fault
else:
return Fault(-32601, 'Method %s not supported.' % method)
示例10: setup_XMLRPC_server
def setup_XMLRPC_server(self):
self.server_quit = 0
comm = Communicator()
self.server = SimpleXMLRPCServer(("127.0.0.1", comm.com_registry["status"]), allow_none=True)
self.server.register_function(self.xmlrpc_kill, "kill")
self.server.register_function(self.xmlrpc_hint, "hint")
self.server.register_function(self.xmlrpc_text, "text")
示例11: list_public_methods
def list_public_methods(obj):
"""Returns a list of attribute strings, found in the specified
object, which represent callable attributes"""
methods = SimpleXMLRPCServer.list_public_methods(obj)
methods = [dotify(m) for m in methods if is_public(getattr(obj, m, None))]
return methods
示例12: _dispatch
def _dispatch(self, method, params, **kwargs):
"""Dispatch a rpc call to the appropriate method with parameters.
This method is copied from SimpleXMLRPCServer but adds
kwargs so that REST methods can receive keyword arguments
rather than just list of parameters, which is all XMLRPC supports.
Args:
method: string, method name
params: tuple, list of arguments
kwargs: optional, dict of keyword arguments
Returns:
output from the called method
Raises:
Exception: if unsupported method is called
"""
func = None
try:
func = self.funcs[method]
except KeyError:
if self.instance is not None:
if hasattr(self.instance, '_dispatch'):
return self.instance._dispatch(method, params, kwargs)
else:
try:
func = SimpleXMLRPCServer.resolve_dotted_attribute(
self.instance,
method,
self.allow_dotted_names)
except AttributeError:
pass
if func is not None:
return func(*params, **kwargs)
else:
raise Exception('method "%s" is not supported' % method)
示例13: _dispatch
def _dispatch(self, method, params):
"""Dispatches the XML-RPC method.
XML-RPC calls are forwarded to a registered function that
matches the called XML-RPC method name. If no such function
exists then the call is forwarded to the registered instance,
if available.
If the registered instance has a _dispatch method then that
method will be called with the name of the XML-RPC method and
its parameters as a tuple
e.g. instance._dispatch('add',(2,3))
If the registered instance does not have a _dispatch method
then the instance will be searched to find a matching method
and, if found, will be called.
Methods beginning with an '_' are considered private and will
not be called.
"""
func = None
try:
# check to see if a matching function has been registered
func = self.funcs[method]
except KeyError:
if self.instance is not None:
# check for a _dispatch method
if hasattr(self.instance, '_dispatch'):
return self.instance._dispatch(method, params)
else:
# call instance method directly
try:
func = SimpleXMLRPCServer.resolve_dotted_attribute(
self.instance,
method,
self.allow_dotted_names
)
except AttributeError:
pass
if func is not None:
try:
# since we are using a keyword xmlrpc proxy this is sending
# the info comes in form of args and kwargs
# so params has 2 items, the first being a list or tuple
# and the second a dictionary
if len(params) == 2 and isinstance(params[1],dict) and\
( isinstance(params[0],list) or isinstance(params[0],tuple) ) :
return func(*params[0], **params[1])
else:
# this is the default way in case a normal xmlrpclib.ServerProxy is used
return func(*params)
except Exception:
# extended functionality to let the client have the full traceback
msg = traceback.format_exc()
raise xmlrpclib.Fault(1, msg)
else:
raise Exception('method "%s" is not supported' % method)
示例14: _dispatch
def _dispatch(self, method, params):
try:
self.local.method = method
return SimpleXMLRPCServer._dispatch(self, method, params)
except:
logging.exception('Exception in method %s', method)
self.local.exception = utils.FormatExceptionOnly()
raise
示例15: test_dotted_attribute
def test_dotted_attribute(self):
# Raises an AttributeError because private methods are not allowed.
self.assertRaises(AttributeError, SimpleXMLRPCServer.resolve_dotted_attribute, str, "__add")
self.assertTrue(SimpleXMLRPCServer.resolve_dotted_attribute(str, "title"))
# Get the test to run faster by sending a request with test_simple1.
# This avoids waiting for the socket timeout.
self.test_simple1()