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   
37       
45       
47      """Helper routine to pickle an object to file socket fsock""" 
48   
49      cPickle.dump(object, fsock, protocol=2) 
 50   
52      """Treat problem of librarie""" 
53       
55          """Find the correct path for the given function. 
56             Due to ME call via MG some libraries might be messed up on the pickle 
57             This routine helps to find back which one we need.  
58          """ 
59   
60          try: 
61              return pickle.Unpickler.find_class(self, module, name) 
62          except ImportError: 
63              pass 
64           
65          newmodule = 'internal.%s' % module.rsplit('.',1)[1] 
66          try: 
67              return pickle.Unpickler.find_class(self, newmodule , name) 
68          except: 
69              pass 
70           
71          newmodule = 'madgraph.iolibs.%s' % module.rsplit('.',1)[1] 
72          try: 
73              return pickle.Unpickler.find_class(self, newmodule , name) 
74          except: 
75              pass         
76   
77          newmodule = 'madgraph.various.%s' % module.rsplit('.',1)[1] 
78          try: 
79              return pickle.Unpickler.find_class(self, newmodule , name) 
80          except: 
81              raise 
  82       
83   
85      """Helper routine to pickle an object to file socket fsock""" 
86   
87      p = UnPickler(fsock) 
88      return p.load() 
 89       
90