[Kimchi-devel] [PATCH] issue #330: Properly log the error message when login fails

Shu Ming shuming at linux.vnet.ibm.com
Thu Mar 6 16:33:57 UTC 2014


? 2014/3/6 22:53, Aline Manera ??:
> On 03/06/2014 06:41 AM, Sheldon wrote:
>> On 03/05/2014 03:35 AM, Aline Manera wrote:
>>> From: Aline Manera <alinefm at br.ibm.com>
>>>
>>> The error message and all its parameters must be string.
>>> So convert error code to string in order to accomplish it.
>>>
>>> Signed-off-by: Aline Manera <alinefm at 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
>> How about the follow change?
>> It can avoid call str() before we raise KimchiException Everywhere.
>> Also I think it is not good to other developers to call str 
>> explicitly Everywhere.
>>
>> diff --git a/src/kimchi/exception.py b/src/kimchi/exception.py
>> index 71a4d11..73e88ce 100644
>> --- a/src/kimchi/exception.py
>> +++ b/src/kimchi/exception.py
>> @@ -50,7 +50,7 @@ class KimchiException(Exception):
>> translation = gettext
>>
>> for key, value in args.iteritems():
>> - if not isinstance(value, unicode):
>> + if isinstance(value, str):
>> args[key] = unicode(value, 'utf-8')
>>
>> return unicode(translation.gettext(text), 'utf-8') % args
>>
>>
>>
>
> What about always convert to string before to unicode?
>
> if not isinstance(value, unicode):
>    args[key] = unicode(*str*(value), 'utf-8')

I think it is more pythonic that:

try:
       args[key] = unicode(value, 'utf-8')
except TypeError:
        args[key] = unicode(*str*(value), 'utf-8')
>
> That way we guarantee everything will be unicode in the end.
>
>
>
> _______________________________________________
> Kimchi-devel mailing list
> Kimchi-devel at ovirt.org
> http://lists.ovirt.org/mailman/listinfo/kimchi-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ovirt.org/pipermail/kimchi-devel/attachments/20140307/2f6418cf/attachment.html>


More information about the Kimchi-devel mailing list