Skip to content

Commit 98d2574

Browse files
committed
Support msgpack-1.0.0 (packing part)
The default value of the 'use_bin_type' option was changed in msgpack-1.0.0. We should support different versions of the library and provide the same behaviour across them. Aside of this, 'encoding' option was dropped since this version of the msgpack library, but we didn't actually support it for packing. Binary strings are packed as is (as mp_str), Unicode strings are encoded as UTF-8 (as mp_str too) and nothing is changed regarding this. Fixes #155
1 parent 1166622 commit 98d2574

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

tarantool/request.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,19 @@ def __init__(self, conn):
6565
self._sync = None
6666
self._body = ''
6767

68-
self.packer = msgpack.Packer()
68+
packer_kwargs = dict()
69+
70+
# use_bin_type=True is default since msgpack-1.0.0.
71+
#
72+
# The option controls whether to pack binary (non-unicode)
73+
# string values as mp_bin or as mp_str.
74+
#
75+
# The default behaviour of the connector is to pack both
76+
# bytes and Unicode strings as mp_str.
77+
if msgpack.version >= (1, 0, 0):
78+
packer_kwargs['use_bin_type'] = False
79+
80+
self.packer = msgpack.Packer(**packer_kwargs)
6981

7082
def _dumps(self, src):
7183
return self.packer.pack(src)

0 commit comments

Comments
 (0)