From fd225011ceb501efc4a8d737f49cd97754451141 Mon Sep 17 00:00:00 2001 From: rnv Date: Wed, 24 May 2017 10:30:56 +0300 Subject: [PATCH] Python3 porting: 1-st draft version. --- .../AddComponent_CheckOfUndefined.cxx | 14 +++++++++++++- src/FactorialComponent/FactorialComponent.py | 16 ++++++++-------- .../SIGNALSComponent_CheckOfUndefined.cxx | 15 ++++++++++++++- src/SyrComponent/COMPONENT_shared_modules.py | 2 +- src/SyrControlComponent/SyrControlComponent.py | 12 ++++++------ 5 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/AddComponent/AddComponent_CheckOfUndefined.cxx b/src/AddComponent/AddComponent_CheckOfUndefined.cxx index 09f2058..ae2ec2c 100644 --- a/src/AddComponent/AddComponent_CheckOfUndefined.cxx +++ b/src/AddComponent/AddComponent_CheckOfUndefined.cxx @@ -66,6 +66,14 @@ using namespace std; extern "C" void HandleServerSideSignals(CORBA::ORB_ptr theORB); +#if PY_VERSION_HEX < 0x03050000 +static wchar_t* +Py_DecodeLocale(const char *arg, size_t *size) +{ + return _Py_char2wchar(arg, size); +} +#endif + int main(int argc, char* argv[]) { #ifdef HAVE_MPI2 @@ -96,8 +104,12 @@ int main(int argc, char* argv[]) } else { + wchar_t **changed_argv = new wchar_t*[argc]; + for (int i = 0; i < argc; i++) { + changed_argv[i] = Py_DecodeLocale(argv[i], NULL); + } Py_Initialize() ; - PySys_SetArgv( argc , argv ) ; + PySys_SetArgv( argc , changed_argv ) ; } char *containerName = ""; diff --git a/src/FactorialComponent/FactorialComponent.py b/src/FactorialComponent/FactorialComponent.py index b978f67..84b1272 100644 --- a/src/FactorialComponent/FactorialComponent.py +++ b/src/FactorialComponent/FactorialComponent.py @@ -40,25 +40,25 @@ class FactorialComponent( SuperVisionTest__POA.FactorialComponent, SALOME_Compon def eval(self, val): self.beginService( 'FactorialComponent eval' ) - print "eval :",val + print("eval :",val) if (val < 0): - raise ArgumentError("factorial must be positive, not " + `val`) + raise ArgumentError("factorial must be positive, not " + repr(val)) if (val < 2): - print "eval return",val + print("eval return",val) self.sendMessage( NOTIF_STEP , "Done" ) self.endService( 'FactorialComponent eval' ) return val else: val1 = self.eval(val-1) self.sendMessage( NOTIF_TRACE , "One More Time" ) - print "eval return",val," * ",val1 + print("eval return",val," * ",val1) return val * val1 def sigma(self, val): self.beginService( 'FactorialComponent sigma' ) - print "sigma :",val + print("sigma :",val) if (val < 0): - raise ArgumentError("sigma must be positive, not " + `val`) + raise ArgumentError("sigma must be positive, not " + repr(val)) i = 0 while i < 10000 : n = 1 @@ -67,7 +67,7 @@ class FactorialComponent( SuperVisionTest__POA.FactorialComponent, SALOME_Compon s = s + n n = n + 1 i = i + 1 - print "sigma returns",s + print("sigma returns",s) self.endService( 'FactorialComponent sigma' ) return s @@ -78,5 +78,5 @@ class FactorialComponent( SuperVisionTest__POA.FactorialComponent, SALOME_Compon def __init__(self, orb, poa, this, containerName, instanceName, interfaceName): SALOME_ComponentPy_i.__init__(self, orb, poa, this, containerName, instanceName, interfaceName, False) - print "FactorialComponent::__init__" + print("FactorialComponent::__init__") diff --git a/src/SIGNALSComponent/SIGNALSComponent_CheckOfUndefined.cxx b/src/SIGNALSComponent/SIGNALSComponent_CheckOfUndefined.cxx index cf17237..0f97f6b 100644 --- a/src/SIGNALSComponent/SIGNALSComponent_CheckOfUndefined.cxx +++ b/src/SIGNALSComponent/SIGNALSComponent_CheckOfUndefined.cxx @@ -65,6 +65,15 @@ using namespace std; extern "C" void HandleServerSideSignals(CORBA::ORB_ptr theORB); + +#if PY_VERSION_HEX < 0x03050000 +static wchar_t* +Py_DecodeLocale(const char *arg, size_t *size) +{ + return _Py_char2wchar(arg, size); +} +#endif + int main(int argc, char* argv[]) { #ifdef HAVE_MPI2 @@ -95,8 +104,12 @@ int main(int argc, char* argv[]) } else { + wchar_t **changed_argv = new wchar_t*[argc]; + for (int i = 0; i < argc; i++) { + changed_argv[i] = Py_DecodeLocale(argv[i], NULL); + } Py_Initialize() ; - PySys_SetArgv( argc , argv ) ; + PySys_SetArgv( argc , changed_argv ) ; } char *containerName = ""; diff --git a/src/SyrComponent/COMPONENT_shared_modules.py b/src/SyrComponent/COMPONENT_shared_modules.py index 92220b2..22a74f0 100644 --- a/src/SyrComponent/COMPONENT_shared_modules.py +++ b/src/SyrComponent/COMPONENT_shared_modules.py @@ -28,7 +28,7 @@ # see salome_shared_modules.py # (avoids incomplete import at run time) -print "============== import SuperVisionTest =======================" +print("============== import SuperVisionTest =======================") import SuperVisionTest diff --git a/src/SyrControlComponent/SyrControlComponent.py b/src/SyrControlComponent/SyrControlComponent.py index 5de3f8a..35e722a 100644 --- a/src/SyrControlComponent/SyrControlComponent.py +++ b/src/SyrControlComponent/SyrControlComponent.py @@ -96,7 +96,7 @@ class SyrControlComponent( SuperVisionTest__POA.SyrControlComponent, SALOME_Comp if iN < max : N = iN + 1 OutLoop = 1 - print 'SyrControlComponent LOOPN InLoop iN OutLoop N',InLoop,iN,OutLoop,N + print('SyrControlComponent LOOPN InLoop iN OutLoop N',InLoop,iN,OutLoop,N) self.endService( 'SyrControlComponent LOOPN' ) return OutLoop,N,0 @@ -106,7 +106,7 @@ class SyrControlComponent( SuperVisionTest__POA.SyrControlComponent, SALOME_Comp OutLoop = 1 else : OutLoop = 0 - print 'SyrControlComponent WHILENOTONE OutLoop N',OutLoop,N + print('SyrControlComponent WHILENOTONE OutLoop N',OutLoop,N) return OutLoop def IFNOTEVEN( self , N ) : @@ -114,7 +114,7 @@ class SyrControlComponent( SuperVisionTest__POA.SyrControlComponent, SALOME_Comp Odd = 0 if Even == 0 : Odd = 1 - print 'SyrControlComponent IFNOTEVEN Odd Even N',Odd,Even,N + print('SyrControlComponent IFNOTEVEN Odd Even N',Odd,Even,N) return Odd,Even def LOOPi( self , InLoop , ii ): @@ -127,19 +127,19 @@ class SyrControlComponent( SuperVisionTest__POA.SyrControlComponent, SALOME_Comp if ii+1 < 2 : i = ii + 1 OutLoop = 1 - print 'SyrControlComponent LOOPi InLoop ii OutLoop i',InLoop,ii,OutLoop,i + print('SyrControlComponent LOOPi InLoop ii OutLoop i',InLoop,ii,OutLoop,i) return OutLoop,i def WHILEEVEN( self , N ) : OutLoop = self.Syr.C_ISEVEN( N ) - print 'SyrControlComponent WHILEEVEN OutLoop N',OutLoop,N + print('SyrControlComponent WHILEEVEN OutLoop N',OutLoop,N) return OutLoop def __init__(self, orb, poa, this, containerName, instanceName, interfaceName): SALOME_ComponentPy_i.__init__(self, orb, poa, this, containerName, instanceName, interfaceName, True) self.Syr = lcc.FindOrLoadComponent( 'FactoryServer' , 'SyrComponent' ) - print "SyrControlComponent::__init__",dir(self.Syr) + print("SyrControlComponent::__init__",dir(self.Syr)) def getVersion( self ): import salome_version -- 2.39.2