def _dispatch(self, method, params, config=None):
"""
Default method resolver and caller
:param method: Name of the method to call
:param params: List of arguments to give to the method
:param config: Request-specific configuration
:return: The result of the method
"""
config = config or self.json_config
func = None
try:
# Look into registered methods
func = self.funcs[method]
except KeyError:
if self.instance is not None:
# Try with the registered instance
try:
# Instance has a custom dispatcher
return getattr(self.instance, '_dispatch')(method, params)
except AttributeError:
# Resolve the method name in the instance
try:
func = xmlrpcserver.resolve_dotted_attribute(
self.instance, method, True)
except AttributeError:
# Unknown method
pass
if func is not None:
try:
# Call the method
if isinstance(params, utils.ListType):
return func(*params)
else:
return func(**params)
except TypeError as ex:
# Maybe the parameters are wrong
fault = Fault(-32602, 'Invalid parameters: {0}'.format(ex),
config=config)
_logger.warning("Invalid call parameters: %s", fault)
return fault
except:
# Method exception
err_lines = traceback.format_exc().splitlines()
trace_string = '{0} | {1}'.format(err_lines[-3], err_lines[-1])
fault = Fault(-32603, 'Server error: {0}'.format(trace_string),
config=config)
_logger.exception("Server-side exception: %s", fault)
return fault
else:
# Unknown method
fault = Fault(-32601, 'Method {0} not supported.'.format(method),
config=config)
_logger.warning("Unknown method: %s", fault)
return fault
# ------------------------------------------------------------------------------
评论列表
文章目录