Support for str in StrEnum.

The StrEnum class has been modified to accept str value and convert
it into unicode. This is to fix encoding issue on F14.
This commit is contained in:
Endi S. Dewata
2011-01-13 12:42:16 -05:00
parent 3486047583
commit 00b3984e5a

View File

@@ -1384,6 +1384,24 @@ class StrEnum(Enum):
type = unicode
def _convert_scalar(self, value, index=None):
"""
Convert a single scalar value.
"""
if type(value) is self.type:
return value
if type(value) is str:
try:
return value.decode('utf-8')
except UnicodeDecodeError:
raise ConversionError(
name=self.name, index=index,
error=ugettext(self.scalar_error)
)
raise ConversionError(name=self.name, index=index,
error=ugettext(self.type_error),
)
class List(Param):
"""