From: Gilles DAVID Date: Wed, 19 Apr 2017 14:47:37 +0000 (+0200) Subject: Python3: résolution des problèmes X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9a352d6ca759733268e985381b99ef1b5c0fc73e;p=tools%2Fmedcoupling.git Python3: résolution des problèmes Compilation and tests OK with Python 2.7. Python 3: unicode todo --- diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest1.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest1.py index 7d7799c9e..c5e027dc2 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest1.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest1.py @@ -17,6 +17,9 @@ # # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # +from __future__ import division +# Uncomment to be coherent with Python 3 +# from __future__ import unicode_literals from MEDCoupling import * import unittest diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest2.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest2.py index a261817e6..da8cdae30 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest2.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest2.py @@ -17,6 +17,9 @@ # # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # +from __future__ import division +# Uncomment to be coherent with Python 3 +# from __future__ import unicode_literals from MEDCoupling import * import unittest diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest3.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest3.py index 10ed467b4..3a38b7196 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest3.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest3.py @@ -17,6 +17,9 @@ # # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # +from __future__ import division +# Uncomment to be coherent with Python 3 +# from __future__ import unicode_literals from MEDCoupling import * import unittest diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest4.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest4.py index f0586d109..a9203fc52 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest4.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest4.py @@ -17,6 +17,9 @@ # # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # +from __future__ import division +# Uncomment to be coherent with Python 3 +# from __future__ import unicode_literals from MEDCoupling import * import unittest @@ -761,7 +764,7 @@ class MEDCouplingBasicsTest4(unittest.TestCase): pass expected1=[-0.9,1.3,1.7,2.1,3.,3.] for i in range(6): - self.assertAlmostEqual(expected1[i],res[i/2][i%2],14) + self.assertAlmostEqual(expected1[i], res[i // 2][i % 2], 14) pass # d1.rearrange(2); @@ -774,7 +777,7 @@ class MEDCouplingBasicsTest4(unittest.TestCase): pass expected2=[1.,3.,-0.9,3.] for i in range(4): - self.assertAlmostEqual(expected2[i],res[i/2][i%2],14) + self.assertAlmostEqual(expected2[i], res[i // 2][i % 2], 14) pass # d1.rearrange(1); @@ -787,7 +790,7 @@ class MEDCouplingBasicsTest4(unittest.TestCase): pass expected3=[-0.9,3.] for i in range(2): - self.assertAlmostEqual(expected3[i],res[i/2][i%2],14) + self.assertAlmostEqual(expected3[i], res[i // 2][i % 2], 14) pass pass @@ -1502,7 +1505,7 @@ class MEDCouplingBasicsTest4(unittest.TestCase): baseMesh = MEDCouplingUMesh.New("box_circle", 2) baseMesh.allocateCells(2) - meshCoords = DataArrayDouble.New(coords, len(coords)/2, 2) + meshCoords = DataArrayDouble.New(coords, len(coords) // 2, 2) meshCoords.setInfoOnComponents(["X [au]", "Y [au]"]) baseMesh.setCoords(meshCoords) @@ -1533,7 +1536,7 @@ class MEDCouplingBasicsTest4(unittest.TestCase): connec = list(range(4)) m1 = MEDCouplingUMesh.New("box", 2) m1.allocateCells(1) - meshCoords = DataArrayDouble.New(coords, len(coords)/2, 2) + meshCoords = DataArrayDouble.New(coords, len(coords) // 2, 2) m1.setCoords(meshCoords) m1.insertNextCell(NORM_POLYGON, connec) m1.finishInsertingCells() diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py index 08fa757b9..4725d855d 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py @@ -17,6 +17,9 @@ # # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # +from __future__ import division +# Uncomment to be coherent with Python 3 +# from __future__ import unicode_literals from MEDCoupling import * import unittest @@ -1799,7 +1802,7 @@ class MEDCouplingBasicsTest5(unittest.TestCase): conn = [5,5,2,6,4,5,6,3,0,1,5,4,5,10,8,11,9,5,11,2,1,7,10,9] connI = [0,5,12,17,24] m = MEDCouplingUMesh("box",2) - cooArr = DataArrayDouble(coo,len(coo)/2,2) + cooArr = DataArrayDouble(coo,len(coo)//2,2) m.setCoords(cooArr) m.setConnectivity(DataArrayInt(conn),DataArrayInt(connI)) m.mergeNodes(eps) @@ -3415,7 +3418,7 @@ class MEDCouplingBasicsTest5(unittest.TestCase): connec = [0,1] m_line = MEDCouplingUMesh("seg", 1) m_line.allocateCells(1) - meshCoords = DataArrayDouble.New(coords, len(coords)/2, 2) + meshCoords = DataArrayDouble.New(coords, len(coords)//2, 2) m_line.setCoords(meshCoords) m_line.insertNextCell(NORM_SEG2, connec) a, b, c, d = MEDCouplingUMesh.Intersect2DMeshWith1DLine(m_circ, m_line, eps) @@ -3446,7 +3449,7 @@ class MEDCouplingBasicsTest5(unittest.TestCase): coords2 = [0., 1.3, -1.3, 0., -0.6, 0.6, 0., -1.3, -0.5, -0.5] connec2, cI2 = [NORM_SEG3, 0, 1, 2, NORM_SEG3, 1, 3, 4], [0,4,8] m_line = MEDCouplingUMesh("seg", 1) - m_line.setCoords(DataArrayDouble(coords2, len(coords2)/2, 2)) + m_line.setCoords(DataArrayDouble(coords2, len(coords2)//2, 2)) m_line.setConnectivity(DataArrayInt(connec2), DataArrayInt(cI2)) a, b, c, d = MEDCouplingUMesh.Intersect2DMeshWith1DLine(m, m_line, eps) self.assertTrue(a.getCoords().getHiddenCppPointer()==b.getCoords().getHiddenCppPointer()) @@ -3475,7 +3478,7 @@ class MEDCouplingBasicsTest5(unittest.TestCase): coords2 = [-1., 0.25, 1., 0.25] connec2, cI2 = [NORM_SEG2, 0, 1], [0,3] m_line = MEDCouplingUMesh.New("seg", 1) - m_line.setCoords(DataArrayDouble(coords2, len(coords2)/2, 2)) + m_line.setCoords(DataArrayDouble(coords2, len(coords2)//2, 2)) m_line.setConnectivity(DataArrayInt(connec2), DataArrayInt(cI2)) m_line2 = m_line.deepCopy() m2 = m.deepCopy() @@ -3510,7 +3513,7 @@ class MEDCouplingBasicsTest5(unittest.TestCase): coords2 = [-2., 1., 2., 1.0] connec2, cI2 = [NORM_SEG2, 0, 1], [0,3] m_line = MEDCouplingUMesh("seg", 1) - m_line.setCoords(DataArrayDouble(coords2, len(coords2)/2, 2)) + m_line.setCoords(DataArrayDouble(coords2, len(coords2)//2, 2)) m_line.setConnectivity(DataArrayInt(connec2), DataArrayInt(cI2)) a, b, c, d = MEDCouplingUMesh.Intersect2DMeshWith1DLine(m, m_line, eps) self.assertTrue(a.getCoords().getHiddenCppPointer()==b.getCoords().getHiddenCppPointer()) @@ -3541,7 +3544,7 @@ class MEDCouplingBasicsTest5(unittest.TestCase): coords2 = [-2., 0., 2., 0.] connec2, cI2 = [NORM_SEG2, 0, 1], [0,3] m_line = MEDCouplingUMesh.New("seg", 1) - m_line.setCoords(DataArrayDouble(coords2, len(coords2)/2, 2)) + m_line.setCoords(DataArrayDouble(coords2, len(coords2)//2, 2)) m_line.setConnectivity(DataArrayInt(connec2), DataArrayInt(cI2)) a, b, c, d = MEDCouplingUMesh.Intersect2DMeshWith1DLine(m, m_line, eps) self.assertTrue(a.getCoords().getHiddenCppPointer()==b.getCoords().getHiddenCppPointer()) @@ -3607,7 +3610,7 @@ class MEDCouplingBasicsTest5(unittest.TestCase): coords2 = [1., 2., 1., -2.] connec2, cI2 = [NORM_SEG2, 0, 1], [0,3] m_line = MEDCouplingUMesh("seg", 1) - m_line.setCoords(DataArrayDouble(coords2, len(coords2)/2, 2)) + m_line.setCoords(DataArrayDouble(coords2, len(coords2)//2, 2)) m_line.setConnectivity(DataArrayInt(connec2), DataArrayInt(cI2)) a, b, c, d = MEDCouplingUMesh.Intersect2DMeshWith1DLine(m, m_line, eps) self.assertTrue(a.getCoords().getHiddenCppPointer()==b.getCoords().getHiddenCppPointer()) diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index c95357632..2c2d92fcb 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -223,20 +223,12 @@ using namespace INTERP_KERNEL; %newobject MEDCoupling::MEDCouplingFieldDouble::__add__; %newobject MEDCoupling::MEDCouplingFieldDouble::__sub__; %newobject MEDCoupling::MEDCouplingFieldDouble::__mul__; -#ifdef USE_PYTHON3 -%newobject MEDCoupling::MEDCouplingFieldDouble::__truediv__; -#else %newobject MEDCoupling::MEDCouplingFieldDouble::__div__; -#endif %newobject MEDCoupling::MEDCouplingFieldDouble::__pow__; %newobject MEDCoupling::MEDCouplingFieldDouble::__radd__; %newobject MEDCoupling::MEDCouplingFieldDouble::__rsub__; %newobject MEDCoupling::MEDCouplingFieldDouble::__rmul__; -#ifdef USE_PYTHON3 -%newobject MEDCoupling::MEDCouplingFieldDouble::__rtruediv__; -#else %newobject MEDCoupling::MEDCouplingFieldDouble::__rdiv__; -#endif %newobject MEDCoupling::MEDCouplingFieldDouble::clone; %newobject MEDCoupling::MEDCouplingFieldDouble::cloneWithMesh; %newobject MEDCoupling::MEDCouplingFieldDouble::deepCopy; @@ -4503,11 +4495,7 @@ namespace MEDCoupling return MEDCoupling_MEDCouplingFieldDouble___rmul__Impl(self,obj); } -#ifdef USE_PYTHON3 - MEDCouplingFieldDouble *__truediv__(PyObject *obj) throw(INTERP_KERNEL::Exception) -#else MEDCouplingFieldDouble *__div__(PyObject *obj) throw(INTERP_KERNEL::Exception) -#endif { const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__div__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double."; const char msg2[]="in MEDCouplingFieldDouble.__div__ : self field has no Array of values set !"; @@ -4576,11 +4564,7 @@ namespace MEDCoupling } } -#ifdef USE_PYTHON3 - MEDCouplingFieldDouble *__rtruediv__(PyObject *obj) throw(INTERP_KERNEL::Exception) -#else MEDCouplingFieldDouble *__rdiv__(PyObject *obj) throw(INTERP_KERNEL::Exception) -#endif { return MEDCoupling_MEDCouplingFieldDouble___rdiv__Impl(self,obj); } @@ -4855,11 +4839,7 @@ namespace MEDCoupling } } -#ifdef USE_PYTHON3 - PyObject *___itruediv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) -#else PyObject *___idiv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) -#endif { const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__idiv__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double."; const char msg2[]="in MEDCouplingFieldDouble.__idiv__ : self field has no Array of values set !"; diff --git a/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i b/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i index 5dc0a99e8..9fcc3cd65 100644 --- a/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i +++ b/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i @@ -1940,6 +1940,25 @@ static void convertObjToPossibleCpp6(PyObject *value, int& sw, char& cTyp, std:: return; } } +#ifdef USE_PYTHON3 + if(PyUnicode_Check(value)) + { + Py_ssize_t sz; // =PyString_Size(value); + const char *pt = PyUnicode_AsUTF8AndSize(value, &sz); + if(sz==1) + { + cTyp=pt[0]; + sw=1; + return; + } + else + { + sType=pt; + sw=2; + return; + } + } +#endif if(PyTuple_Check(value)) { int size=PyTuple_Size(value); diff --git a/src/MEDCoupling_Swig/MEDCouplingDataForTest.py b/src/MEDCoupling_Swig/MEDCouplingDataForTest.py index 485a4d98e..0b559220f 100644 --- a/src/MEDCoupling_Swig/MEDCouplingDataForTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingDataForTest.py @@ -17,6 +17,9 @@ # # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # +from __future__ import division +# Uncomment to be coherent with Python 3 +# from __future__ import unicode_literals from MEDCoupling import * from six.moves import range @@ -684,7 +687,7 @@ class MEDCouplingDataForTest: fff.setGaussLocalizationOnCells([6,7],[-1.,-1.,-1.,-1.,1.,-1.,1.,1.,-1.,1.,-1.,-1.,-1.,-1.,1.,-1.,1.,1.,1.,1.,1.,1.,-1.,1.],[-0.577350269189626,-0.577350269189626,-0.577350269189626,-0.577350269189626,-0.577350269189626,0.577350269189626,-0.577350269189626,0.577350269189626,-0.577350269189626,-0.577350269189626,0.577350269189626,0.577350269189626,0.577350269189626,-0.577350269189626,-0.577350269189626,0.577350269189626,-0.577350269189626,0.577350269189626,0.577350269189626,0.577350269189626,-0.577350269189626,0.577350269189626,0.577350269189626,0.577350269189626],[1.,1.,1.,1.,1.,1.,1.,1.]) return MEDCouplingFieldTemplate(fff) - def buildCircle(self, center_X, center_Y, radius): + def buildCircle(self, center_X, center_Y, radius): from cmath import rect from math import pi @@ -694,7 +697,7 @@ class MEDCouplingDataForTest: connec = list(range(4)) baseMesh = MEDCouplingUMesh.New("circle", 2) baseMesh.allocateCells(1) - meshCoords = DataArrayDouble.New(coords, len(coords)/2, 2) + meshCoords = DataArrayDouble.New(coords, len(coords) // 2, 2) meshCoords += (center_X, center_Y) baseMesh.setCoords(meshCoords) @@ -713,7 +716,7 @@ class MEDCouplingDataForTest: connec = [7,5,3,1, 6,4,2,0] baseMesh = MEDCouplingUMesh.New("circle", 2) baseMesh.allocateCells(1) - meshCoords = DataArrayDouble.New(coords, len(coords)/2, 2) + meshCoords = DataArrayDouble.New(coords, len(coords) // 2, 2) meshCoords += (center_X, center_Y) baseMesh.setCoords(meshCoords) diff --git a/src/MEDCoupling_Swig/MEDCouplingExamplesTest.py b/src/MEDCoupling_Swig/MEDCouplingExamplesTest.py index b811511ee..b6ef65261 100644 --- a/src/MEDCoupling_Swig/MEDCouplingExamplesTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingExamplesTest.py @@ -17,6 +17,9 @@ # # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # +from __future__ import division +# Uncomment to be coherent with Python 3 +# from __future__ import unicode_literals from MEDCoupling import * import unittest diff --git a/src/MEDCoupling_Swig/MEDCouplingFinalize.i b/src/MEDCoupling_Swig/MEDCouplingFinalize.i index 1640bc63b..0f9a8c5a2 100644 --- a/src/MEDCoupling_Swig/MEDCouplingFinalize.i +++ b/src/MEDCoupling_Swig/MEDCouplingFinalize.i @@ -25,6 +25,12 @@ DataArrayDouble.__isub__=MEDCouplingDataArrayDoubleIsub DataArrayDouble.__imul__=MEDCouplingDataArrayDoubleImul DataArrayDouble.__idiv__=MEDCouplingDataArrayDoubleIdiv DataArrayDouble.__ipow__=MEDCouplingDataArrayDoubleIpow +DataArrayDouble.__truediv__=DataArrayDouble.__div__ +DataArrayDouble.__itruediv__=MEDCouplingDataArrayDoubleIdiv +DataArrayDouble.__rtruediv__=DataArrayDouble.__rdiv__ +DataArrayDouble.__floordiv__=DataArrayDouble.__div__ +DataArrayDouble.__ifloordiv__=MEDCouplingDataArrayDoubleIdiv +DataArrayDouble.__rfloordiv__=DataArrayDouble.__rdiv__ DataArrayInt.__new__=classmethod(MEDCouplingDataArrayIntnew) DataArrayInt.__iadd__=MEDCouplingDataArrayIntIadd @@ -33,6 +39,12 @@ DataArrayInt.__imul__=MEDCouplingDataArrayIntImul DataArrayInt.__idiv__=MEDCouplingDataArrayIntIdiv DataArrayInt.__imod__=MEDCouplingDataArrayIntImod DataArrayInt.__ipow__=MEDCouplingDataArrayIntIpow +DataArrayInt.__truediv__=DataArrayInt.__div__ +DataArrayInt.__itruediv__=MEDCouplingDataArrayIntIdiv +DataArrayInt.__rtruediv__=DataArrayInt.__rdiv__ +DataArrayInt.__floordiv__=DataArrayInt.__div__ +DataArrayInt.__ifloordiv__=MEDCouplingDataArrayIntIdiv +DataArrayInt.__rfloordiv__=DataArrayInt.__rdiv__ DataArrayByte.__new__=classmethod(MEDCouplingDataArrayBytenew) @@ -41,16 +53,26 @@ MEDCouplingFieldDouble.__isub__=MEDCouplingFieldDoubleIsub MEDCouplingFieldDouble.__imul__=MEDCouplingFieldDoubleImul MEDCouplingFieldDouble.__idiv__=MEDCouplingFieldDoubleIdiv MEDCouplingFieldDouble.__ipow__=MEDCouplingFieldDoubleIpow +MEDCouplingFieldDouble.__truediv__=MEDCouplingFieldDouble.__div__ +MEDCouplingFieldDouble.__rtruediv__=MEDCouplingFieldDouble.__rdiv__ +MEDCouplingFieldDouble.__itruediv__=MEDCouplingFieldDoubleIdiv +MEDCouplingFieldDouble.__floordiv__=MEDCouplingFieldDouble.__div__ +MEDCouplingFieldDouble.__rfloordiv__=MEDCouplingFieldDouble.__rdiv__ +MEDCouplingFieldDouble.__ifloordiv__=MEDCouplingFieldDoubleIdiv DataArrayDoubleTuple.__iadd__=MEDCouplingDataArrayDoubleTupleIadd DataArrayDoubleTuple.__isub__=MEDCouplingDataArrayDoubleTupleIsub DataArrayDoubleTuple.__imul__=MEDCouplingDataArrayDoubleTupleImul DataArrayDoubleTuple.__idiv__=MEDCouplingDataArrayDoubleTupleIdiv +DataArrayDoubleTuple.__itruediv__=MEDCouplingDataArrayDoubleTupleIdiv +DataArrayDoubleTuple.__ifloordiv__=MEDCouplingDataArrayDoubleTupleIdiv DataArrayIntTuple.__iadd__=MEDCouplingDataArrayIntTupleIadd DataArrayIntTuple.__isub__=MEDCouplingDataArrayIntTupleIsub DataArrayIntTuple.__imul__=MEDCouplingDataArrayIntTupleImul DataArrayIntTuple.__idiv__=MEDCouplingDataArrayIntTupleIdiv +DataArrayIntTuple.__itruediv__=MEDCouplingDataArrayIntTupleIdiv +DataArrayIntTuple.__ifloordiv__=MEDCouplingDataArrayIntTupleIdiv DataArrayIntTuple.__imod__=MEDCouplingDataArrayIntTupleImod DenseMatrix.__iadd__=ParaMEDMEMDenseMatrixIadd @@ -65,6 +87,12 @@ MEDCouplingIMesh.__new__=classmethod(MEDCouplingIMeshnew) MEDCouplingMappedExtrudedMesh.__new__=classmethod(MEDCouplingExtrudedMeshnew) MEDCouplingFieldDouble.__new__=classmethod(MEDCouplingFieldDoublenew) +DataArrayAsciiCharIterator.__next__ = DataArrayAsciiCharIterator.next +DataArrayIntIterator.__next__ = DataArrayIntIterator.next +DataArrayDoubleIterator.__next__ = DataArrayDoubleIterator.next +MEDCouplingUMeshCellIterator.__next__ = MEDCouplingUMeshCellIterator.next +MEDCouplingUMeshCellByTypeIterator.__next__ = MEDCouplingUMeshCellByTypeIterator.next + del INTERPKERNELExceptionReduce del MEDCouplingDataArrayDoublenew del MEDCouplingDataArrayDoubleIadd diff --git a/src/MEDCoupling_Swig/MEDCouplingMemArray.i b/src/MEDCoupling_Swig/MEDCouplingMemArray.i index d994b3a87..5b1cbb0d3 100644 --- a/src/MEDCoupling_Swig/MEDCouplingMemArray.i +++ b/src/MEDCoupling_Swig/MEDCouplingMemArray.i @@ -115,13 +115,8 @@ %newobject MEDCoupling::DataArrayInt::__rsub__; %newobject MEDCoupling::DataArrayInt::__mul__; %newobject MEDCoupling::DataArrayInt::__rmul__; -#ifdef USE_PYTHON3 -%newobject MEDCoupling::DataArrayInt::__truediv__; -%newobject MEDCoupling::DataArrayInt::__rtruediv__; -#else %newobject MEDCoupling::DataArrayInt::__div__; %newobject MEDCoupling::DataArrayInt::__rdiv__; -#endif %newobject MEDCoupling::DataArrayInt::__mod__; %newobject MEDCoupling::DataArrayInt::__rmod__; %newobject MEDCoupling::DataArrayInt::__pow__; @@ -204,11 +199,7 @@ %newobject MEDCoupling::DataArrayDouble::__radd__; %newobject MEDCoupling::DataArrayDouble::__rsub__; %newobject MEDCoupling::DataArrayDouble::__rmul__; -#ifdef USE_PYTHON3 -%newobject MEDCoupling::DataArrayDouble::__rtruediv__; -#else %newobject MEDCoupling::DataArrayDouble::__rdiv__; -#endif %newobject MEDCoupling::DataArrayDouble::__pow__; %newobject MEDCoupling::DataArrayDouble::__rpow__; %newobject MEDCoupling::DataArrayDoubleTuple::buildDADouble; @@ -2155,11 +2146,7 @@ namespace MEDCoupling } } -#ifdef USE_PYTHON3 - PyObject *__truediv__(PyObject *obj) throw(INTERP_KERNEL::Exception) -#else PyObject *__div__(PyObject *obj) throw(INTERP_KERNEL::Exception) - #endif { const char msg[]="Unexpected situation in __div__ !"; double val; @@ -2215,11 +2202,7 @@ namespace MEDCoupling } } -#ifdef USE_PYTHON3 - DataArrayDouble *__rtruediv__(PyObject *obj) throw(INTERP_KERNEL::Exception) -#else DataArrayDouble *__rdiv__(PyObject *obj) throw(INTERP_KERNEL::Exception) -#endif { const char msg[]="Unexpected situation in __rdiv__ !"; double val; @@ -2251,11 +2234,7 @@ namespace MEDCoupling } } -#ifdef USE_PYTHON3 - PyObject *___itruediv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) -#else PyObject *___idiv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) -#endif { const char msg[]="Unexpected situation in __idiv__ !"; double val; @@ -2526,11 +2505,7 @@ namespace MEDCoupling return trueSelf; } -#ifdef USE_PYTHON3 - PyObject *___itruediv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) -#else PyObject *___idiv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) -#endif { MCAuto ret=self->buildDADouble(1,self->getNumberOfCompo()); MEDCoupling_DataArrayDouble____idiv___(ret,0,obj); @@ -4394,11 +4369,7 @@ namespace MEDCoupling } } -#ifdef USE_PYTHON3 - DataArrayInt *__truediv__(PyObject *obj) throw(INTERP_KERNEL::Exception) -#else DataArrayInt *__div__(PyObject *obj) throw(INTERP_KERNEL::Exception) -#endif { const char msg[]="Unexpected situation in __div__ !"; int val; @@ -4434,11 +4405,7 @@ namespace MEDCoupling } } -#ifdef USE_PYTHON3 - DataArrayInt *__rtruediv__(PyObject *obj) throw(INTERP_KERNEL::Exception) -#else DataArrayInt *__rdiv__(PyObject *obj) throw(INTERP_KERNEL::Exception) -#endif { const char msg[]="Unexpected situation in __rdiv__ !"; int val; @@ -4470,11 +4437,7 @@ namespace MEDCoupling } } -#ifdef USE_PYTHON3 - PyObject *___itruediv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) -#else PyObject *___idiv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) -#endif { const char msg[]="Unexpected situation in __idiv__ !"; int val; @@ -4887,12 +4850,7 @@ namespace MEDCoupling Py_XINCREF(trueSelf); return trueSelf; } - -#ifdef USE_PYTHON3 - PyObject *___itruediv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) -#else PyObject *___idiv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) -#endif { MCAuto ret=self->buildDAInt(1,self->getNumberOfCompo()); MEDCoupling_DataArrayInt____idiv___(ret,0,obj); @@ -6087,6 +6045,29 @@ namespace MEDCoupling std::copy(PyString_AsString(strOrListOfInt),PyString_AsString(strOrListOfInt)+sz,vals.begin()); return self->findIdSequence(vals); } +#ifdef USE_PYTHON3 + else if(PyUnicode_Check(strOrListOfInt)) + { + Py_ssize_t sz=PyUnicode_GET_LENGTH(strOrListOfInt); + std::vector vals(sz); + std::copy(PyUnicode_AsUTF8(strOrListOfInt),PyUnicode_AsUTF8(strOrListOfInt)+sz,vals.begin()); + return self->findIdSequence(vals); + } + else if(PyByteArray_Check(strOrListOfInt)) + { + Py_ssize_t sz=PyByteArray_Size(strOrListOfInt); + std::vector vals(sz); + std::copy(PyByteArray_AsString(strOrListOfInt),PyByteArray_AsString(strOrListOfInt)+sz,vals.begin()); + return self->findIdSequence(vals); + } + else if(PyBytes_Check(strOrListOfInt)) + { + Py_ssize_t sz=PyBytes_Size(strOrListOfInt); + std::vector vals(sz); + std::copy(PyBytes_AsString(strOrListOfInt),PyBytes_AsString(strOrListOfInt)+sz,vals.begin()); + return self->findIdSequence(vals); + } +#endif else throw INTERP_KERNEL::Exception("DataArrayAsciiChar::search : only strings in input supported !"); } diff --git a/src/MEDCoupling_Swig/MEDCouplingNumPyTest.py b/src/MEDCoupling_Swig/MEDCouplingNumPyTest.py index 0f6735d65..3132371cc 100644 --- a/src/MEDCoupling_Swig/MEDCouplingNumPyTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingNumPyTest.py @@ -17,6 +17,9 @@ # # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # +from __future__ import division +# Uncomment to be coherent with Python 3 +# from __future__ import unicode_literals from MEDCoupling import * diff --git a/src/MEDCoupling_Swig/MEDCouplingPickleTest.py b/src/MEDCoupling_Swig/MEDCouplingPickleTest.py index 5565c1b5e..4d9d6031c 100644 --- a/src/MEDCoupling_Swig/MEDCouplingPickleTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingPickleTest.py @@ -17,6 +17,9 @@ # # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # +from __future__ import division +# Uncomment to be coherent with Python 3 +# from __future__ import unicode_literals from MEDCoupling import * from MEDCouplingDataForTest import MEDCouplingDataForTest diff --git a/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py b/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py index cde9b2ed6..c172facd2 100644 --- a/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py @@ -17,6 +17,9 @@ # # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # +from __future__ import division +# Uncomment to be coherent with Python 3 +# from __future__ import unicode_literals from MEDCouplingDataForTest import MEDCouplingDataForTest from MEDCouplingRemapper import * @@ -1119,8 +1122,8 @@ class MEDCouplingBasicsTest(unittest.TestCase): cI2 = [0, 44] mTgt = MEDCouplingUMesh("target", 3) mSrc = MEDCouplingUMesh("src", 3) - mTgt.setCoords(DataArrayDouble(coo1, len(coo1)/3, 3)) - mSrc.setCoords(DataArrayDouble(coo2, len(coo2)/3, 3)) + mTgt.setCoords(DataArrayDouble(coo1, len(coo1) // 3, 3)) + mSrc.setCoords(DataArrayDouble(coo2, len(coo2) // 3, 3)) mTgt.setConnectivity(DataArrayInt(conn1), DataArrayInt(cI1)) mSrc.setConnectivity(DataArrayInt(conn2), DataArrayInt(cI2)) diff --git a/src/MEDLoader/Swig/MEDLoader.i b/src/MEDLoader/Swig/MEDLoader.i index 7add2d533..1d7e9b764 100644 --- a/src/MEDLoader/Swig/MEDLoader.i +++ b/src/MEDLoader/Swig/MEDLoader.i @@ -175,6 +175,12 @@ def MEDCouplingMEDFileParametersnew(cls,*args): %include "MEDCouplingFinalize.i" +%pythoncode %{ +MEDFileMeshesIterator.__next__ = MEDFileMeshesIterator.next +MEDFileAnyTypeFieldMultiTSIterator.__next__ = MEDFileAnyTypeFieldMultiTSIterator.next +MEDFileFieldsIterator.__next__ = MEDFileFieldsIterator.next +%} + %pythoncode %{ MEDFileUMesh.__new__=classmethod(MEDCouplingMEDFileUMeshnew) del MEDCouplingMEDFileUMeshnew