diff options
author | Endi S. Dewata <edewata@redhat.com> | 2011-01-13 12:42:16 -0500 |
---|---|---|
committer | Endi S. Dewata <edewata@redhat.com> | 2011-01-13 21:48:07 -0500 |
commit | 00b3984e5a754b40bd10515ce9629583c78b6c8e (patch) | |
tree | bc8e8f11f313ba68f896dd6e8a80eb447610eb6d /ipalib/parameters.py | |
parent | 34860475835c6ccb5c3ebb08bce0b3b65e656ee1 (diff) | |
download | freeipa-00b3984e5a754b40bd10515ce9629583c78b6c8e.tar.gz freeipa-00b3984e5a754b40bd10515ce9629583c78b6c8e.tar.xz freeipa-00b3984e5a754b40bd10515ce9629583c78b6c8e.zip |
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.
Diffstat (limited to 'ipalib/parameters.py')
-rw-r--r-- | ipalib/parameters.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/ipalib/parameters.py b/ipalib/parameters.py index 128c8a463..78eacde25 100644 --- a/ipalib/parameters.py +++ b/ipalib/parameters.py @@ -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): """ |