[f22-branch 3/3] Make anaconda more unicode-y (#1205183)

dashea installerbot-noreply at redhat.com
Fri Apr 10 15:18:17 UTC 2015


From: David Shea <dshea at redhat.com>

Use unicode types for translated strings so that anaconda doesn't crash
when trying combine unicode strings with non-ascii strs.
---
 pyanaconda/i18n.py                                  |  4 ++--
 pyanaconda/localization.py                          |  2 +-
 pyanaconda/ui/gui/spokes/lib/lang_locale_handler.py | 10 +++++++---
 pyanaconda/ui/gui/utils.py                          |  4 +++-
 pyanaconda/users.py                                 |  4 +++-
 5 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/pyanaconda/i18n.py b/pyanaconda/i18n.py
index 3e6c248..2e80957 100644
--- a/pyanaconda/i18n.py
+++ b/pyanaconda/i18n.py
@@ -23,9 +23,9 @@
 
 import gettext
 
-_ = lambda x: gettext.ldgettext("anaconda", x) if x else ""
+_ = lambda x: gettext.translation("anaconda", fallback=True).ugettext(x) if x != "" else u""
 N_ = lambda x: x
-P_ = lambda x, y, z: gettext.ldngettext("anaconda", x, y, z)
+P_ = lambda x, y, z: gettext.translation("anaconda", fallback=True).ungettext(x, y, z)
 
 # This is equivalent to "pgettext" in GNU gettext. The pgettext functions
 # are not exported by Python, but all they really do is a stick a EOT
diff --git a/pyanaconda/localization.py b/pyanaconda/localization.py
index 6cac742..a305941 100644
--- a/pyanaconda/localization.py
+++ b/pyanaconda/localization.py
@@ -398,7 +398,7 @@ def get_xlated_timezone(tz_spec_part):
                                      territoryIdQuery=parts.get("territory", ""),
                                      scriptIdQuery=parts.get("script", ""))
 
-    return xlated.encode("utf-8")
+    return xlated
 
 def write_language_configuration(lang, root):
     """
diff --git a/pyanaconda/ui/gui/spokes/lib/lang_locale_handler.py b/pyanaconda/ui/gui/spokes/lib/lang_locale_handler.py
index 1874647..9eaaeb7 100644
--- a/pyanaconda/ui/gui/spokes/lib/lang_locale_handler.py
+++ b/pyanaconda/ui/gui/spokes/lib/lang_locale_handler.py
@@ -85,9 +85,13 @@ def _matches_entry(self, model, itr, *args):
 
         # Otherwise, filter the list showing only what is matched by the
         # text entry.  Either the English or native names can match.
-        lowered = entry.lower()
-        translit = strip_accents(unicode(native, "utf-8")).lower()
-        if lowered in native.lower() or lowered in english.lower() or lowered in translit:
+        # Convert strings to unicode so lower() works.
+        lowered = entry.decode('utf-8').lower()
+        native = native.decode('utf-8').lower()
+        english = english.decode('utf-8').lower()
+        translit = strip_accents(native).lower()
+
+        if lowered in native or lowered in english or lowered in translit:
             return True
         else:
             return False
diff --git a/pyanaconda/ui/gui/utils.py b/pyanaconda/ui/gui/utils.py
index 775b6d7..8f3c328 100644
--- a/pyanaconda/ui/gui/utils.py
+++ b/pyanaconda/ui/gui/utils.py
@@ -424,7 +424,9 @@ def escape_markup(value):
     if isinstance(value, unicode):
         value = value.encode("utf-8")
 
-    return GLib.markup_escape_text(str(value))
+    escaped = GLib.markup_escape_text(str(value))
+
+    return escaped.decode("utf-8")
 
 # This will be populated by override_cell_property. Keys are tuples of (column, renderer).
 # Values are a dict of the form {property-name: (property-func, property-data)}.
diff --git a/pyanaconda/users.py b/pyanaconda/users.py
index b7f9417..14a69f5 100644
--- a/pyanaconda/users.py
+++ b/pyanaconda/users.py
@@ -27,6 +27,7 @@
 import tempfile
 import os
 import os.path
+import locale
 from pyanaconda import iutil
 import pwquality
 from pyanaconda.iutil import strip_accents
@@ -177,7 +178,8 @@ def validatePassword(pw, user="root", settings=None, minlen=None):
             # Leave valid alone here: the password is weak but can still
             # be accepted.
             # PWQError values are built as a tuple of (int, str)
-            message = e.args[1]
+            # Conver the str message (encoded to the current locale) to a unicode
+            message = e.args[1].decode(locale.nl_langinfo(locale.CODESET))
 
     return (valid, strength, message)
 


-- 
To view this commit on github, visit https://github.com/rhinstaller/anaconda/commit/fca81b74e14991821926c1bfde4479211274056a


More information about the anaconda-patches mailing list