Skip to content

Support msgpack 1.0.0 #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
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
15 changes: 12 additions & 3 deletions tarantool/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,20 @@ def __init__(self, conn, response):
# Get rid of the following warning.
# > PendingDeprecationWarning: encoding is deprecated,
# > Use raw=False instead.
unpacker = msgpack.Unpacker(use_list=True, raw=False)
if msgpack.version >= (1, 0, 0):
unpacker = msgpack.Unpacker(use_list=True, raw=False, strict_map_key=False)
else:
unpacker = msgpack.Unpacker(use_list=True, raw=False)
elif conn.encoding is not None:
unpacker = msgpack.Unpacker(use_list=True, encoding=conn.encoding)
if msgpack.version >= (1, 0, 0):
unpacker = msgpack.Unpacker(use_list=True, encoding=conn.encoding, strict_map_key=False)
else:
unpacker = msgpack.Unpacker(use_list=True, encoding=conn.encoding)
else:
unpacker = msgpack.Unpacker(use_list=True)
if msgpack.version >= (1, 0, 0):
unpacker = msgpack.Unpacker(use_list=True, strict_map_key=False)
else:
unpacker = msgpack.Unpacker(use_list=True)
Comment on lines +57 to +70
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can reduce code duplication by unpacking a dictionary to keyword parameters. A kind of this (not tested):

kwargs = dict(use_list=True)
if msgpack.version >= (1, 0, 0):
    # XXX: Explain why it is necessary.
    kwargs['strict_map_key'] = False
if msgpack.version >= (0, 5, 2) and conn.encoding == 'utf-8':
    # Get rid of the following warning.
    # > PendingDeprecationWarning: encoding is deprecated,
    # > Use raw=False instead.
    kwargs['raw'] = False
elif conn.encoding is not None:
    kwargs['encoding'] = conn.encoding

unpacker = msgpack.Unpacker(**kwargs)


unpacker.feed(response)
header = unpacker.unpack()
Expand Down