<div class="gmail_quote">On 30 September 2010 06:32, Dipankar Patro <span dir="ltr">&lt;<a href="mailto:dipankar@seeta.in">dipankar@seeta.in</a>&gt;</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 &#39;:&#39; character in the username with &#39;_&#39;, 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 = {&#39;red&#39;: {&#39;dark&#39;:&#39;#b20008&#39;, &#39;medium&#39;:&#39;#e6000a&#39;, &#39;light&#39;:&#39;#ffadce&#39;},<br>

            &#39;orange&#39;: {&#39;dark&#39;:&#39;#9a5200&#39;, &#39;medium&#39;:&#39;#c97e00&#39;, &#39;light&#39;:&#39;#ffc169&#39;},<br>@@ -42,6 +43,7 @@ def set_nick(nick):<br>     if not nick:<br>         raise ValueError(_(&quot;You must enter a name.&quot;))<br>

     if not isinstance(nick, unicode):<br>+        nick = re.sub(r&#39;:&#39;, &#39;_&#39;, nick)<br>         nick = unicode(nick, &#39;utf-8&#39;)<br>     client = gconf.client_get_default()<br>     client.set_string(&quot;/desktop/sugar/user/nick&quot;, 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 &quot;:&quot;. 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="&#39;courier new&#39;, monospace">if nick:</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  nick = unicode(nick.replace(&#39;:&#39;, &#39;_&#39;), encoding=&#39;utf-8&#39;)</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  client = gconf.client_get_default()</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  client.set_string(&quot;/desktop/sugar/user/nick&quot;, nick)</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">else:</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  raise ValueError(_(&quot;You must enter a name.&quot;))</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&#39;t know where to implement the name change.</div><div><br></div><div>Tim</div><div><br></div><div> </div></div>