<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 03/06/2014 10:53 PM, Aline Manera
wrote:<br>
</div>
<blockquote cite="mid:53188BF6.5090308@linux.vnet.ibm.com"
type="cite">
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<div class="moz-cite-prefix">On 03/06/2014 06:41 AM, Sheldon
wrote:<br>
</div>
<blockquote cite="mid:531842B9.5020708@linux.vnet.ibm.com"
type="cite">On 03/05/2014 03:35 AM, Aline Manera wrote: <br>
<blockquote type="cite">From: Aline Manera <a
moz-do-not-send="true" class="moz-txt-link-rfc2396E"
href="mailto:alinefm@br.ibm.com"><alinefm@br.ibm.com></a>
<br>
<br>
The error message and all its parameters must be string. <br>
So convert error code to string in order to accomplish it. <br>
<br>
Signed-off-by: Aline Manera <a moz-do-not-send="true"
class="moz-txt-link-rfc2396E"
href="mailto:alinefm@br.ibm.com"><alinefm@br.ibm.com></a>
<br>
--- <br>
src/kimchi/auth.py | 2 +- <br>
1 file changed, 1 insertion(+), 1 deletion(-) <br>
<br>
diff --git a/src/kimchi/auth.py b/src/kimchi/auth.py <br>
index af3b610..b16f2db 100644 <br>
--- a/src/kimchi/auth.py <br>
+++ b/src/kimchi/auth.py <br>
@@ -107,7 +107,7 @@ def authenticate(username, password,
service="passwd"): <br>
try: <br>
auth.authenticate() <br>
except PAM.error, (resp, code): <br>
- msg_args = {'userid': username, 'code': code} <br>
+ msg_args = {'userid': username, 'code': str(code)} <br>
raise OperationFailed("KCHAUTH0001E", msg_args) <br>
<br>
return True <br>
</blockquote>
How about the follow change? <br>
It can avoid call str() before we raise KimchiException
Everywhere. <br>
Also I think it is not good to other developers to call str
explicitly Everywhere. <br>
<br>
diff --git a/src/kimchi/exception.py b/src/kimchi/exception.py <br>
index 71a4d11..73e88ce 100644 <br>
--- a/src/kimchi/exception.py <br>
+++ b/src/kimchi/exception.py <br>
@@ -50,7 +50,7 @@ class KimchiException(Exception): <br>
translation = gettext <br>
<br>
for key, value in args.iteritems(): <br>
- if not isinstance(value, unicode): <br>
+ if isinstance(value, str): <br>
args[key] = unicode(value, 'utf-8') <br>
<br>
return unicode(translation.gettext(text), 'utf-8') % args <br>
<br>
<br>
<br>
</blockquote>
<br>
What about always convert to string before to unicode?<br>
<br>
if not isinstance(value, unicode):<br>
args[key] = unicode(<b>str</b>(value), 'utf-8')<br>
</blockquote>
This is also OK. seems it is more understand to most python
developer. <br>
actually it is same effect with the above code I suggested.<br>
<br>
AFAK, seems two types has no string representation, one is unicode
and another is object derived from nothing.<br>
<br>
The later object derived from nothing, we can consider it is a bug.<br>
Kimchi do not allowed this. class c1(): pass<br>
But I'm not worry about it.<br>
IMO, no one will not pass this instance of object to
KimchiException as args.<br>
<br>
we just allow objects derived from python object class in kimchi,
class c2(object): pass<br>
<br>
<br>
<br>
<blockquote cite="mid:53188BF6.5090308@linux.vnet.ibm.com"
type="cite"> <br>
That way we guarantee everything will be unicode in the end.<br>
<br>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">--
Thanks and best regards!
Sheldon Feng(冯少合)<a class="moz-txt-link-rfc2396E" href="mailto:shaohef@linux.vnet.ibm.com"><shaohef@linux.vnet.ibm.com></a>
IBM Linux Technology Center</pre>
</body>
</html>