11#!/usr/bin/env python
2- # Copyright (c) 2015, 2016 IBM. All rights reserved.
2+ # Copyright (c) 2015, 2018 IBM. All rights reserved.
33#
44# Licensed under the Apache License, Version 2.0 (the "License");
55# you may not use this file except in compliance with the License.
2121
2222from ._2to3 import iteritems_ , next_ , unicode_ , STRTYPE , NONETYPE
2323from .error import CloudantArgumentError , CloudantFeedException
24- from ._common_util import feed_arg_types , TYPE_CONVERTERS
24+ from ._common_util import ANY_ARG , ANY_TYPE , feed_arg_types , TYPE_CONVERTERS
2525
2626class Feed (object ):
2727 """
@@ -100,7 +100,7 @@ def _translate(self, options):
100100 if isinstance (val , STRTYPE ):
101101 translation [key ] = val
102102 elif not isinstance (val , NONETYPE ):
103- arg_converter = TYPE_CONVERTERS .get (type (val ))
103+ arg_converter = TYPE_CONVERTERS .get (type (val ), json . dumps )
104104 translation [key ] = arg_converter (val )
105105 except Exception as ex :
106106 raise CloudantArgumentError (115 , key , ex )
@@ -111,11 +111,18 @@ def _validate(self, key, val, arg_types):
111111 Ensures that the key and the value are valid arguments to be used with
112112 the feed.
113113 """
114- if key not in arg_types :
115- raise CloudantArgumentError (116 , key )
116- if (not isinstance (val , arg_types [key ]) or
117- (isinstance (val , bool ) and int in arg_types [key ])):
118- raise CloudantArgumentError (117 , key , arg_types [key ])
114+ if key in arg_types :
115+ arg_type = arg_types [key ]
116+ else :
117+ if ANY_ARG not in arg_types :
118+ raise CloudantArgumentError (116 , key )
119+ arg_type = arg_types [ANY_ARG ]
120+
121+ if arg_type == ANY_TYPE :
122+ return
123+ if (not isinstance (val , arg_type ) or
124+ (isinstance (val , bool ) and int in arg_type )):
125+ raise CloudantArgumentError (117 , key , arg_type )
119126 if isinstance (val , int ) and val < 0 and not isinstance (val , bool ):
120127 raise CloudantArgumentError (118 , key , val )
121128 if key == 'feed' :
0 commit comments