From: Gilles DAVID Date: Fri, 31 Mar 2017 07:46:01 +0000 (+0200) Subject: [PY3] PyString_AsString => Py_EncodeLocale(PyUnicode_AS_UNICODE()) X-Git-Tag: V9_0_0~5^2~8 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b10548082454f6ec58140ac2b2b8a01f71eaf098;p=modules%2Fmed.git [PY3] PyString_AsString => Py_EncodeLocale(PyUnicode_AS_UNICODE()) --- diff --git a/src/MEDCalculator/Swig/MEDCalculatorTypemaps.i b/src/MEDCalculator/Swig/MEDCalculatorTypemaps.i index ebbd5a0f9..2bad47bd5 100644 --- a/src/MEDCalculator/Swig/MEDCalculatorTypemaps.i +++ b/src/MEDCalculator/Swig/MEDCalculatorTypemaps.i @@ -20,6 +20,14 @@ #include +#if PY_VERSION_HEX < 0x03050000 +static char* +Py_EncodeLocale(const wchar_t *text, size_t *error_pos) +{ + return _Py_wchar2char(text, error_pos); +} +#endif + static PyObject* convertMEDCalculatorDBField(MEDCoupling::MEDCalculatorDBField *f, int owner) { PyObject *ret=0; @@ -40,7 +48,7 @@ void convertPyObjToRS(PyObject *o, MEDCoupling::MEDCalculatorDBRangeSelection& r } if(PyString_Check(o)) { - char *s=PyString_AsString(o); + char *s=Py_EncodeLocale(PyUnicode_AS_UNICODE(o), NULL); rs=s; return ; } diff --git a/src/MEDCouplingCorba_Swig/Client/MEDCouplingClient.i b/src/MEDCouplingCorba_Swig/Client/MEDCouplingClient.i index 3c31e7267..360f8b7aa 100644 --- a/src/MEDCouplingCorba_Swig/Client/MEDCouplingClient.i +++ b/src/MEDCouplingCorba_Swig/Client/MEDCouplingClient.i @@ -59,6 +59,16 @@ using namespace MEDCoupling; %nodefaultctor; %nodefaultdtor; +%{ +#if PY_VERSION_HEX < 0x03050000 +static char* +Py_EncodeLocale(const wchar_t *text, size_t *error_pos) +{ + return _Py_wchar2char(text, error_pos); +} +#endif +%} + namespace MEDCoupling { class MEDCouplingFieldDoubleClient @@ -78,7 +88,7 @@ namespace MEDCoupling PyObject *iorField=PyObject_CallMethod(orbPython,(char*)"object_to_string",(char*)"O",fieldPtr); if(!iorField) throw INTERP_KERNEL::Exception("Error : the input parameter of MEDCouplingFieldDoubleClient.New appears to differ from CORBA reference ! Expecting a FieldDouble CORBA reference !"); - char *ior=PyString_AsString(iorField); + char *ior=Py_EncodeLocale(PyUnicode_AS_UNICODE(iorField), NULL); int argc=0; CORBA::ORB_var orb=CORBA::ORB_init(argc,0); CORBA::Object_var fieldPtrCpp=orb->string_to_object(ior); @@ -110,7 +120,7 @@ namespace MEDCoupling PyObject *iorField=PyObject_CallMethod(orbPython,(char*)"object_to_string",(char*)"O",fieldPtr); if(!iorField) throw INTERP_KERNEL::Exception("Error : the input parameter of MEDCouplingFieldTemplateClient.New appears to differ from CORBA reference ! Expecting a FieldTemplate CORBA reference !"); - char *ior=PyString_AsString(iorField); + char *ior=Py_EncodeLocale(PyUnicode_AS_UNICODE(iorField), NULL); int argc=0; CORBA::ORB_var orb=CORBA::ORB_init(argc,0); CORBA::Object_var fieldPtrCpp=orb->string_to_object(ior); @@ -142,7 +152,7 @@ namespace MEDCoupling PyObject *iorField=PyObject_CallMethod(orbPython,(char*)"object_to_string",(char*)"O",fieldPtr); if(!iorField) throw INTERP_KERNEL::Exception("Error : the input parameter of MEDCouplingFieldTemplateClient.New appears to differ from CORBA reference ! Expecting a MultiFields CORBA reference !"); - char *ior=PyString_AsString(iorField); + char *ior=Py_EncodeLocale(PyUnicode_AS_UNICODE(iorField), NULL); int argc=0; CORBA::ORB_var orb=CORBA::ORB_init(argc,0); CORBA::Object_var fieldPtrCpp=orb->string_to_object(ior); @@ -175,7 +185,7 @@ namespace MEDCoupling PyObject *iorField=PyObject_CallMethod(orbPython,(char*)"object_to_string",(char*)"O",fieldPtr); if(!iorField) throw INTERP_KERNEL::Exception("Error : the input parameter of MEDCouplingFieldOverTimeClient.New appears to differ from CORBA reference ! Expecting a FieldOverTime CORBA reference !"); - char *ior=PyString_AsString(iorField); + char *ior=Py_EncodeLocale(PyUnicode_AS_UNICODE(iorField), NULL); int argc=0; CORBA::ORB_var orb=CORBA::ORB_init(argc,0); CORBA::Object_var fieldPtrCpp=orb->string_to_object(ior); @@ -207,7 +217,7 @@ namespace MEDCoupling PyObject *iorMesh=PyObject_CallMethod(orbPython,(char*)"object_to_string",(char*)"O",meshPtr); if(!iorMesh) throw INTERP_KERNEL::Exception("Error : the input parameter of MEDCouplingMeshClient.New appears to differ from CORBA reference ! Expecting a MeshCorbaInterface CORBA reference !"); - char *ior=PyString_AsString(iorMesh); + char *ior=Py_EncodeLocale(PyUnicode_AS_UNICODE(iorMesh), NULL); int argc=0; CORBA::ORB_var orb=CORBA::ORB_init(argc,0); CORBA::Object_var meshPtrCpp=orb->string_to_object(ior); @@ -282,7 +292,7 @@ namespace MEDCoupling PyObject *iorMesh=PyObject_CallMethod(orbPython,(char*)"object_to_string",(char*)"O",meshPtr); if(!iorMesh) throw INTERP_KERNEL::Exception("Error : the input parameter of MEDCouplingUMeshClient.New appears to differ from CORBA reference ! Expecting a UMeshCorbaInterface CORBA reference !"); - char *ior=PyString_AsString(iorMesh); + char *ior=Py_EncodeLocale(PyUnicode_AS_UNICODE(iorMesh), NULL); int argc=0; CORBA::ORB_var orb=CORBA::ORB_init(argc,0); CORBA::Object_var meshPtrCpp=orb->string_to_object(ior); @@ -314,7 +324,7 @@ namespace MEDCoupling PyObject *iorMesh=PyObject_CallMethod(orbPython,(char*)"object_to_string",(char*)"O",meshPtr); if(!iorMesh) throw INTERP_KERNEL::Exception("Error : the input parameter of MEDCoupling1SGTUMeshClient.New appears to differ from CORBA reference ! Expecting a 1SGTUMeshCorbaInterface CORBA reference !"); - char *ior=PyString_AsString(iorMesh); + char *ior=Py_EncodeLocale(PyUnicode_AS_UNICODE(iorMesh), NULL); int argc=0; CORBA::ORB_var orb=CORBA::ORB_init(argc,0); CORBA::Object_var meshPtrCpp=orb->string_to_object(ior); @@ -346,7 +356,7 @@ namespace MEDCoupling PyObject *iorMesh=PyObject_CallMethod(orbPython,(char*)"object_to_string",(char*)"O",meshPtr); if(!iorMesh) throw INTERP_KERNEL::Exception("Error : the input parameter of MEDCoupling1DGTUMeshClient.New appears to differ from CORBA reference ! Expecting a 1DGTUMeshCorbaInterface CORBA reference !"); - char *ior=PyString_AsString(iorMesh); + char *ior=Py_EncodeLocale(PyUnicode_AS_UNICODE(iorMesh), NULL); int argc=0; CORBA::ORB_var orb=CORBA::ORB_init(argc,0); CORBA::Object_var meshPtrCpp=orb->string_to_object(ior); @@ -378,7 +388,7 @@ namespace MEDCoupling PyObject *iorMesh=PyObject_CallMethod(orbPython,(char*)"object_to_string",(char*)"O",meshPtr); if(!iorMesh) throw INTERP_KERNEL::Exception("Error : the input parameter of MEDCouplingExtrudedMeshClient.New appears to differ from CORBA reference ! Expecting an ExtrudedMeshCorbaInterface CORBA reference !"); - char *ior=PyString_AsString(iorMesh); + char *ior=Py_EncodeLocale(PyUnicode_AS_UNICODE(iorMesh), NULL); int argc=0; CORBA::ORB_var orb=CORBA::ORB_init(argc,0); CORBA::Object_var meshPtrCpp=orb->string_to_object(ior); @@ -410,7 +420,7 @@ namespace MEDCoupling PyObject *iorMesh=PyObject_CallMethod(orbPython,(char*)"object_to_string",(char*)"O",meshPtr); if(!iorMesh) throw INTERP_KERNEL::Exception("Error : the input parameter of MEDCouplingCMeshClient.New appears to differ from CORBA reference ! Expecting a CMeshCorbaInterface CORBA reference !"); - char *ior=PyString_AsString(iorMesh); + char *ior=Py_EncodeLocale(PyUnicode_AS_UNICODE(iorMesh), NULL); int argc=0; CORBA::ORB_var orb=CORBA::ORB_init(argc,0); CORBA::Object_var meshPtrCpp=orb->string_to_object(ior); @@ -442,7 +452,7 @@ namespace MEDCoupling PyObject *iorMesh=PyObject_CallMethod(orbPython,(char*)"object_to_string",(char*)"O",meshPtr); if(!iorMesh) throw INTERP_KERNEL::Exception("Error : the input parameter of MEDCouplingIMeshClient.New appears to differ from CORBA reference ! Expecting a IMeshCorbaInterface CORBA reference !"); - char *ior=PyString_AsString(iorMesh); + char *ior=Py_EncodeLocale(PyUnicode_AS_UNICODE(iorMesh), NULL); int argc=0; CORBA::ORB_var orb=CORBA::ORB_init(argc,0); CORBA::Object_var meshPtrCpp=orb->string_to_object(ior); @@ -474,7 +484,7 @@ namespace MEDCoupling PyObject *iorMesh=PyObject_CallMethod(orbPython,(char*)"object_to_string",(char*)"O",meshPtr); if(!iorMesh) throw INTERP_KERNEL::Exception("Error : the input parameter of MEDCouplingCurveLinearMeshClient.New appears to differ from CORBA reference ! Expecting a CurveLinearMeshCorbaInterface CORBA reference !"); - char *ior=PyString_AsString(iorMesh); + char *ior=Py_EncodeLocale(PyUnicode_AS_UNICODE(iorMesh), NULL); int argc=0; CORBA::ORB_var orb=CORBA::ORB_init(argc,0); CORBA::Object_var meshPtrCpp=orb->string_to_object(ior); @@ -506,7 +516,7 @@ namespace MEDCoupling PyObject *iorMesh=PyObject_CallMethod(orbPython,(char*)"object_to_string",(char*)"O",meshPtr); if(!iorMesh) throw INTERP_KERNEL::Exception("Error : the input parameter of DataArrayDoubleClient.New appears to differ from CORBA reference ! Expecting a DataArrayDoubleCorbaInterface CORBA reference !"); - char *ior=PyString_AsString(iorMesh); + char *ior=Py_EncodeLocale(PyUnicode_AS_UNICODE(iorMesh), NULL); int argc=0; CORBA::ORB_var orb=CORBA::ORB_init(argc,0); CORBA::Object_var meshPtrCpp=orb->string_to_object(ior); @@ -538,7 +548,7 @@ namespace MEDCoupling PyObject *iorMesh=PyObject_CallMethod(orbPython,(char*)"object_to_string",(char*)"O",meshPtr); if(!iorMesh) throw INTERP_KERNEL::Exception("Error : the input parameter of DataArrayIntClient.New appears to differ from CORBA reference ! Expecting a DataArrayIntCorbaInterface CORBA reference !"); - char *ior=PyString_AsString(iorMesh); + char *ior=Py_EncodeLocale(PyUnicode_AS_UNICODE(iorMesh), NULL); int argc=0; CORBA::ORB_var orb=CORBA::ORB_init(argc,0); CORBA::Object_var meshPtrCpp=orb->string_to_object(ior);