Skip to content

Commit

Permalink
Merge pull request #1022 from to266/BUGFIX_drop_marshalling_functions
Browse files Browse the repository at this point in the history
Drop marshalling functions
  • Loading branch information
francisco-dlp committed May 26, 2016
2 parents 9d1572d + 0be8d1f commit 24285d2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 26 deletions.
34 changes: 8 additions & 26 deletions hyperspy/misc/export_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@
from operator import attrgetter
from hyperspy.misc.utils import attrsetter
from copy import deepcopy
try:
import dill
dill_avail = True
except ImportError:
dill_avail = False
import types
import marshal
import dill


def check_that_flags_make_sense(flags):
Expand Down Expand Up @@ -73,11 +67,11 @@ def export_to_dictionary(target, whitelist, dic, fullcopy=True):
object used for initialization of the target. The object is
saved in the tuple in whitelist
* 'fn':
the targeted attribute is a function, and may be pickled
(preferably with dill package). A tuple of (thing, value) will
be exported to the dictionary, where thing is None if function
is passed as-is, and bool if dill package is used to pickle the
function, and value is the result.
the targeted attribute is a function, and may be pickled. A
tuple of (thing, value) will be exported to the dictionary,
where thing is None if function is passed as-is, and True if
dill package is used to pickle the function, with the value as
the result of the pickle.
* 'id':
the id of the targeted attribute is exported (e.g.
id(target.name))
Expand Down Expand Up @@ -127,13 +121,7 @@ def export_to_dictionary(target, whitelist, dic, fullcopy=True):
value['data'] = deepcopy(value['data'])
elif 'fn' in flags:
if fullcopy:
if dill_avail:
value = (True, dill.dumps(value))
else:
# Apparently this fails because Python does not guarantee backwards-compatibility for marshal, and pickle does
# not work for our lambda functions. Hence drop marshal
# support and only work with dill package
value = (False, marshal.dumps(value.__code__))
value = (True, dill.dumps(value))
else:
value = (None, value)
elif fullcopy:
Expand Down Expand Up @@ -213,14 +201,8 @@ def reconstruct_object(flags, value):
ifdill, thing = value
if ifdill is None:
return thing
if ifdill in [False, 'False', b'False']:
return types.FunctionType(marshal.loads(thing), globals())
if ifdill in [True, 'True', b'True']:
if not dill_avail:
raise ValueError("the dictionary was constructed using "
"\"dill\" package, which is not available on the system")
else:
return dill.loads(thing)
return dill.loads(thing)
# should not be reached
raise ValueError("The object format is not recognized")
return value
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
'requests',
'setuptools',
'sympy',
'dill',
'h5py']


Expand Down
1 change: 1 addition & 0 deletions stdeb.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Depends:
python-requests
python-sympy
python-setuptools
python3-dill
Reccommends:
python-statsmodels,
Suggests:
Expand Down

0 comments on commit 24285d2

Please sign in to comment.