def test_method_parser(self):
     working_sigs = [
         ('jsonrpc', 'jsonrpc', OrderedDict(), Any),
         ('jsonrpc.methodName', 'jsonrpc.methodName', OrderedDict(), Any),
         ('jsonrpc.methodName() -> list', 'jsonrpc.methodName', OrderedDict(), list),
         ('jsonrpc.methodName(str, str, str ) ', 'jsonrpc.methodName', OrderedDict([('a', str), ('b', str), ('c', str)]), Any),
         ('jsonrpc.methodName(str, b=str, c=str)', 'jsonrpc.methodName', OrderedDict([('a', str), ('b', str), ('c', str)]), Any),
         ('jsonrpc.methodName(str, b=str) -> dict', 'jsonrpc.methodName', OrderedDict([('a', str), ('b', str)]), dict),
         ('jsonrpc.methodName(str, str, c=Any) -> Any', 'jsonrpc.methodName', OrderedDict([('a', str), ('b', str), ('c', Any)]), Any),
         ('jsonrpc(Any ) -> Any', 'jsonrpc', OrderedDict([('a', Any)]), Any),
     ]
     error_sigs = [
         ('jsonrpc(str) -> nowai', ValueError),
         ('jsonrpc(nowai) -> Any', ValueError),
         ('jsonrpc(nowai=str, str)', ValueError),
         ('jsonrpc.methodName(nowai*str) -> Any', ValueError)
     ]
     for sig in working_sigs:
         ret = _parse_sig(sig[0], list(iter(sig[2])))
         self.assertEquals(ret[0], sig[1])
         self.assertEquals(ret[1], sig[2])
         self.assertEquals(ret[2], sig[3])
     for sig in error_sigs:
         e = None
         try:
             _parse_sig(sig[0], ['a'])
         except Exception, exc:
             e = exc
         self.assert_(type(e) is sig[1])
 def test_method_parser(self):
     working_sigs = [
         ('jsonrpc', 'jsonrpc', OrderedDict(), Any),
         ('jsonrpc.methodName', 'jsonrpc.methodName', OrderedDict(), Any),
         ('jsonrpc.methodName() -> list', 'jsonrpc.methodName', OrderedDict(), list),
         ('jsonrpc.methodName(str, str, str ) ', 'jsonrpc.methodName', OrderedDict([('a', str), ('b', str), ('c', str)]), Any),
         ('jsonrpc.methodName(str, b=str, c=str)', 'jsonrpc.methodName', OrderedDict([('a', str), ('b', str), ('c', str)]), Any),
         ('jsonrpc.methodName(str, b=str) -> dict', 'jsonrpc.methodName', OrderedDict([('a', str), ('b', str)]), dict),
         ('jsonrpc.methodName(str, str, c=Any) -> Any', 'jsonrpc.methodName', OrderedDict([('a', str), ('b', str), ('c', Any)]), Any),
         ('jsonrpc(Any ) -> Any', 'jsonrpc', OrderedDict([('a', Any)]), Any),
     ]
     error_sigs = [
         ('jsonrpc(str) -> nowai', ValueError),
         ('jsonrpc(nowai) -> Any', ValueError),
         ('jsonrpc(nowai=str, str)', ValueError),
         ('jsonrpc.methodName(nowai*str) -> Any', ValueError)
     ]
     for sig in working_sigs:
         ret = _parse_sig(sig[0], list(iter(sig[2])))
         self.assertEquals(ret[0], sig[1])
         self.assertEquals(ret[1], sig[2])
         self.assertEquals(ret[2], sig[3])
     for sig in error_sigs:
         e = None
         try:
             _parse_sig(sig[0], ['a'])
         except Exception, exc:
             e = exc
         self.assert_(type(e) is sig[1])
Exemple #3
0
 def decorator(f):
     arg_names = getfullargspec(f)[0]
     name_args = {'name': name, 'arg_names': arg_names}
     if authenticated:
         name_args['arg_names'] = ['username', 'password'
                                   ] + name_args['arg_names']
         name_args['name'] = _inject_args(name_args['name'],
                                          ('String', 'String'))
         _f = self.auth_backend(f, authenticated)
     else:
         _f = f
     method, arg_types, return_type = _parse_sig(
         name_args['name'], name_args['arg_names'], validate)
     _f.json_args = name_args['arg_names']
     _f.json_arg_types = arg_types
     _f.json_return_type = return_type
     _f.json_method = method
     _f.json_safe = safe
     _f.json_sig = name_args['name']
     _f.json_validate = validate
     self.site.register(method, _f)
     return _f