[Sugar-devel] Replacing Illegal character ':' in username (SL #2152)

Tim McNamara paperless at timmcnamara.co.nz
Wed Sep 29 16:29:59 EDT 2010


On 30 September 2010 06:32, Dipankar Patro <dipankar at seeta.in> wrote:

> Hi,
>
> With reference to bug : http://bugs.sugarlabs.org/ticket/2152
>
> I am trying to replace the ':' character in the username with '_', while
> the user is entering the Username in About Me.
>
> The following has been done by me so far:
> -------------------------------------------------------------
> diff --git a/extensions/cpsection/aboutme/model.py
> b/extensions/cpsection/aboutme/model.py
> index 8500799..47e7158 100644
> --- a/extensions/cpsection/aboutme/model.py
> +++ b/extensions/cpsection/aboutme/model.py
> @@ -17,6 +17,7 @@
>
>  from gettext import gettext as _
>  import gconf
> +import re
>
>  _COLORS = {'red': {'dark':'#b20008', 'medium':'#e6000a',
> 'light':'#ffadce'},
>             'orange': {'dark':'#9a5200', 'medium':'#c97e00',
> 'light':'#ffc169'},
> @@ -42,6 +43,7 @@ def set_nick(nick):
>      if not nick:
>          raise ValueError(_("You must enter a name."))
>      if not isinstance(nick, unicode):
> +        nick = re.sub(r':', '_', nick)
>          nick = unicode(nick, 'utf-8')
>      client = gconf.client_get_default()
>      client.set_string("/desktop/sugar/user/nick", nick)
>

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.

if nick:
  nick = unicode(nick.replace(':', '_'), encoding='utf-8')
  client = gconf.client_get_default()
  client.set_string("/desktop/sugar/user/nick", nick)
else:
  raise ValueError(_("You must enter a name."))

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.

Like Sascha, I don't know where to implement the name change.

Tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.sugarlabs.org/archive/sugar-devel/attachments/20100930/9c646266/attachment-0001.htm 


More information about the Sugar-devel mailing list