Details
-
Bug
-
Resolution: Won't Fix
-
Minor
-
None
-
2.0.3
-
Security Level: Public
-
None
Description
In 1.x to create a transcoder you would do the following:
from couchbase import Couchbase, FMT_JSON, FMT_MASK, FMT_BYTES
|
from couchbase.transcoder import Transcoder
|
|
# We'll define our own flag.
|
FMT_ZLIB = (FMT_MASK << 1) & ~FMT_MASK
|
#Compress objects before storing them in CB
|
class ZlibTranscoder(Transcoder):
|
def encode_value(self, value, format):
|
converted, flags = super(ZlibTranscoder, self).encode_value(value, format & FMT_MASK)
|
if (format & FMT_ZLIB):
|
flags |= FMT_ZLIB
|
converted = zlib.compress(converted)
|
return (converted, flags)
|
|
def decode_value(self, value, flags):
|
if (flags & FMT_ZLIB):
|
value = zlib.decompress(value)
|
flags &= FMT_MASK
|
return super(ZlibTranscoder, self).decode_value(value, flags)
|
This fails to be interpreted with this error:
Traceback (most recent call last):
|
File "/push2cb.py", line 8, in <module>
|
from couchbase import Couchbase, FMT_JSON, FMT_MASK, FMT_BYTES
|
ImportError: cannot import name FMT_MASK
|
The 2.X SDK does not have `FMT_MASK`:
https://github.com/couchbase/couchbase-python-client/blob/master/couchbase/user_constants.py#L22
I suspect the correct constants to use now is FMT_COMMON_MASK?
- It would be good if there is a transcoding example. I have one I can submit if you would like.
- It would be nice to fix the compatibility breakage if we can't we should document it.