Merge lp:~mvo/software-center/lp967036 into lp:software-center

Proposed by Michael Vogt
Status: Merged
Merged at revision: 2966
Proposed branch: lp:~mvo/software-center/lp967036
Merge into: lp:software-center
Diff against target: 99 lines (+24/-9)
3 files modified
softwarecenter/hw.py (+2/-2)
softwarecenter/ui/gtk3/widgets/labels.py (+9/-5)
test/gtk3/test_widgets.py (+13/-2)
To merge this branch: bzr merge lp:~mvo/software-center/lp967036
Reviewer Review Type Date Requested Status
Gary Lasker (community) Approve
Review via email: mp+101694@code.launchpad.net

Description of the change

This fixes the unicode/str crash in #967036 and adds a regression test. Its a rather unfortunate str/unicode
python issue we are hitting here. We use the utf8 encoded summary string as input for %s but we can't specify
a encoding in %s AFAIK so python will use "ascii" when calling str() on it and that fails. So we first need
to convert it back to unicode :/ The alternative would be to return a unicode translated object from get_hw_short_summary() but that would be inconsistent with what we do in other functions. I'm not overly happy with the current fix, but I don't better alternatives currently. Fortunately py3 will make this problem go away when everything is unicode (or bytes).

To test install language-pack-gnome-ru and run:
$ LANGUAGE=ru ./software-center darwinia
then you should see under the details that it requires a mouse ("мышь" in russia apparently :)

I also made the label selectable to be consistent with the other labels.

To post a comment you must log in.
lp:~mvo/software-center/lp967036 updated
2963. By Kiwinote

trivial: pep8 fixes

2964. By Michael Vogt

merged lp:~gary-lasker/software-center/sorting-fix-lp969215

2965. By Kiwinote

* sc/ui/gtk3/widgets/apptreeview.py:
  - everyone tries to expand a category in the installed pane by clicking
    on the text rather than the expander arrow (LP: #877130)

Revision history for this message
Gary Lasker (gary-lasker) wrote :

Nice unicode magic! And thanks for the unit test. :)

Thank you, Michael!

review: Approve
lp:~mvo/software-center/lp967036 updated
2966. By Gary Lasker

* lp:~mvo/software-center/lp967036:
  - fix UnicodeDecodeError crash for apps with hardware
    requirements in the details view (LP: #967036)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'softwarecenter/hw.py'
2--- softwarecenter/hw.py 2012-03-20 08:40:10 +0000
3+++ softwarecenter/hw.py 2012-04-12 08:15:24 +0000
4@@ -86,7 +86,7 @@
5 # FIXME: deal with OPENGL_DRIVER_BLACKLIST_TAG as this needs rsplit(":")
6 # and a view of all available tags
7 s = TAG_DESCRIPTION.get(tag)
8- return utf8(s)
9+ return utf8(_(s))
10
11
12 def get_hw_missing_long_description(tags):
13@@ -107,7 +107,7 @@
14 # ensure that the last \n is gone
15 if s:
16 s = s[:-1]
17- return utf8(s)
18+ return utf8(_(s))
19
20
21 def get_private_extensions_hardware_support_for_tags(tags):
22
23=== modified file 'softwarecenter/ui/gtk3/widgets/labels.py'
24--- softwarecenter/ui/gtk3/widgets/labels.py 2012-03-29 18:53:08 +0000
25+++ softwarecenter/ui/gtk3/widgets/labels.py 2012-04-12 08:15:24 +0000
26@@ -20,7 +20,6 @@
27 from gettext import gettext as _
28
29 from softwarecenter.hw import get_hw_short_description
30-from softwarecenter.utils import utf8
31
32
33 class HardwareRequirementsLabel(Gtk.HBox):
34@@ -58,6 +57,7 @@
35
36 def _build_ui(self):
37 self._label = Gtk.Label()
38+ self._label.set_selectable(True)
39 self._label.show()
40 self.pack_start(self._label, True, True, 0)
41
42@@ -66,12 +66,16 @@
43 sym = self.SUPPORTED_SYM[self.result]
44 # we add a trailing
45 if self.last_item:
46- s = self.LABEL_LAST_ITEM
47+ label_text = self.LABEL_LAST_ITEM
48 else:
49- s = self.LABEL
50- return _(s) % {
51+ label_text = self.LABEL
52+ short_descr = get_hw_short_description(self.tag)
53+ return _(label_text) % {
54 "sym": sym,
55- "hardware": _(utf8(get_hw_short_description(self.tag)))
56+ # we need unicode() here instead of utf8 or str because
57+ # the %s in "label_text" will cause str() to be called on the
58+ # encoded string, but it will not know what encoding to use
59+ "hardware": unicode(short_descr, "utf8", "ignore")
60 }
61
62 def set_hardware_requirement(self, tag, result):
63
64=== modified file 'test/gtk3/test_widgets.py'
65--- test/gtk3/test_widgets.py 2012-03-15 19:31:46 +0000
66+++ test/gtk3/test_widgets.py 2012-04-12 08:15:24 +0000
67@@ -9,12 +9,11 @@
68
69 from testutils import setup_test_env, do_events
70 setup_test_env()
71+from softwarecenter.utils import utf8
72 from softwarecenter.ui.gtk3.widgets.reviews import get_test_reviews_window
73-
74 from softwarecenter.ui.gtk3.widgets.labels import (
75 HardwareRequirementsLabel, HardwareRequirementsBox)
76
77-
78 # window destory timeout
79 TIMEOUT=100
80
81@@ -145,6 +144,18 @@
82 label.set_hardware_requirement('hardware::video:opengl', 'yes')
83 self.assertEqual(len(label.get_children()), 1)
84
85+ # regression test for bug #967036
86+ @patch("softwarecenter.ui.gtk3.widgets.labels.get_hw_short_description")
87+ def test_hardware_requirements_label_utf8(self, mock_get_hw):
88+ magic_marker = u" \u1234 GPS"
89+ mock_get_hw.return_value = utf8(magic_marker)
90+ label = HardwareRequirementsLabel()
91+ label.set_hardware_requirement('hardware::gps', 'yes')
92+ self.assertEqual(
93+ label.get_label(),
94+ u"%s%s" % (HardwareRequirementsLabel.SUPPORTED_SYM["yes"],
95+ magic_marker))
96+
97 def test_hardware_requirements_box(self):
98 box = HardwareRequirementsBox()
99 # test empty

Subscribers

People subscribed via source and target branches