[Cython] Fixed problems with unicode strings in Python 2
This commit is contained in:
parent
b277818347
commit
9601895b98
4 changed files with 8 additions and 8 deletions
|
|
@ -70,7 +70,7 @@ cdef class _SolutionBase:
|
|||
def __get__(self):
|
||||
return list(self._selectedSpecies)
|
||||
def __set__(self, species):
|
||||
if isinstance(species, (str, int)):
|
||||
if isinstance(species, (str, unicode, int)):
|
||||
species = (species,)
|
||||
self._selectedSpecies.resize(len(species))
|
||||
for i,spec in enumerate(species):
|
||||
|
|
|
|||
|
|
@ -178,7 +178,7 @@ cdef class Boundary1D(Domain1D):
|
|||
""" Species mole fractions at this boundary. """
|
||||
def __set__(self, X):
|
||||
cdef np.ndarray[np.double_t, ndim=1] data
|
||||
if isinstance(X, str):
|
||||
if isinstance(X, (str, unicode)):
|
||||
self.boundary.setMoleFractions(stringify(X))
|
||||
else:
|
||||
data = np.ascontiguousarray(X, dtype=np.double)
|
||||
|
|
@ -457,7 +457,7 @@ cdef class Sim1D:
|
|||
def _get_indices(self, dom, comp):
|
||||
idom = self.domainIndex(dom)
|
||||
dom = self.domains[idom]
|
||||
if isinstance(comp, str):
|
||||
if isinstance(comp, (str, unicode)):
|
||||
kcomp = dom.componentIndex(comp)
|
||||
else:
|
||||
kcomp = comp
|
||||
|
|
|
|||
|
|
@ -774,7 +774,7 @@ cdef class ReactorNet:
|
|||
def sensitivity(self, species, int p, int r=0):
|
||||
if isinstance(species, int):
|
||||
return self.net.sensitivity(species,p)
|
||||
elif isinstance(species, str):
|
||||
elif isinstance(species, (str, unicode)):
|
||||
return self.net.sensitivity(stringify(species), p, r)
|
||||
|
||||
def sensitivities(self):
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ cdef class ThermoPhase(_SolutionBase):
|
|||
an integer. In the latter case, the index is checked for validity and
|
||||
returned. If no such element is present, an exception is thrown.
|
||||
"""
|
||||
if isinstance(element, str):
|
||||
if isinstance(element, (str, unicode)):
|
||||
index = self.thermo.elementIndex(stringify(element))
|
||||
elif isinstance(element, (int, float)):
|
||||
index = <int>element
|
||||
|
|
@ -191,7 +191,7 @@ cdef class ThermoPhase(_SolutionBase):
|
|||
an integer. In the latter case, the index is checked for validity and
|
||||
returned. If no such species is present, an exception is thrown.
|
||||
"""
|
||||
if isinstance(species, str):
|
||||
if isinstance(species, (str, unicode)):
|
||||
index = self.thermo.speciesIndex(stringify(species))
|
||||
elif isinstance(species, (int, float)):
|
||||
index = <int>species
|
||||
|
|
@ -253,7 +253,7 @@ cdef class ThermoPhase(_SolutionBase):
|
|||
def __get__(self):
|
||||
return self._getArray1(thermo_getMassFractions)
|
||||
def __set__(self, Y):
|
||||
if isinstance(Y, str):
|
||||
if isinstance(Y, (str, unicode)):
|
||||
self.thermo.setMassFractionsByName(stringify(Y))
|
||||
else:
|
||||
self._setArray1(thermo_setMassFractions, Y)
|
||||
|
|
@ -272,7 +272,7 @@ cdef class ThermoPhase(_SolutionBase):
|
|||
def __get__(self):
|
||||
return self._getArray1(thermo_getMoleFractions)
|
||||
def __set__(self, X):
|
||||
if isinstance(X, str):
|
||||
if isinstance(X, (str, unicode)):
|
||||
self.thermo.setMoleFractionsByName(stringify(X))
|
||||
else:
|
||||
self._setArray1(thermo_setMoleFractions, X)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue