1 |
commit: 5cd96f04deb82e55aa60f91a2340240c076771d8 |
2 |
Author: Pawel Hajdan, Jr <phajdan.jr <AT> gentoo <DOT> org> |
3 |
AuthorDate: Thu Jun 2 15:37:54 2011 +0000 |
4 |
Commit: Paweł Hajdan <phajdan.jr <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu Jun 2 15:37:54 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/arch-tools.git;a=commit;h=5cd96f04 |
7 |
|
8 |
Make sure to unicode-sanitize all strings passed to ncurses to prevent runtime exceptions. |
9 |
|
10 |
--- |
11 |
bugzilla-viewer.py | 16 ++++++++++------ |
12 |
1 files changed, 10 insertions(+), 6 deletions(-) |
13 |
|
14 |
diff --git a/bugzilla-viewer.py b/bugzilla-viewer.py |
15 |
index 686a3aa..e62ac98 100755 |
16 |
--- a/bugzilla-viewer.py |
17 |
+++ b/bugzilla-viewer.py |
18 |
@@ -17,6 +17,14 @@ import portage.versions |
19 |
|
20 |
CPV_REGEX = re.compile("[A-Za-z0-9+_.-]+/[A-Za-z0-9+_-]+-[0-9]+(?:\.[0-9]+)*[a-z0-9_]*(?:-r[0-9]+)?") |
21 |
|
22 |
+def unicode_sanitize(text): |
23 |
+ """Converts a possibly unicode text to a regular string.""" |
24 |
+ if type(text) == unicode: |
25 |
+ real_output = text |
26 |
+ else: |
27 |
+ real_output = unicode(text, errors='replace') |
28 |
+ return real_output.encode("utf-8") |
29 |
+ |
30 |
class TermTooSmall(Exception): |
31 |
pass |
32 |
|
33 |
@@ -135,7 +143,7 @@ class MainWindow: |
34 |
|
35 |
for i in range(len(self.bugs)): |
36 |
self.bugs_pad.addstr(i, 0, |
37 |
- " %d %s" % (self.bugs[i].id_number(), self.bugs[i].summary())) |
38 |
+ unicode_sanitize(" %d %s" % (self.bugs[i].id_number(), self.bugs[i].summary()))) |
39 |
|
40 |
def scroll_bugs_pad(self, amount): |
41 |
height = len(self.bugs) |
42 |
@@ -218,11 +226,7 @@ class MainWindow: |
43 |
self.contents_pad_pos = 0 |
44 |
|
45 |
for i in range(len(output)): |
46 |
- if type(output[i]) == unicode: |
47 |
- real_output = output[i] |
48 |
- else: |
49 |
- real_output = unicode(output[i], errors='replace') |
50 |
- self.contents_pad.addstr(i, 0, real_output.encode("utf-8")) |
51 |
+ self.contents_pad.addstr(i, 0, unicode_sanitize(output[i])) |
52 |
|
53 |
def scroll_contents_pad(self, amount): |
54 |
height = self.contents_pad_length - self.height + 5 |