From: rnv Date: Tue, 27 Jun 2017 16:07:30 +0000 (+0300) Subject: Merge Python 3 porting: additional chnages. X-Git-Tag: V9_0_0~24 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3e8cb819ece8ab264fe0c8d6d970387d2bfeb755;hp=8aabfc9256249b3d60820832ac3450978a5a0f19;p=modules%2Fkernel.git Merge Python 3 porting: additional chnages. --- diff --git a/bin/appliskel/tests/salomeInstance/instances.py b/bin/appliskel/tests/salomeInstance/instances.py index 50ecfa80d..02a52cc2e 100644 --- a/bin/appliskel/tests/salomeInstance/instances.py +++ b/bin/appliskel/tests/salomeInstance/instances.py @@ -91,13 +91,13 @@ class TestLauncher(unittest.TestCase): # Connect to one instance import runConsole - port = all_instances[len(all_instances)/2].get_port() + port = all_instances[len(all_instances)//2].get_port() print("Connect to instance running on port", port) self.__connectToInstance(port) # Connect to another instance import runConsole - port = all_instances[len(all_instances)/4].get_port() + port = all_instances[len(all_instances)//4].get_port() print("Connect to instance running on port", port) self.__connectToInstance(port) diff --git a/bin/salome_utils.py b/bin/salome_utils.py index 603b8168c..5c2297330 100644 --- a/bin/salome_utils.py +++ b/bin/salome_utils.py @@ -56,10 +56,9 @@ def _try_bool( arg ): are supported. If does not represent a boolean, an exception is raised. """ - import types - if type( arg ) == bool : + if isinstance(arg, bool) : return arg - elif type( arg ) == bytes : + elif isinstance(arg, (str, bytes)): v = str( arg ).lower() if v in [ "yes", "y", "true" ]: return True elif v in [ "no", "n", "false" ]: return False diff --git a/idl/SALOMEDS.idl b/idl/SALOMEDS.idl index bc22b3d33..eb14c2fa0 100644 --- a/idl/SALOMEDS.idl +++ b/idl/SALOMEDS.idl @@ -41,7 +41,7 @@ module SALOMEDS { /*! \brief Name of the file in which the %Study is saved. */ - typedef string URLPath; + typedef wstring URLPath; /*! \brief Main identifier of an object in %SALOME application */ @@ -55,6 +55,8 @@ module SALOMEDS */ typedef string SalomeReference; +//! List of file names + typedef sequence ListOfFileNames; //! List of modification dates of a study typedef sequence ListOfDates ; //! An unbounded sequence of strings @@ -125,6 +127,7 @@ module SALOMEDS */ SComponent NewComponent(in string ComponentDataType) raises(LockProtection); + /*! \brief Definition of the instance to the %SComponent Defines the instance to the %SComponent. @@ -246,8 +249,7 @@ module SALOMEDS \param anObject The %SObject which will be identified \param theGUID GUID has the following format "00000000-0000-0000-0000-000000000000" */ - - void SetGUID(in SObject anObject, in string theGUID) raises(LockProtection); + void SetGUID(in SObject anObject, in string theGUID) raises(LockProtection); /*! Searches for a definite %SObject with a definite GUID and returns True if it finds it. @@ -402,7 +404,10 @@ Searches for a definite %SObject with a definite GUID and returns True if it fin This is equivalent to the methods setName() & getName() */ - readonly attribute string Name; // equivalent to getName() + attribute wstring Name; // equivalent to getName() + +/*! \brief Indicate the file where the %study has been saved +*/ //! Sequence containing %SObjects typedef sequence ListOfSObject; @@ -518,7 +523,7 @@ Searches for a definite %SObject with a definite GUID and returns True if it fin /*! \brief Indicate the file where the %study has been saved */ - attribute string URL; + attribute wstring URL; /*! \brief List of %SObjects diff --git a/src/Basics/Basics_Utils.cxx b/src/Basics/Basics_Utils.cxx index 73b4e800e..97d6c0b5f 100644 --- a/src/Basics/Basics_Utils.cxx +++ b/src/Basics/Basics_Utils.cxx @@ -106,6 +106,36 @@ namespace Kernel_Utils return guid; } + const wchar_t* decode(const char* encoded) + { + setlocale(LC_ALL, ""); + size_t length = strlen(encoded) + sizeof(char); + wchar_t* decoded = new wchar_t[length]; + memset( decoded, '\0', length); + mbstowcs(decoded, encoded, length); + return decoded; + } + + const wchar_t* decode_s(std::string encoded) + { + return decode(encoded.c_str()); + } + + const char* encode(const wchar_t* decoded) + { + setlocale(LC_ALL, ""); + size_t length = std::wcslen(decoded) + sizeof(wchar_t); + char* encoded = new char[length]; + memset( encoded, '\0', length); + wcstombs(encoded, decoded, length); + return encoded; + } + + std::string encode_s(const wchar_t* decoded) + { + return std::string(encode(decoded)); + } + #ifndef WIN32 void print_traceback() { diff --git a/src/Basics/Basics_Utils.hxx b/src/Basics/Basics_Utils.hxx index 5843afb75..cef9dc3fc 100644 --- a/src/Basics/Basics_Utils.hxx +++ b/src/Basics/Basics_Utils.hxx @@ -56,6 +56,11 @@ namespace Kernel_Utils ObjectdID //!< Global usage object identifier ID }; + const wchar_t* decode(const char* encoded); + const wchar_t* decode_s(std::string encoded); + const char* encode(const wchar_t* decoded); + std::string encode_s(const wchar_t* decoded); + //! Get predefined GUID BASICS_EXPORT std::string GetGUID( GUIDtype ); #ifndef WIN32 diff --git a/src/HDFPersist/HDFfile.cc b/src/HDFPersist/HDFfile.cc index 71b44e112..d372e460c 100644 --- a/src/HDFPersist/HDFfile.cc +++ b/src/HDFPersist/HDFfile.cc @@ -58,29 +58,36 @@ void HDFfile::CreateOnDisk() void HDFfile::OpenOnDisk(hdf_access_mode access_mode) { - _access_mode = access_mode; + _access_mode = access_mode; + std::string msgerr; - switch (_access_mode) - { - case HDF_RDWR : - if (access(_name,F_OK)) + switch (_access_mode) { - if ((_id = HDFfileCreate(_name)) < 0) - throw HDFexception("Can't open HDF file"); + case HDF_RDWR: + if (access(_name, F_OK)) + { + if ((_id = HDFfileCreate(_name)) < 0) { + msgerr = "Can't create HDF in RW mode file" + std::string(_name); + throw HDFexception(msgerr.c_str()); + } + } + else if ((_id = HDFfileOpen(_name, _access_mode)) < 0) { + msgerr = "Can't open HDF in RW mode file " + std::string(_name); + throw HDFexception(msgerr.c_str()); + } + break; + + case HDF_RDONLY: + if ((_id = HDFfileOpen(_name, _access_mode)) < 0) { + msgerr = "Can't open HDF in RO mode file " + std::string(_name); + throw HDFexception(msgerr.c_str()); + } + break; + + default: + msgerr = "Can't open HDF file " + std::string(_name) + " : bad acces option"; + throw HDFexception(msgerr.c_str()); } - else - if ((_id = HDFfileOpen(_name,_access_mode)) < 0) - throw HDFexception("Can't open HDF file"); - break; - - case HDF_RDONLY : - if ((_id = HDFfileOpen(_name,_access_mode)) < 0) - throw HDFexception("Can't open HDF file"); - break; - - default : - throw HDFexception("Can't open HDF file : bad acces option"); - } } void HDFfile::CloseOnDisk() diff --git a/src/KERNEL_PY/salome_study.py b/src/KERNEL_PY/salome_study.py index be6d72f29..5626aecdf 100755 --- a/src/KERNEL_PY/salome_study.py +++ b/src/KERNEL_PY/salome_study.py @@ -302,7 +302,9 @@ def salome_study_init(theStudyPath=None): pass import types - if theStudyPath and type(theStudyPath) == types.StringType: + if theStudyPath and isinstance(theStudyPath, (str, bytes)): + if isinstance(theStudyPath, bytes): + theStudyPath = str(theStudyPath, 'UTF8') openStudy(theStudyPath) myStudyName = myStudy._get_Name() diff --git a/src/SALOMEDS/SALOMEDS_Client.cxx b/src/SALOMEDS/SALOMEDS_Client.cxx index 12662b5f1..db0f0e245 100644 --- a/src/SALOMEDS/SALOMEDS_Client.cxx +++ b/src/SALOMEDS/SALOMEDS_Client.cxx @@ -30,6 +30,7 @@ #include CORBA_SERVER_HEADER(SALOMEDS) #include "SALOMEDS_AttributeName_i.hxx" #include "SALOME_KernelServices.hxx" +#include "Basics_Utils.hxx" #include "utilities.h" #include "HDFOI.hxx" @@ -192,7 +193,7 @@ static void Test() DumpStudy(); // Save as - myStudy->SaveAs("/home/edeville/Study1.hdf", false, false); + myStudy->SaveAs(Kernel_Utils::decode("/home/edeville/Study1.hdf"), false, false); // Get Persistent Reference of the study test name = myStudy->GetPersistentReference(); diff --git a/src/SALOMEDS/SALOMEDS_Study.cxx b/src/SALOMEDS/SALOMEDS_Study.cxx index 0583c10ca..86629e271 100644 --- a/src/SALOMEDS/SALOMEDS_Study.cxx +++ b/src/SALOMEDS/SALOMEDS_Study.cxx @@ -125,8 +125,9 @@ bool SALOMEDS_Study::Open(const std::string& theStudyUrl) { if(CORBA::is_nil(_corba_impl)) return false; - - if (!_corba_impl->Open(theStudyUrl.c_str())) + std::wstring wtheStudyUrl = std::wstring(theStudyUrl.begin(), theStudyUrl.end()); + + if (!_corba_impl->Open( (wchar_t*)wtheStudyUrl.c_str() ) ) return false; return true; @@ -145,7 +146,7 @@ bool SALOMEDS_Study::SaveAs(const std::string& theUrl, bool theMultiFile, bool t if(CORBA::is_nil(_corba_impl)) return false; - return _corba_impl->SaveAs((char*)theUrl.c_str(), theMultiFile, theASCII); + return _corba_impl->SaveAs(Kernel_Utils::decode_s(theUrl), theMultiFile, theASCII); } SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb) @@ -497,10 +498,19 @@ std::string SALOMEDS_Study::Name() SALOMEDS::Locker lock; aName = _local_impl->Name(); } - else aName = _corba_impl->Name(); + else aName = Kernel_Utils::encode_s(_corba_impl->Name()); return aName; } +void SALOMEDS_Study::Name(const std::string& theName) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + _local_impl->Name(theName); + } + else _corba_impl->Name(Kernel_Utils::decode_s(theName)); +} + bool SALOMEDS_Study::IsSaved() { bool isSaved; @@ -549,7 +559,8 @@ std::string SALOMEDS_Study::URL() SALOMEDS::Locker lock; aURL = _local_impl->URL(); } - else aURL = _corba_impl->URL(); + else + aURL = Kernel_Utils::encode_s(_corba_impl->URL()); return aURL; } @@ -559,7 +570,7 @@ void SALOMEDS_Study::URL(const std::string& url) SALOMEDS::Locker lock; _local_impl->URL(url); } - else _corba_impl->URL((char*)url.c_str()); + else _corba_impl->URL(Kernel_Utils::decode_s(url)); } std::vector<_PTR(SObject)> SALOMEDS_Study::FindDependances(const _PTR(SObject)& theSO) diff --git a/src/SALOMEDS/SALOMEDS_Study.hxx b/src/SALOMEDS/SALOMEDS_Study.hxx index 4f3b6db1f..affbad4fc 100644 --- a/src/SALOMEDS/SALOMEDS_Study.hxx +++ b/src/SALOMEDS/SALOMEDS_Study.hxx @@ -80,6 +80,7 @@ public: virtual _PTR(SComponentIterator) NewComponentIterator(); virtual _PTR(StudyBuilder) NewBuilder(); virtual std::string Name(); + virtual void Name(const std::string& name); virtual bool IsSaved(); virtual void IsSaved(bool save); virtual bool IsModified(); diff --git a/src/SALOMEDS/SALOMEDS_Study_i.cxx b/src/SALOMEDS/SALOMEDS_Study_i.cxx index 1ac5ee0a3..19abf1b64 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.cxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.cxx @@ -372,7 +372,7 @@ void SALOMEDS_Study_i::Clear() * Purpose : Open a Study from it's persistent reference */ //============================================================================ -bool SALOMEDS_Study_i::Open(const char* aUrl) +bool SALOMEDS_Study_i::Open(const wchar_t* aWUrl) throw(SALOME::SALOME_Exception) { if (!_closed) @@ -382,7 +382,8 @@ bool SALOMEDS_Study_i::Open(const char* aUrl) Unexpect aCatch(SalomeException); MESSAGE("Begin of SALOMEDS_Study_i::Open"); - + + std::string aUrl = Kernel_Utils::encode_s(aWUrl); bool res = _impl->Open(std::string(aUrl)); // update desktop title with new study name @@ -411,11 +412,13 @@ CORBA::Boolean SALOMEDS_Study_i::Save(CORBA::Boolean theMultiFile, CORBA::Boolea * Purpose : Save a study to the persistent reference aUrl */ //============================================================================ -CORBA::Boolean SALOMEDS_Study_i::SaveAs(const char* aUrl, CORBA::Boolean theMultiFile, CORBA::Boolean theASCII) +CORBA::Boolean SALOMEDS_Study_i::SaveAs(const wchar_t* aWUrl, CORBA::Boolean theMultiFile, CORBA::Boolean theASCII) { SALOMEDS::Locker lock; if (_closed) throw SALOMEDS::Study::StudyInvalidReference(); + + std::string aUrl = Kernel_Utils::encode_s(aWUrl); return _impl->SaveAs(std::string(aUrl), _factory, theMultiFile, theASCII); } @@ -832,11 +835,23 @@ SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder() * Purpose : get study name */ //============================================================================ -char* SALOMEDS_Study_i::Name() +wchar_t* SALOMEDS_Study_i::Name() { SALOMEDS::Locker lock; // Name is specified as IDL attribute: user exception cannot be raised - return CORBA::string_dup(_impl->Name().c_str()); + return CORBA::wstring_dup(Kernel_Utils::decode_s(_impl->Name())); +} + +//============================================================================ +/*! Function : Name + * Purpose : set study name + */ +//============================================================================ +void SALOMEDS_Study_i::Name(const wchar_t* wname) +{ + SALOMEDS::Locker lock; + // Name is specified as IDL attribute: user exception cannot be raised + _impl->Name(Kernel_Utils::encode_s(wname)); } //============================================================================ @@ -899,11 +914,11 @@ void SALOMEDS_Study_i::Modified() * Purpose : get URL of the study (persistent reference of the study) */ //============================================================================ -char* SALOMEDS_Study_i::URL() +wchar_t* SALOMEDS_Study_i::URL() { - SALOMEDS::Locker lock; + SALOMEDS::Locker lock; // URL is specified as IDL attribute: user exception cannot be raised - return CORBA::string_dup(_impl->URL().c_str()); + return CORBA::wstring_dup(Kernel_Utils::decode_s(_impl->URL())); } //============================================================================ @@ -911,11 +926,11 @@ char* SALOMEDS_Study_i::URL() * Purpose : set URL of the study (persistent reference of the study) */ //============================================================================ -void SALOMEDS_Study_i::URL(const char* url) +void SALOMEDS_Study_i::URL(const wchar_t* wurl) { SALOMEDS::Locker lock; // URL is specified as IDL attribute: user exception cannot be raised - _impl->URL(std::string((char*)url)); + _impl->URL(Kernel_Utils::encode_s(wurl)); // update desktop title with new study name NameChanged(); diff --git a/src/SALOMEDS/SALOMEDS_Study_i.hxx b/src/SALOMEDS/SALOMEDS_Study_i.hxx index 232b0fb4c..d1c3d7f22 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.hxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.hxx @@ -76,7 +76,7 @@ public: \param char* arguments, the study URL \return Study_ptr arguments */ - virtual bool Open(const char* aStudyUrl) throw (SALOME::SALOME_Exception); + virtual bool Open(const wchar_t* aStudyUrl) throw (SALOME::SALOME_Exception); //! method to save a Study virtual CORBA::Boolean Save(CORBA::Boolean theMultiFile, CORBA::Boolean theASCII); @@ -85,7 +85,7 @@ public: /*! \param char* arguments, the new URL of the study */ - virtual CORBA::Boolean SaveAs(const char* aUrl, CORBA::Boolean theMultiFile, CORBA::Boolean theASCII); + virtual CORBA::Boolean SaveAs(const wchar_t* aUrl, CORBA::Boolean theMultiFile, CORBA::Boolean theASCII); //! method to copy the object /*! @@ -202,7 +202,13 @@ public: /*! \return char* arguments, the study name */ - virtual char* Name(); + virtual wchar_t* Name(); + + //! method to set study name + /*! + \param name char* arguments, the study name + */ + virtual void Name(const wchar_t* name); //! method to get if study has been saved /*! @@ -229,13 +235,13 @@ public: /*! \return char* arguments, the study URL */ - virtual char* URL(); + virtual wchar_t* URL(); //! method to set URL of the study /*! \param url char* arguments, the study URL */ - virtual void URL(const char* url); + virtual void URL(const wchar_t* url); static void IORUpdated(SALOMEDSImpl_AttributeIOR* theAttribute); diff --git a/src/SALOMEDS/Test/SALOMEDSTest_AttributeComment.cxx b/src/SALOMEDS/Test/SALOMEDSTest_AttributeComment.cxx index 455bde6b1..07f9e976b 100755 --- a/src/SALOMEDS/Test/SALOMEDSTest_AttributeComment.cxx +++ b/src/SALOMEDS/Test/SALOMEDSTest_AttributeComment.cxx @@ -25,6 +25,8 @@ * Use code of SALOMEDS_AttributeComment.cxx */ +//#include "Basics_Utils.hxx" + void SALOMEDSTest::testAttributeComment() { //Create Study diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx index c76daf908..773f16e5f 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx @@ -1583,6 +1583,17 @@ std::string SALOMEDSImpl_Study::Name() return Kernel_Utils::GetBaseName( _name, false ); } +//============================================================================ +/*! Function : Name + * Purpose : set study name + */ +//============================================================================ +void SALOMEDSImpl_Study::Name(const std::string& name) +{ + _errorCode = ""; + _name = name; +} + //============================================================================ /*! Function : IsSaved * Purpose : get if study has been saved diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx index f1c1d23ba..9ed178cf6 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx @@ -195,6 +195,9 @@ public: //! method to get study name virtual std::string Name(); + + //! method to set study name + virtual void Name(const std::string& name); //! method to get if study has been saved virtual bool IsSaved(); diff --git a/src/SALOMESDS/TestSalomeSDS.py b/src/SALOMESDS/TestSalomeSDS.py index a4302f27c..e00a5ed77 100644 --- a/src/SALOMESDS/TestSalomeSDS.py +++ b/src/SALOMESDS/TestSalomeSDS.py @@ -48,7 +48,7 @@ def work(t): import TestSalomeSDSHelper0 import os,subprocess fname=os.path.splitext(TestSalomeSDSHelper0.__file__)[0]+".py" - proc=subprocess.Popen(["python",fname],stdout=subprocess.PIPE,stderr=subprocess.PIPE) + proc = subprocess.Popen(["python3", fname], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out,err=proc.communicate() if proc.returncode!=0: print(out)