<div class="gmail_quote">On 30 September 2010 06:32, Dipankar Patro <span dir="ltr"><<a href="mailto:dipankar@seeta.in">dipankar@seeta.in</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi,<br><br>With reference to bug : <a href="http://bugs.sugarlabs.org/ticket/2152" target="_blank">http://bugs.sugarlabs.org/ticket/2152</a><br><br>I am trying to replace the ':' character in the username with '_', while the user is entering the Username in About Me.<br>
<br>The following has been done by me so far:<br>-------------------------------------------------------------<br>diff --git a/extensions/cpsection/aboutme/model.py b/extensions/cpsection/aboutme/model.py<br>index 8500799..47e7158 100644<br>
--- a/extensions/cpsection/aboutme/model.py<br>+++ b/extensions/cpsection/aboutme/model.py<br>@@ -17,6 +17,7 @@<br> <br> from gettext import gettext as _<br> import gconf<br>+import re<br> <br> _COLORS = {'red': {'dark':'#b20008', 'medium':'#e6000a', 'light':'#ffadce'},<br>
'orange': {'dark':'#9a5200', 'medium':'#c97e00', 'light':'#ffc169'},<br>@@ -42,6 +43,7 @@ def set_nick(nick):<br> if not nick:<br> raise ValueError(_("You must enter a name."))<br>
if not isinstance(nick, unicode):<br>+ nick = re.sub(r':', '_', nick)<br> nick = unicode(nick, 'utf-8')<br> client = gconf.client_get_default()<br> client.set_string("/desktop/sugar/user/nick", nick)<br>
</blockquote><div><br></div><div>I would use simple string operations rather than regular expressions. Also, take it out of the type checking block. Unicode expressions may still contain ":". Looking at this, I would also change the first conditional to something that emulates a try/except block.</div>
<div><br></div><div><font class="Apple-style-span" face="'courier new', monospace">if nick:</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> nick = unicode(nick.replace(':', '_'), encoding='utf-8')</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> client = gconf.client_get_default()</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> client.set_string("/desktop/sugar/user/nick", nick)</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">else:</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> raise ValueError(_("You must enter a name."))</font></div>
<meta http-equiv="content-type" content="text/html; charset=utf-8"><div><br></div><div>I see no added advantage in type testing for unicode. Unicode instances will incur no further penalty than what would have occurred anyway with type testing.</div>
<div><br></div><div>Like Sascha, I don't know where to implement the name change.</div><div><br></div><div>Tim</div><div><br></div><div> </div></div>