Skip to content

Commit 72bc88f

Browse files
committed
Support msgpack-1.0.0 (unpacking part)
msgpack-1.0.0 changes default value of 'raw' and 'strict_map_key' options. We should handle different versions of the library and provide the same behaviour across them. This version of the msgpack library also drops support of 'encoding' option. We already use raw=True/False msgpack option to implement encoding=None/'utf-8' connector option, so the only change we should do about this is to explicitly forbid other encoding values. Unlikely using of text encodings other than UTF-8 is popular. Part of #155
1 parent 6761fa5 commit 72bc88f

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

tarantool/connection.py

+7
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
NetworkError,
5353
DatabaseError,
5454
InterfaceError,
55+
ConfigurationError,
5556
SchemaError,
5657
NetworkWarning,
5758
SchemaReloadException,
@@ -79,6 +80,7 @@ class Connection(object):
7980
Error = tarantool.error
8081
DatabaseError = DatabaseError
8182
InterfaceError = InterfaceError
83+
ConfigurationError = ConfigurationError
8284
SchemaError = SchemaError
8385
NetworkError = NetworkError
8486

@@ -101,6 +103,11 @@ def __init__(self, host, port,
101103
creates network connection.
102104
if False than you have to call connect() manualy.
103105
'''
106+
107+
if msgpack.version >= (1, 0, 0) and encoding not in (None, 'utf-8'):
108+
raise ConfigurationError("Only None and 'utf-8' encoding option " +
109+
"values are supported with msgpack>=1.0.0")
110+
104111
if os.name == 'nt':
105112
libc = ctypes.WinDLL(
106113
ctypes.util.find_library('Ws2_32'), use_last_error=True

tarantool/response.py

+17
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,23 @@ def __init__(self, conn, response):
6464
elif conn.encoding is not None:
6565
unpacker_kwargs['encoding'] = conn.encoding
6666

67+
# raw=False is default since msgpack-1.0.0.
68+
#
69+
# The option decodes mp_str to bytes, not a Unicode
70+
# string (when True).
71+
if msgpack.version >= (1, 0, 0) and conn.encoding is None:
72+
unpacker_kwargs['raw'] = True
73+
74+
# encoding option is not supported since msgpack-1.0.0,
75+
# but it is handled in the Connection constructor.
76+
assert(msgpack.version < (1, 0, 0) or conn.encoding in (None, 'utf-8'))
77+
78+
# strict_map_key=True is default since msgpack-1.0.0.
79+
#
80+
# The option forbids non-string keys in a map (when True).
81+
if msgpack.version >= (1, 0, 0):
82+
unpacker_kwargs['strict_map_key'] = False
83+
6784
unpacker = msgpack.Unpacker(**unpacker_kwargs)
6885

6986
unpacker.feed(response)

0 commit comments

Comments
 (0)