Ejemplo n.º 1
0
	def _dispatch(self, method, params):
		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 = resolve_dotted_attribute(
							self.instance,
							method,
							self.allow_dotted_names
							)
					except AttributeError:
						pass

		if func is not None:
			try:
				return func(*params)
			except Exception as e:
				import traceback
				log.critical('Error while executing method "%s": %s' % (method, e))
				log.critical(traceback.format_exc())
				raise
		else:
			log.warning('Client tried to call method "%s" which does not exist!' % (method,))
			raise Exception('method "%s" is not supported' % method)
Ejemplo n.º 2
0
 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 isinstance(params, list):
                 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)
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
    def _dispatch(self, method, params):
        logger.info("Recv XMLRPC call: path=%s, method=%s, params=%s",
                    getattr(self, "_path", None), 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 = resolve_dotted_attribute(
                            self.instance, method, self.allow_dotted_names)
                    except AttributeError:
                        pass

        if func is not None:
            try:
                params = params or ([], {})
                return func(*params[0], **params[1])
            except:
                logger.exception("")
                raise
        else:
            raise Exception('method "%s" is not supported' % method)
    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
Ejemplo n.º 6
0
    def _dispatch(self, method, params):
        """
        Default method resolver and caller

        :param method: Name of the method to call
        :param params: List of arguments to give to the method
        :return: The result of the method
        """
        func = None
        try:
            # Try with registered methods
            func = self.funcs[method]

        except KeyError:
            if self.instance is not None:
                # Try with the registered instance
                if hasattr(self.instance, '_dispatch'):
                    # Instance has a custom dispatcher
                    return self.instance._dispatch(method, params)

                else:
                    # 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 type(params) is utils.ListType:
                    return func(*params)

                else:
                    return func(**params)

            except TypeError as ex:
                # Maybe the parameters are wrong
                return Fault(-32602, 'Invalid parameters: {0}'.format(ex),
                             config=self.json_config)

            except:
                # Method exception
                err_lines = traceback.format_exc().splitlines()
                trace_string = '{0} | {1}'.format(err_lines[-3], err_lines[-1])
                return Fault(-32603, 'Server error: {0}'.format(trace_string),
                             config=self.json_config)

        else:
            # Unknown method
            return Fault(-32601, 'Method {0} not supported.'.format(method),
                         config=self.json_config)
Ejemplo n.º 7
0
    def _dispatch(self, method, params):
        logger.info("Recv XMLRPC call: path=%s, method=%s, params=%s", getattr(self, "_path", None), 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 = resolve_dotted_attribute(self.instance, method, self.allow_dotted_names)
                    except AttributeError:
                        pass

        if func is not None:
            try:
                params = params or ([], {})
                return func(*params[0], **params[1])
            except:
                logger.exception("")
                raise
        else:
            raise Exception('method "%s" is not supported' % method)