From 42b466521a6a9240449b39ff106721bf51c92546 Mon Sep 17 00:00:00 2001 From: Jean-Philippe ARGAUD Date: Mon, 8 Oct 2018 20:28:15 +0200 Subject: [PATCH] Correction of Python 3 compatibility --- src/daComposant/daCore/Aidsm.py | 5 ++++- src/daSalome/daGUI/daGuiImpl/adaoCase.py | 4 ++-- src/daSalome/daYacsIntegration/daOptimizerLoop.py | 11 +++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/daComposant/daCore/Aidsm.py b/src/daComposant/daCore/Aidsm.py index 953ef8d..a13a093 100644 --- a/src/daComposant/daCore/Aidsm.py +++ b/src/daComposant/daCore/Aidsm.py @@ -742,7 +742,10 @@ class Aidsm(object): if sys.version_info[0] == 2: del self.__adaoObject # Because it breaks pickle in Python 2. Not required for Python 3 del self.__case # Because it breaks pickle in Python 2. Not required for Python 3 - return 0 + if sys.version_info.major < 3: + return 0 + else: + return self.__StoredInputs # ============================================================================== if __name__ == "__main__": diff --git a/src/daSalome/daGUI/daGuiImpl/adaoCase.py b/src/daSalome/daGUI/daGuiImpl/adaoCase.py index 8c20963..7f65168 100644 --- a/src/daSalome/daGUI/daGuiImpl/adaoCase.py +++ b/src/daSalome/daGUI/daGuiImpl/adaoCase.py @@ -118,8 +118,8 @@ class AdaoCase: def validationReportforJDC(self): rtn = "Validation report is empty." if self.eficas_editor.jdc: - rtn = u"Validation report for the selected ADAO case:\n\n" - rtn += unicode( self.eficas_editor.jdc.report()) + rtn = "Validation report for the selected ADAO case:\n\n" + rtn += self.eficas_editor.jdc.report() return rtn def showTreeAdaoCase(self): diff --git a/src/daSalome/daYacsIntegration/daOptimizerLoop.py b/src/daSalome/daYacsIntegration/daOptimizerLoop.py index ea8ad0b..3a44bd2 100644 --- a/src/daSalome/daYacsIntegration/daOptimizerLoop.py +++ b/src/daSalome/daYacsIntegration/daOptimizerLoop.py @@ -30,6 +30,7 @@ except: import pickle import numpy import threading +import sys # Pour disposer des classes dans l'espace de nommage lors du pickle from daCore.AssimilationStudy import AssimilationStudy @@ -361,7 +362,7 @@ class AssimilationAlgorithm_asynch(SALOMERuntime.OptimizerAlgASync): self.pool.destroyAll() def obs(self, var, info): - # print "Call observer %s" % info + # print("Call observer %s with var type %s" %(info,type(var)) sample = pilot.StructAny_New(self.runtime.getTypeCode('SALOME_TYPES/ParametricInput')) # Fake data @@ -445,9 +446,11 @@ class AssimilationAlgorithm_asynch(SALOMERuntime.OptimizerAlgASync): # # Remove data observers, required to pickle assimilation study object # for observer_name in list(self.da_study.observers_dict.keys()): # self.ADD.removeDataObserver(observer_name, self.obs) - self.da_study.YI_prepare_to_pickle() - result = pickle.dumps(self.da_study) - return result + if sys.version_info.major < 3: + self.da_study.YI_prepare_to_pickle() + return pickle.dumps(self.da_study) + else: + return pickle.dumps(self.da_study.getResults().prepare_to_pickle()) # Obligatoire ??? def finish(self): -- 2.39.2