[PATCH 2/4] Move upcase_first_letter function to iutil

Vratislav Podzimek vpodzime at redhat.com
Fri Sep 13 10:59:39 UTC 2013


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):
     """
-- 
1.7.11.7



More information about the anaconda-patches mailing list