
On 03/06/2014 01:31 AM, Aline Manera wrote:
On 03/04/2014 10:49 PM, Shu Ming wrote:
2014/3/5 3:35, Aline Manera:
From: Aline Manera <alinefm@br.ibm.com>
The error message and all its parameters must be string. So convert error code to string in order to accomplish it.
I think the code is str already. Why should it be converted explicitly? Is there any error encountered?
Yes. Take a look in github: https://github.com/kimchi-project/kimchi/issues/330
The error happens because KimchiException() converts all message and arguments to unicode So we need to ensure the arguments are strings or do it convert it on KimchiException() which I think can cause problems when a different type which does not have str representattion
I have check the code is really a int. Now I check the follow exception.py: for key, value in args.iteritems(): if not isinstance(value, unicode): args[key] = unicode(value, 'utf-8') return unicode(translation.gettext(text), 'utf-8') % args it is as you said, unicode require the arguments are strings. but I have a try the follow code can work, with unicode(value, 'utf-8'). In [22]: unicode(translation.gettext("你好 %(code)s"), 'utf-8') % {"code": 1} Out[22]: u'\u4f60\u597d 1' or In [31]: translation.gettext(u"你好 %(code)s") % {"code": 1} Out[31]: u'\u4f60\u597d 1' I wonder can we improve the KimchiException()? or we need to convert every where when we call KimchiException str(int) is looks like strange for a python developer.
Signed-off-by: Aline Manera <alinefm@br.ibm.com> --- src/kimchi/auth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/kimchi/auth.py b/src/kimchi/auth.py index af3b610..b16f2db 100644 --- a/src/kimchi/auth.py +++ b/src/kimchi/auth.py @@ -107,7 +107,7 @@ def authenticate(username, password, service="passwd"): try: auth.authenticate() except PAM.error, (resp, code): - msg_args = {'userid': username, 'code': code} + msg_args = {'userid': username, 'code': str(code)} raise OperationFailed("KCHAUTH0001E", msg_args)
return True
_______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel
-- Thanks and best regards! Sheldon Feng(冯少合)<shaohef@linux.vnet.ibm.com> IBM Linux Technology Center