Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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
  • Loading branch information
Totktonada committed Aug 28, 2020
commit 30d54f0fee1d09517b0546753f94484ebdc22cbc
7 changes: 7 additions & 0 deletions tarantool/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
NetworkError,
DatabaseError,
InterfaceError,
ConfigurationError,
SchemaError,
NetworkWarning,
SchemaReloadException,
Expand Down Expand Up @@ -79,6 +80,7 @@ class Connection(object):
Error = tarantool.error
DatabaseError = DatabaseError
InterfaceError = InterfaceError
ConfigurationError = ConfigurationError
SchemaError = SchemaError
NetworkError = NetworkError

Expand All @@ -101,6 +103,11 @@ def __init__(self, host, port,
creates network connection.
if False than you have to call connect() manualy.
'''

if msgpack.version >= (1, 0, 0) and encoding not in (None, 'utf-8'):
raise ConfigurationError("Only None and 'utf-8' encoding option " +
"values are supported with msgpack>=1.0.0")

if os.name == 'nt':
libc = ctypes.WinDLL(
ctypes.util.find_library('Ws2_32'), use_last_error=True
Expand Down
17 changes: 17 additions & 0 deletions tarantool/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,23 @@ def __init__(self, conn, response):
elif conn.encoding is not None:
unpacker_kwargs['encoding'] = conn.encoding

# raw=False is default since msgpack-1.0.0.
#
# The option decodes mp_str to bytes, not a Unicode
# string (when True).
if msgpack.version >= (1, 0, 0) and conn.encoding is None:
unpacker_kwargs['raw'] = True

# encoding option is not supported since msgpack-1.0.0,
# but it is handled in the Connection constructor.
assert(msgpack.version < (1, 0, 0) or conn.encoding in (None, 'utf-8'))

# strict_map_key=True is default since msgpack-1.0.0.
#
# The option forbids non-string keys in a map (when True).
if msgpack.version >= (1, 0, 0):
unpacker_kwargs['strict_map_key'] = False

unpacker = msgpack.Unpacker(**unpacker_kwargs)

unpacker.feed(response)
Expand Down