Esempio n. 1
0
def _get_method(methods, name):
    """Finds a method in a list (or dictionary).

    :param methods: List or dictionary of named functions.
    :param name: Name of the method to find.
    :raises MethodNotFound: If the method wasn't in the list.
    :returns: The method from the list.
    """
    # If it's a dictionary, search for the key
    if isinstance(methods, dict):
        try:
            return methods[name]
        except KeyError:
            raise MethodNotFound(name)
    # Otherwise it must be a list, search the __name__ attributes
    try:
        return next(m for m in methods if m.__name__ == name)
    except StopIteration:
        raise MethodNotFound(name)
Esempio n. 2
0
def sem_do(**kwargs):
    param = dict(**kwargs)
    # if param['rpc_call'] not in rpc_methods_dict.keys():
    if hasattr(RPCExecutor, param['rpc_call']) == False:
        raise MethodNotFound('method %s is not supported' % param['rpc_call'])
    # for required_param in rpc_methods_dict[param['rpc_call']]:
    for required_param in inspect.getfullargspec(
            getattr(RPCExecutor, param['rpc_call'])).args:
        if required_param not in param.keys():
            if required_param == 'self':
                continue
            raise InvalidParams('param %s is missing for method %s' %
                                (required_param, param['rpc_call']))
    global_server_pipe.send(param)
    try:
        result = global_server_pipe.recv()
    except EOFError:
        raise ServerError()
    return result
Esempio n. 3
0
 def test_raise(self):
     with self.assertRaises(JsonRpcServerError):
         raise MethodNotFound("Test")