[master] [PATCH] Refactor and cleanup our localization module

Vratislav Podzimek vpodzime at redhat.com
Wed Jan 9 13:33:17 UTC 2013


On Tue, 2013-01-08 at 09:22 -0800, Brian C. Lane wrote:
> On Tue, Jan 08, 2013 at 01:03:27PM +0100, Vratislav Podzimek wrote:
> > expand_langs may use parse_langcode which should be a global function
> > not a static method of the Language class. Also some pieces deserve
> > better documentation and some other pieces were potentially dangerous.
> > 
> > Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
> > ---
> >  pyanaconda/localization.py | 91 +++++++++++++++++++++++++++-------------------
> >  1 file changed, 53 insertions(+), 38 deletions(-)
> 
> 
> > +
> > +    match = LANGCODE_RE.match(langcode)
> > +    return match.groupdict()
> 
> The match could fail. I'd catch that and return an empty {}
Good point, thanks! Fixing locally.

> 
> 
> > +    lang_dict = parse_langcode(astring)
> > +    base, loc, enc, script = [lang_dict[key] for key in ("language",
> > +                                      "territory", "codeset", "modifier")]
> 
> The key may not be in the lang_dict, add 'if key in lang_dict' to the end
> of the list comprehension.
The key has to be in dict if the dict is not {} (as suggested in your
previous comment). Or am I wrong? I think check for lang_dict != {}
should be enough. Using 'if key in lang_dict' doesn't make much sense to
me as it would return the items in a wrong order in case something is
missing.

-- 
Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic



More information about the anaconda-patches mailing list