[PATCH 2/4] Move upcase_first_letter function to iutil

Vratislav Podzimek vpodzime at redhat.com
Fri Sep 13 13:11:44 UTC 2013


On Fri, 2013-09-13 at 09:05 -0400, David Shea wrote:
> On 09/13/2013 06:59 AM, Vratislav Podzimek wrote:
> > This function may come handy in various module, not only in the localization
> > module.
> >
> > Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
> > ---
> >   pyanaconda/iutil.py        | 21 +++++++++++++++++++++
> >   pyanaconda/localization.py | 27 ++++-----------------------
> >   2 files changed, 25 insertions(+), 23 deletions(-)
> >
> > diff --git a/pyanaconda/iutil.py b/pyanaconda/iutil.py
> > index 4e362ff..020f15d 100644
> > --- a/pyanaconda/iutil.py
> > +++ b/pyanaconda/iutil.py
> > @@ -742,3 +742,24 @@ def lowerASCII(s):
> >       locale-independent.
> >       """
> >       return string.translate(_toASCII(s), _ASCIIlower_table)
> > +
> > +def upcase_first_letter(string):
> > +    """
> > +    Helper function that upcases the first letter of the string. Python's
> > +    standard string.capitalize() not only upcases the first letter but also
> > +    lowercases all the others. string.title() capitalizes all words in the
> > +    string.
> > +
> > +    :type string: either a str or unicode object
> > +    :return: the given string with the first letter upcased
> > +    :rtype: str or unicode (depends on the input)
> > +
> > +    """
> > +
> > +    if not string:
> > +        # cannot change anything
> > +        return string
> > +    elif len(string) == 1:
> > +        return string.upper()
> > +    else:
> > +        return string[0].upper() + string[1:]
> > diff --git a/pyanaconda/localization.py b/pyanaconda/localization.py
> > index f9469d8..7e473dd 100644
> > --- a/pyanaconda/localization.py
> > +++ b/pyanaconda/localization.py
> > @@ -26,6 +26,8 @@ import re
> >   import langtable
> >   import glob
> >   
> > +from pyanaconda.iutil import upcase_first_letter
> > +
> >   import logging
> >   log = logging.getLogger("anaconda")
> >   
> > @@ -47,27 +49,6 @@ class InvalidLocaleSpec(LocalizationConfigError):
> >   
> >       pass
> >   
> > -def _upcase_first_letter(string):
> > -    """
> > -    Helper function that upcases the first letter of the string. Python's
> > -    standard string.capitalize() not only upcases the first letter but also
> > -    lowercases all the others. string.title() capitalizes all words in the
> > -    string.
> > -
> > -    :type string: either a str or unicode object
> > -    :return: the given string with the first letter upcased
> > -    :rtype: str or unicode (depends on the input)
> > -
> > -    """
> > -
> > -    if not string:
> > -        # cannot change anything
> > -        return string
> > -    elif len(string) == 1:
> > -        return string.upper()
> > -    else:
> > -        return string[0].upper() + string[1:]
> > -
> >   def parse_langcode(langcode):
> >       """
> >       For a given langcode (e.g. 'SR_RS.UTF-8 at latin') returns a dictionary
> > @@ -237,7 +218,7 @@ def get_english_name(locale):
> >                                      scriptId=parts.get("script", ""),
> >                                      languageIdQuery="en")
> >   
> > -    return _upcase_first_letter(name)
> > +    return upcase_first_letter(name)
> >   
> >   def get_native_name(locale):
> >       """
> > @@ -261,7 +242,7 @@ def get_native_name(locale):
> >                                      languageIdQuery=parts["language"],
> >                                      scriptIdQuery=parts.get("script", ""))
> >   
> > -    return _upcase_first_letter(name)
> > +    return upcase_first_letter(name)
> >   
> >   def get_available_translations(localedir=None):
> >       """
> "string" isn't the best parameter name, since it conflicts with the 
> string module, which is imported in iutil. Also need to change the use 
> of _upcase_first_letter in tests/pyanaconda/localization_test.py
Good points, thanks. Maybe I should upgrade my system to be able to run
'make check' and use it. :) Fixing locally.

-- 
Vratislav Podzimek

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



More information about the anaconda-patches mailing list