Skip to content

Commit 6761fa5

Browse files
committed
refactoring: extract msgpack unpacker tuning code
We will need a bit more logic in unpacker configuration code to support msgpack-1.0.0, so it is convenient to factor out it from actual creation of the unpacker instance. No behaviour is changed here. Part of #155
1 parent 4f79627 commit 6761fa5

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

tarantool/response.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,21 @@ def __init__(self, conn, response):
5050
# created in the __new__().
5151
# super(Response, self).__init__()
5252

53+
unpacker_kwargs = dict()
54+
55+
# Decode msgpack arrays into Python lists (not tuples).
56+
unpacker_kwargs['use_list'] = True
57+
58+
# Use raw=False instead of encoding='utf-8'.
5359
if msgpack.version >= (0, 5, 2) and conn.encoding == 'utf-8':
5460
# Get rid of the following warning.
5561
# > PendingDeprecationWarning: encoding is deprecated,
5662
# > Use raw=False instead.
57-
unpacker = msgpack.Unpacker(use_list=True, raw=False)
63+
unpacker_kwargs['raw'] = False
5864
elif conn.encoding is not None:
59-
unpacker = msgpack.Unpacker(use_list=True, encoding=conn.encoding)
60-
else:
61-
unpacker = msgpack.Unpacker(use_list=True)
65+
unpacker_kwargs['encoding'] = conn.encoding
66+
67+
unpacker = msgpack.Unpacker(**unpacker_kwargs)
6268

6369
unpacker.feed(response)
6470
header = unpacker.unpack()

0 commit comments

Comments
 (0)