2 # Copyright (C) 2007-2013 EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 Ce module contient des fonctions utilitaires pour tester les types
31 # use isinstance() instead of type() because objects returned from numpy arrays
32 # inherit from python scalars but are numpy.float64 or numpy.int32...
36 return isinstance(obj, int) or type(obj) is long
40 return isinstance(obj, float)
44 return isinstance(obj, complex)
46 from decimal import Decimal
49 def is_float_or_int(obj):
50 return is_float(obj) or is_int(obj) or isinstance(obj, Decimal)
54 return is_float_or_int(obj) or is_complex(obj)
58 return isinstance(obj, (str, unicode))
62 return type(obj) is list
66 return type(obj) is tuple
71 return type(obj) is _np_arr
75 """a sequence (allow iteration, not a string) ?"""
76 return is_list(obj) or is_tuple(obj) or is_array(obj)
80 from N_ASSD import ASSD
81 return isinstance(obj, ASSD)
85 """Retourne `obj` si c'est une liste ou un tuple,
86 sinon retourne [obj,] (en tant que list).
88 if not is_sequence(obj):
94 """Return `obj` as a tuple."""
95 return tuple(force_list(obj))
97 # backward compatibility
98 from warnings import warn
102 """same as is_sequence"""
103 warn("'is_enum' is deprecated, use 'is_sequence'",
104 DeprecationWarning, stacklevel=2)
105 return is_sequence(obj)