@@ -160,7 +160,7 @@ def feed_arg_types(feed_type):
160160 return _COUCH_DB_UPDATES_ARG_TYPES
161161 return _CHANGES_ARG_TYPES
162162
163- def python_to_couch (options ):
163+ def python_to_couch (options , encoder = None ):
164164 """
165165 Translates query options from python style options into CouchDB/Cloudant
166166 query options. For example ``{'include_docs': True}`` will
@@ -171,13 +171,14 @@ def python_to_couch(options):
171171 :func:`~cloudant.view.View.__call__` callable, both used to retrieve data.
172172
173173 :param dict options: Python style parameters to be translated.
174+ :param encoder: Custom encoder, defaults to None
174175
175176 :returns: Dictionary of translated CouchDB/Cloudant query parameters
176177 """
177178 translation = dict ()
178179 for key , val in iteritems_ (options ):
179180 py_to_couch_validate (key , val )
180- translation .update (_py_to_couch_translate (key , val ))
181+ translation .update (_py_to_couch_translate (key , val , encoder ))
181182 return translation
182183
183184def py_to_couch_validate (key , val ):
@@ -201,14 +202,16 @@ def py_to_couch_validate(key, val):
201202 if val not in ('ok' , 'update_after' ):
202203 raise CloudantArgumentError (135 , val )
203204
204- def _py_to_couch_translate (key , val ):
205+ def _py_to_couch_translate (key , val , encoder = None ):
205206 """
206207 Performs the conversion of the Python parameter value to its CouchDB
207208 equivalent.
208209 """
209210 try :
210211 if key in ['keys' , 'endkey_docid' , 'startkey_docid' , 'stale' , 'update' ]:
211212 return {key : val }
213+ if key in ['endkey' , 'key' , 'startkey' ]:
214+ return {key : json .dumps (val , cls = encoder )}
212215 if val is None :
213216 return {key : None }
214217 arg_converter = TYPE_CONVERTERS .get (type (val ))
@@ -249,7 +252,7 @@ def get_docs(r_session, url, encoder=None, headers=None, **params):
249252 keys = None
250253 if keys_list is not None :
251254 keys = json .dumps ({'keys' : keys_list }, cls = encoder )
252- f_params = python_to_couch (params )
255+ f_params = python_to_couch (params , encoder )
253256 resp = None
254257 if keys is not None :
255258 # If we're using POST we are sending JSON so add the header
0 commit comments