[Kimchi-devel] [PATCH] issue #330: Properly log the error message when login fails
Sheldon
shaohef at linux.vnet.ibm.com
Wed Mar 5 04:39:42 UTC 2014
On 03/05/2014 11:59 AM, Sheldon wrote:
> On 03/05/2014 09:49 AM, Shu Ming wrote:
>> 2014/3/5 3:35, Aline Manera:
>>> 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.
>>
>> I think the code is str already. Why should it be converted
>> explicitly? Is there any error encountered?
> agree.
> Also python can converted the parameters well when format the string.
> This is different with C code.
>
> such as:
> In [218]: "This is a code test: %(code)s " % {"code": 2}
> Out[218]: 'This is a code test: 2 '
>
>
> so is this is need?
> IMO, if we still need it to be converted explicitly. We can use %d,
> instead of %s as follow.
>
> In [221]: "This is a code test: %(code)d " % {"code": 2}
> Out[221]: 'This is a code test: 2 '
for int, it is no need to be converted explicitly
In [250]: int.__str__
Type: wrapper_descriptor
String Form:<slot wrapper '__str__' of 'int' objects>
Namespace: Python builtin
Docstring: x.__str__() <==> str(x)
How I will give a example about how %s works.
In [234]: class a(object):
.....: def __str__(self):
.....: return "b"
.....:
In [235]: class ca(object):
def __str__(self):
return "b"
.....:
In [236]: class ca(object):
.....: def __str__(self):
.....: return "b"
.....:
In [237]: ia = ca()
In [238]: print ia
b
In [239]: "%s" % ia
Out[239]: 'b'
In [240]: class ca(object): pass
In [241]: ia = ca()
In [242]: print ia
<__main__.ca object at 0x2b705d0>
In [243]: "%s" % ia
Out[243]: '<__main__.ca object at 0x2b705d0>'
>>
>>>
>>> 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
>>
>> _______________________________________________
>> Kimchi-devel mailing list
>> Kimchi-devel at ovirt.org
>> http://lists.ovirt.org/mailman/listinfo/kimchi-devel
>>
>>
>>
>
>
--
Thanks and best regards!
Sheldon Feng(冯少合)<shaohef at linux.vnet.ibm.com>
IBM Linux Technology Center
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ovirt.org/pipermail/kimchi-devel/attachments/20140305/43c9ef4a/attachment.html>
More information about the Kimchi-devel
mailing list