Conversion Functions¶
By default, this library uses the default pickle
and json
modules of the standard Python installation to perform conversion
to and from those formats.
Sometimes there may be a wish to use a different implementation of
those functions (for example, cPickle
or a faster JSON encoder/
decoder).
There are two functions available to change the default Pickle and JSON converters.
Note that these immediately affect all
Bucket
objects. If you wish to have
a finer grained control over which object uses which converters, you
may wish to consider writing your own
Transcoder
implementation instead.
-
couchbase.
set_json_converters
(encode, decode)[source]¶ Modify the default JSON conversion functions. This affects all
Bucket
instances.These functions will called instead of the default ones (
json.dumps
andjson.loads
) to encode and decode JSON (whenFMT_JSON
is used).Parameters: - encode (callable) – Callable to invoke when encoding an object to JSON.
This should have the same prototype as
json.dumps
, with the exception that it is only ever passed a single argument. - decode (callable) – Callable to invoke when decoding an object to JSON.
This should have the same prototype and behavior
as
json.loads
with the exception that it is only ever passed a single argument.
Returns: A tuple of
(old encoder, old decoder)
No exceptions are raised, and it is the responsibility of the caller to ensure that the provided functions operate correctly, otherwise exceptions may be thrown randomly when encoding and decoding values
- encode (callable) – Callable to invoke when encoding an object to JSON.
This should have the same prototype as
-
couchbase.
set_pickle_converters
(encode, decode)[source]¶ Modify the default Pickle conversion functions. This affects all
Bucket
instances.These functions will be called instead of the default ones (
pickle.dumps
andpickle.loads
) to encode and decode values to and from the Pickle format (whenFMT_PICKLE
is used).Parameters: - encode (callable) – Callable to invoke when encoding an object to
Pickle. This should have the same prototype as
pickle.dumps
with the exception that it is only ever called with a single argument - decode (callable) – Callable to invoke when decoding a Pickle encoded
object to a Python object. Should have the same prototype as
pickle.loads
with the exception that it is only ever passed a single argument
Returns: A tuple of
(old encoder, old decoder)
No exceptions are raised and it is the responsibility of the caller to ensure that the provided functions operate correctly.
- encode (callable) – Callable to invoke when encoding an object to
Pickle. This should have the same prototype as