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:
Erik Johnson 2019-04-10 15:08:50 -05:00 committed by Pedro Algarvio
parent 63759444df
commit e6c2ae4a7b
No known key found for this signature in database
GPG key ID: BB36BF6584A298FF

View file

@ -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: