[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#750120: python-apt: Some locales use no-breaking space for LC_NUMBER, so return unicode for SizeToStr



Package: python-apt
Version: 0.9.3.5
Severity: normal
Tags: upstream l10n patch

Dear Maintainer,

this is on Ubuntu, but this was the closest I could find to the python-apt
upstream :)

This is breaking the distribution upgrade on my girlfriends computer
(since she is using nn_NO.UTF8 as her language).

Ubuntu's upgrading python script is not expecting that the str returned
will have undecodeable chars. This could also be fixed at Ubuntu's
level, but looking at it, I thought it hit closer to home for
apt_pkg.size_to_str() to return a ready decoded unicode string to all
its users.


-- System Information:
Debian Release: jessie/sid
  APT prefers trusty-updates
  APT policy: (500, 'trusty-updates'), (500, 'trusty-security'), (500, 'trusty'), (100, 'trusty-backports')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 3.13.0-27-generic (SMP w/4 CPU cores)
Locale: LANG=nn_NO.UTF-8, LC_CTYPE=nn_NO.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages python-apt depends on:
ii  libapt-inst1.5     1.0.1ubuntu2
ii  libapt-pkg4.12     1.0.1ubuntu2
ii  libc6              2.19-0ubuntu6
ii  libgcc1            1:4.9-20140406-0ubuntu1
ii  libstdc++6         4.8.2-19ubuntu1
ii  python             2.7.5-5ubuntu3
ii  python-apt-common  0.9.3.5
pn  python:any         <none>

Versions of packages python-apt recommends:
ii  iso-codes    3.52-1
ii  lsb-release  4.1+Debian11ubuntu6
ii  xz-utils     5.1.1alpha+20120614-2ubuntu2

Versions of packages python-apt suggests:
pn  python-apt-dbg  <none>
pn  python-apt-doc  <none>
ii  python-gtk2     2.24.0-3ubuntu3
pn  python-vte      <none>

-- no debconf information
>From 1f482cbb9ebb2338cbe288613fc1554682a58637 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Odin=20H=C3=B8rthe=20Omdal?= <odinho@opera.com>
Date: Sun, 1 Jun 2014 21:05:23 +0200
Subject: [PATCH] Some locales use no-breaking space for text, so return
 unicode

---
 python/string.cc          |  3 ++-
 tests/test_size_to_str.py | 10 +++++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/python/string.cc b/python/string.cc
index 9b02c93..006f102 100644
--- a/python/string.cc
+++ b/python/string.cc
@@ -86,7 +86,8 @@ PyObject *StrSizeToStr(PyObject *Self,PyObject *Args)
    // Check for OverflowErrors or other exceptions during conversion.
    if (PyErr_Occurred())
       return 0;
-   return CppPyString(SizeToStr(value));
+   std::string Str = SizeToStr(value)
+   return PyUnicode_FromStringAndSize(Str.c_str(),Str.length)
 }
 
 PyObject *StrQuoteString(PyObject *Self,PyObject *Args)
diff --git a/tests/test_size_to_str.py b/tests/test_size_to_str.py
index ba1e45b..c7b844d 100644
--- a/tests/test_size_to_str.py
+++ b/tests/test_size_to_str.py
@@ -91,13 +91,21 @@ class SizeToStrTestCase(unittest.TestCase):
 
 
 class RegressionTestCase(unittest.TestCase):
-    """Regression test for LP: #1030278"""
+    """Regression tests"""
 
     def test_no_overflow_error(self):
         # LP: #1030278 produces an overflow error in size_to_str() with a big
         # value under Python 3.
         self.assertEqual(apt_pkg.size_to_str(2147483648000000000000), '2147 E')
 
+    def test_expect_unicode(self):
+        import locale
+        old_locale = locale.getlocale()
+        locale.setlocale(locale.LC_ALL, 'nn_NO.utf8')
+        try:
+            self.assertEqual(apt_pkg.size_to_str(1000000), u'1\xa0000 k')
+        finally:
+            locale.setlocale(locale.LC_ALL, old_locale)
 
 if __name__ == "__main__":
     unittest.main()
-- 
1.9.1


Reply to: