"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "salt/payload.py" between
salt-2019.2.0.tar.gz and salt-2019.2.1.tar.gz

About: SaltStack is a systems management software for data center automation, cloud orchestration, server provisioning, configuration management and more. Community version.

payload.py  (salt-2019.2.0):payload.py  (salt-2019.2.1)
skipping to change at line 17 skipping to change at line 17
# Import python libs # Import python libs
from __future__ import absolute_import, print_function, unicode_literals from __future__ import absolute_import, print_function, unicode_literals
# import sys # Use if sys is commented out below # import sys # Use if sys is commented out below
import logging import logging
import gc import gc
import datetime import datetime
# Import salt libs # Import salt libs
import salt.log import salt.log
import salt.crypt
import salt.transport.frame import salt.transport.frame
import salt.utils.immutabletypes as immutabletypes import salt.utils.immutabletypes as immutabletypes
import salt.utils.stringutils import salt.utils.stringutils
from salt.exceptions import SaltReqTimeoutError from salt.exceptions import SaltReqTimeoutError, SaltDeserializationError
from salt.utils.data import CaseInsensitiveDict
# Import third party libs # Import third party libs
from salt.ext import six from salt.ext import six
try: try:
import zmq import zmq
except ImportError: except ImportError:
# No need for zeromq in local mode # No need for zeromq in local mode
pass pass
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
skipping to change at line 138 skipping to change at line 138
the contents cannot be converted. the contents cannot be converted.
''' '''
try: try:
def ext_type_decoder(code, data): def ext_type_decoder(code, data):
if code == 78: if code == 78:
data = salt.utils.stringutils.to_unicode(data) data = salt.utils.stringutils.to_unicode(data)
return datetime.datetime.strptime(data, '%Y%m%dT%H:%M:%S.%f' ) return datetime.datetime.strptime(data, '%Y%m%dT%H:%M:%S.%f' )
return data return data
gc.disable() # performance optimization for msgpack gc.disable() # performance optimization for msgpack
loads_kwargs = {'use_list': True,
'ext_hook': ext_type_decoder}
if msgpack.version >= (0, 4, 0): if msgpack.version >= (0, 4, 0):
# msgpack only supports 'encoding' starting in 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 # 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 # that under Python 2 we can still work with older versions
# of msgpack. # of msgpack.
if msgpack.version >= (0, 5, 2):
if encoding is None:
loads_kwargs['raw'] = True
else:
loads_kwargs['raw'] = False
else:
loads_kwargs['encoding'] = encoding
try: try:
ret = msgpack.loads(msg, use_list=True, ext_hook=ext_type_de coder, encoding=encoding) ret = msgpack.loads(msg, **loads_kwargs)
except UnicodeDecodeError: except UnicodeDecodeError:
# msg contains binary data # msg contains binary data
ret = msgpack.loads(msg, use_list=True, ext_hook=ext_type_de loads_kwargs.pop('raw', None)
coder) loads_kwargs.pop('encoding', None)
ret = msgpack.loads(msg, **loads_kwargs)
else: else:
ret = msgpack.loads(msg, use_list=True, ext_hook=ext_type_decode r) ret = msgpack.loads(msg, **loads_kwargs)
if six.PY3 and encoding is None and not raw: if six.PY3 and encoding is None and not raw:
ret = salt.transport.frame.decode_embedded_strs(ret) ret = salt.transport.frame.decode_embedded_strs(ret)
except Exception as exc: except Exception as exc:
log.critical( log.critical(
'Could not deserialize msgpack message. This often happens ' 'Could not deserialize msgpack message. This often happens '
'when trying to read a file not in binary mode. ' 'when trying to read a file not in binary mode. '
'To see message payload, enable debug logging and retry. ' 'To see message payload, enable debug logging and retry. '
'Exception: %s', exc 'Exception: %s', exc
) )
log.debug('Msgpack deserialization failure on message: %s', msg) log.debug('Msgpack deserialization failure on message: %s', msg)
gc.collect() gc.collect()
raise raise six.raise_from(
SaltDeserializationError(
'Could not deserialize msgpack message.'
' See log for more info.'
),
exc,
)
finally: finally:
gc.enable() gc.enable()
return ret return ret
def load(self, fn_): def load(self, fn_):
''' '''
Run the correct serialization to load a file Run the correct serialization to load a file
''' '''
data = fn_.read() data = fn_.read()
fn_.close() fn_.close()
skipping to change at line 207 skipping to change at line 224
return msgpack.ExtType(78, salt.utils.stringutils.to_bytes( return msgpack.ExtType(78, salt.utils.stringutils.to_bytes(
obj.strftime('%Y%m%dT%H:%M:%S.%f'))) obj.strftime('%Y%m%dT%H:%M:%S.%f')))
# The same for immutable types # The same for immutable types
elif isinstance(obj, immutabletypes.ImmutableDict): elif isinstance(obj, immutabletypes.ImmutableDict):
return dict(obj) return dict(obj)
elif isinstance(obj, immutabletypes.ImmutableList): elif isinstance(obj, immutabletypes.ImmutableList):
return list(obj) return list(obj)
elif isinstance(obj, (set, immutabletypes.ImmutableSet)): elif isinstance(obj, (set, immutabletypes.ImmutableSet)):
# msgpack can't handle set so translate it to tuple # msgpack can't handle set so translate it to tuple
return tuple(obj) return tuple(obj)
elif isinstance(obj, CaseInsensitiveDict):
return dict(obj)
# Nothing known exceptions found. Let msgpack raise it's own. # Nothing known exceptions found. Let msgpack raise it's own.
return obj return obj
try: try:
if msgpack.version >= (0, 4, 0): if msgpack.version >= (0, 4, 0):
# msgpack only supports 'use_bin_type' starting in 0.4.0. # msgpack only supports 'use_bin_type' starting in 0.4.0.
# Due to this, if we don't need it, don't pass it at all so # 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 # that under Python 2 we can still work with older versions
# of msgpack. # of msgpack.
return msgpack.dumps(msg, default=ext_type_encoder, use_bin_type =use_bin_type) return msgpack.dumps(msg, default=ext_type_encoder, use_bin_type =use_bin_type)
 End of changes. 9 change blocks. 
7 lines changed or deleted 25 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)