def validate_params(method, D): if type(D['params']) == Object: keys = method.json_arg_types.keys() if len(keys) != len(D['params']): raise InvalidParamsError('Not enough params provided for {0}' \ .format(method.json_sig)) for k in keys: if not k in D['params']: raise InvalidParamsError('{0} is not a valid parameter for {1}' \ .format(k, method.json_sig)) if not Any.kind(D['params'][k]) == method.json_arg_types[k]: raise InvalidParamsError('{0} is not the correct type {1} for {2}' \ .format(type(D['params'][k]), method.json_arg_types[k], method.json_sig)) elif type(D['params']) == Array: arg_types = list(method.json_arg_types.values()) try: for i, arg in enumerate(D['params']): if not Any.kind(arg) == arg_types[i]: raise InvalidParamsError('{0} is not the correct type {1} for {2}' \ .format(type(arg), arg_types[i], method.json_sig)) except IndexError: raise InvalidParamsError('Too many params provided for {0}'.format(method.json_sig)) else: if len(D['params']) != len(arg_types): raise InvalidParamsError('Not enough params provided for {0}'.format(method.json_sig))
def validate_params(method, D): if type(D['params']) == Object: keys = method.json_arg_types.keys() if len(keys) != len(D['params']): raise InvalidParamsError('Not eough params provided for {0}' \ .format(method.json_sig)) for k in keys: if not k in D['params']: raise InvalidParamsError('{0} is not a valid parameter for {1}' \ .format(k, method.json_sig)) if not Any.kind(D['params'][k]) == method.json_arg_types[k]: raise InvalidParamsError('{0} is not the correct type {1} for {2}' \ .format(type(D['params'][k]), method.json_arg_types[k], method.json_sig)) elif type(D['params']) == Array: arg_types = list(method.json_arg_types.values()) try: for i, arg in enumerate(D['params']): if not Any.kind(arg) == arg_types[i]: raise InvalidParamsError('{0} is not the correct type {1} for {2}' \ .format(type(arg), arg_types[i], method.json_sig)) except IndexError: raise InvalidParamsError('Too many params provided for {0}'.format( method.json_sig)) else: if len(D['params']) != len(arg_types): raise InvalidParamsError( 'Not enouh params provided for {0}'.format( method.json_sig))
def procedure_desc(self, key): M = self.urls[key] return { 'name': M.json_method, 'summary': M.__doc__, 'idempotent': M.json_safe, 'params': [{'type': str(Any.kind(t)), 'name': k} for k, t in M.json_arg_types.iteritems()], 'return': {'type': str(Any.kind(M.json_return_type))}}
def procedure_desc(self, key): M = self.urls[key] return { 'name': M.json_method, 'summary': M.__doc__, 'idempotent': M.json_safe, 'params': [{'type': text_type(Any.kind(t)), 'name': k} for k, t in iteritems(M.json_arg_types)], 'return': {'type': text_type(Any.kind(M.json_return_type))}}
def test_types(self): assert type(u'') == String assert type('') == String assert not type('') == Object assert not type([]) == Object assert type([]) == Array assert type('') == Any assert Any.kind('') == String assert Any.decode('str') == String assert Any.kind({}) == Object assert Any.kind(None) == Nil
def test_types(self): self.assertEqual(type(u''), String) self.assertEqual(type(''), String) self.assertNotEqual(type(''), Object) self.assertNotEqual(type([]), Object) self.assertEqual(type([]), Array) self.assertEqual(type(''), Any) self.assertEqual(Any.kind(''), String) self.assertEqual(Any.decode('str'), String) self.assertEqual(Any.kind({}), Object) self.assertEqual(Any.kind(None), Nil)
def test_decode_types(self): self.assertEqual(Any.decode('obj'), Object) self.assertEqual(Any.decode('num'), Number) self.assertEqual(Any.decode('bool'), Boolean) self.assertEqual(Any.decode('str'), String) self.assertEqual(Any.decode('arr'), Array) self.assertEqual(Any.decode('nil'), Nil) self.assertEqual(Any.decode('any'), Any)
def test_types(self): self.assertEqual(type(1), Number) self.assertEqual(type(1.0), Number) self.assertEqual(type(1+3j), Number) self.assertEqual(type(-34.54555), Number) self.assertEqual(type(99999999999999999), Number) self.assertEqual(type(u''), String) self.assertEqual(type(''), String) self.assertEqual(type({}), Object) self.assertEqual(type(set()), Array) self.assertEqual(type(frozenset()), Array) self.assertNotEqual(type(''), Object) self.assertNotEqual(type([]), Object) self.assertEqual(type([]), Array) self.assertEqual(type(''), Any) self.assertEqual(Any.kind(''), String) self.assertEqual(Any.decode('str'), String) self.assertEqual(Any.kind({}), Object) self.assertEqual(Any.kind(None), Nil)
def test_types(self): self.assertEqual(type(1), Number) self.assertEqual(type(1.0), Number) self.assertEqual(type(1 + 3j), Number) self.assertEqual(type(-34.54555), Number) self.assertEqual(type(99999999999999999), Number) self.assertEqual(type(u''), String) self.assertEqual(type(''), String) self.assertEqual(type({}), Object) self.assertEqual(type(set()), Array) self.assertEqual(type(frozenset()), Array) self.assertNotEqual(type(''), Object) self.assertNotEqual(type([]), Object) self.assertEqual(type([]), Array) self.assertEqual(type(''), Any) self.assertEqual(Any.kind(''), String) self.assertEqual(Any.decode('str'), String) self.assertEqual(Any.kind({}), Object) self.assertEqual(Any.kind(None), Nil)
def __call__(self, *args, **kwargs): params = kwargs if len(kwargs) else args if Any.kind(params) == Object and self.version != '2.0': raise Exception('Unsupport arg type for JSON-RPC 1.0 ' '(the default version for this client, ' 'pass version="2.0" to use keyword arguments)') r = self.send_payload(params) y = json.loads(r) if u'error' in y: try: if current_app.config['DEBUG']: print '%s error %r' % (self.service_name, y) except: pass return y
def __call__(self, *args, **kwargs): params = kwargs if len(kwargs) else args if Any.kind(params) == Object and self.version != '2.0': raise Exception('Unsupport arg type for JSON-RPC 1.0 ' '(the default version for this client, ' 'pass version="2.0" to use keyword arguments)') r = self.send_payload(params) y = json.loads(r) if 'error' in y: try: if current_app.config['DEBUG']: print('{0} error {1!r}'.format(self.service_name, y)) except: pass return y
def test_kind_types(self): self.assertEqual(String.kind(''), String) self.assertEqual(Any.kind(''), String) self.assertEqual(Any.kind({}), Object) self.assertEqual(Any.kind(None), Nil)