1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """Function to save any Python object to file."""
17
18 import pickle
19 import cPickle
20
21 from . import files as files
22
24 """Exception raised if an error occurs in while trying to save an
25 object to file."""
26 pass
27
29 """Save any Python object to file filename"""
30
31 if not isinstance(filename, basestring):
32 raise SaveObjectError, "filename must be a string"
33
34 files.write_to_file(filename, pickle_object, object, log=log)
35
36 return True
37
44
46 """Helper routine to pickle an object to file socket fsock"""
47
48 cPickle.dump(object, fsock, protocol=2)
49
51 """Treat problem of librarie"""
52
54 """Find the correct path for the given function.
55 Due to ME call via MG some libraries might be messed up on the pickle
56 This routine helps to find back which one we need.
57 """
58
59
60 if module == 'loop_me_comparator':
61 module = 'tests.parallel_tests.loop_me_comparator'
62
63 try:
64 return pickle.Unpickler.find_class(self, module, name)
65 except ImportError:
66 pass
67 newmodule = 'internal.%s' % module.rsplit('.',1)[1]
68 try:
69 return pickle.Unpickler.find_class(self, newmodule , name)
70 except Exception:
71 pass
72
73 newmodule = 'madgraph.iolibs.%s' % module.rsplit('.',1)[1]
74 try:
75 return pickle.Unpickler.find_class(self, newmodule , name)
76 except Exception:
77 pass
78
79 newmodule = 'madgraph.various.%s' % module.rsplit('.',1)[1]
80 try:
81 return pickle.Unpickler.find_class(self, newmodule , name)
82 except Exception:
83 raise
84
85
87 """Helper routine to pickle an object to file socket fsock"""
88
89 p = UnPickler(fsock)
90 return p.load()
91
92