mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 17:50:20 +00:00
Fix deprecation warning in msgpack >= 0.5.2
This prevents a deprecation warning due to the "encoding" argument being deprecated in version 0.5.2.
This commit is contained in:
parent
63759444df
commit
e6c2ae4a7b
1 changed files with 11 additions and 3 deletions
|
@ -140,18 +140,26 @@ class Serial(object):
|
|||
return data
|
||||
|
||||
gc.disable() # performance optimization for msgpack
|
||||
loads_kwargs = {'use_list': True,
|
||||
'ext_hook': ext_type_decoder}
|
||||
if msgpack.version >= (0, 4, 0):
|
||||
# msgpack only supports 'encoding' starting in 0.4.0.
|
||||
# Due to this, if we don't need it, don't pass it at all so
|
||||
# that under Python 2 we can still work with older versions
|
||||
# of msgpack.
|
||||
if msgpack_version >= (0, 5, 2):
|
||||
loads_kwargs['raw'] = False
|
||||
else:
|
||||
loads_kwargs['encoding'] = encoding
|
||||
try:
|
||||
ret = msgpack.loads(msg, use_list=True, ext_hook=ext_type_decoder, encoding=encoding)
|
||||
ret = msgpack.loads(msg, **loads_kwargs)
|
||||
except UnicodeDecodeError:
|
||||
# msg contains binary data
|
||||
ret = msgpack.loads(msg, use_list=True, ext_hook=ext_type_decoder)
|
||||
loads_kwargs.pop('raw', None)
|
||||
loads_kwargs.pop('encoding', None)
|
||||
ret = msgpack.loads(msg, **loads_kwargs)
|
||||
else:
|
||||
ret = msgpack.loads(msg, use_list=True, ext_hook=ext_type_decoder)
|
||||
ret = msgpack.loads(msg, **loads_kwargs)
|
||||
if six.PY3 and encoding is None and not raw:
|
||||
ret = salt.transport.frame.decode_embedded_strs(ret)
|
||||
except Exception as exc:
|
||||
|
|
Loading…
Add table
Reference in a new issue