mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
We never use pickles
and they have not been supported since around salt 0.8.2, so we might as well take them out.
This commit is contained in:
parent
ca68698c8b
commit
cf1855db18
@ -13,7 +13,6 @@ import logging
|
|||||||
import salt.log
|
import salt.log
|
||||||
import salt.crypt
|
import salt.crypt
|
||||||
from salt.exceptions import SaltReqTimeoutError
|
from salt.exceptions import SaltReqTimeoutError
|
||||||
from salt._compat import pickle
|
|
||||||
|
|
||||||
# Import third party libs
|
# Import third party libs
|
||||||
try:
|
try:
|
||||||
@ -91,13 +90,7 @@ class Serial(object):
|
|||||||
'''
|
'''
|
||||||
Run the correct loads serialization format
|
Run the correct loads serialization format
|
||||||
'''
|
'''
|
||||||
if self.serial == 'msgpack':
|
return msgpack.loads(msg, use_list=True)
|
||||||
return msgpack.loads(msg, use_list=True)
|
|
||||||
elif self.serial == 'pickle':
|
|
||||||
try:
|
|
||||||
return pickle.loads(msg)
|
|
||||||
except Exception:
|
|
||||||
return msgpack.loads(msg, use_list=True)
|
|
||||||
|
|
||||||
def load(self, fn_):
|
def load(self, fn_):
|
||||||
'''
|
'''
|
||||||
@ -111,35 +104,32 @@ class Serial(object):
|
|||||||
'''
|
'''
|
||||||
Run the correct dumps serialization format
|
Run the correct dumps serialization format
|
||||||
'''
|
'''
|
||||||
if self.serial == 'pickle':
|
try:
|
||||||
return pickle.dumps(msg)
|
return msgpack.dumps(msg)
|
||||||
else:
|
except TypeError:
|
||||||
try:
|
if msgpack.version >= (0, 2, 0):
|
||||||
return msgpack.dumps(msg)
|
# Should support OrderedDict serialization, so, let's
|
||||||
except TypeError:
|
# raise the exception
|
||||||
if msgpack.version >= (0, 2, 0):
|
raise
|
||||||
# Should support OrderedDict serialization, so, let's
|
|
||||||
# raise the exception
|
|
||||||
raise
|
|
||||||
|
|
||||||
# msgpack is < 0.2.0, let's make it's life easier
|
# msgpack is < 0.2.0, let's make it's life easier
|
||||||
# Since OrderedDict is identified as a dictionary, we can't
|
# Since OrderedDict is identified as a dictionary, we can't
|
||||||
# make use of msgpack custom types, we will need to convert by
|
# make use of msgpack custom types, we will need to convert by
|
||||||
# hand.
|
# hand.
|
||||||
# This means iterating through all elements of a dictionary or
|
# This means iterating through all elements of a dictionary or
|
||||||
# list/tuple
|
# list/tuple
|
||||||
def odict_encoder(obj):
|
def odict_encoder(obj):
|
||||||
if isinstance(obj, dict):
|
if isinstance(obj, dict):
|
||||||
for key, value in obj.copy().iteritems():
|
for key, value in obj.copy().iteritems():
|
||||||
obj[key] = odict_encoder(value)
|
obj[key] = odict_encoder(value)
|
||||||
return dict(obj)
|
return dict(obj)
|
||||||
elif isinstance(obj, (list, tuple)):
|
elif isinstance(obj, (list, tuple)):
|
||||||
obj = list(obj)
|
obj = list(obj)
|
||||||
for idx, entry in enumerate(obj):
|
for idx, entry in enumerate(obj):
|
||||||
obj[idx] = odict_encoder(entry)
|
obj[idx] = odict_encoder(entry)
|
||||||
return obj
|
|
||||||
return obj
|
return obj
|
||||||
return msgpack.dumps(odict_encoder(msg))
|
return obj
|
||||||
|
return msgpack.dumps(odict_encoder(msg))
|
||||||
|
|
||||||
def dump(self, msg, fn_):
|
def dump(self, msg, fn_):
|
||||||
'''
|
'''
|
||||||
|
Loading…
Reference in New Issue
Block a user