def test_map_func_args_with_default(self): args = [1, 2] kw = {'c': 3} args_names = ('a', 'b', 'c', 'd',) defaults = {'c': None, 'd': None} map_ = evelink_api.map_func_args(args, kw, args_names, defaults) self.assertEqual({'a': 1, 'b': 2, 'c': 3, 'd': None}, map_)
def test_map_func_args_with_all_positional_arguments(self): args = [1, 2, 3, 4] kw = {} args_names = ('a', 'b', 'c', 'd',) defaults = {'c': None, 'd': None} map_ = evelink_api.map_func_args(args, kw, args_names, defaults) self.assertEqual({'a': 1, 'b': 2, 'c': 3, 'd': 4}, map_)
def _async(self, *args, **kw): # method specs path = method._request_specs['path'] args_names = method._request_specs['args'] defaults = method._request_specs['defaults'] prop_to_param = method._request_specs['prop_to_param'] map_params = method._request_specs['map_params'] # build parameter map args_map = api.map_func_args(args, kw, args_names, defaults) for attr_name in prop_to_param: args_map[attr_name] = getattr(self, attr_name, None) # fix params name and remove params with None values params = api.translate_args(args_map, map_params) params = dict((k, v,) for k, v in params.items() if v is not None) kw['api_result'] = yield self.api.get_async(path, params=params) raise ndb.Return(method(self, *args, **kw))
def _async(self, *args, **kw): # method specs path = method._request_specs['path'] args_names = method._request_specs['args'] defaults = method._request_specs['defaults'] prop_to_param = method._request_specs['prop_to_param'] map_params = method._request_specs['map_params'] # build parameter map args_map = api.map_func_args(args, kw, args_names, defaults) for attr_name in prop_to_param: args_map[attr_name] = getattr(self, attr_name, None) # fix params name and remove params with None values params = api.translate_args(args_map, map_params) params = dict(( k, v, ) for k, v in params.items() if v is not None) kw['api_result'] = yield self.api.get_async(path, params=params) raise ndb.Return(method(self, *args, **kw))
def wrapper(*args, **kwargs): defaultargs, defaultkwargs = api.get_args_and_defaults(func) mapped_args = api.map_func_args(args, kwargs, defaultargs, defaultkwargs) if mapped_args.get('api') is None: kwargs['api'] = AppEngineAPI() return func(*args, **kwargs)