diff options
author | Pawel Hajdan, Jr <phajdan.jr@gentoo.org> | 2011-06-02 17:37:54 +0200 |
---|---|---|
committer | Pawel Hajdan, Jr <phajdan.jr@gentoo.org> | 2011-06-02 17:37:54 +0200 |
commit | 5cd96f04deb82e55aa60f91a2340240c076771d8 (patch) | |
tree | 737621f88ddcc7de2e1949e956c4c2521b885e81 /bugzilla-viewer.py | |
parent | Bugfix: wrong variable name used for repoman output. (diff) | |
download | arch-tools-5cd96f04deb82e55aa60f91a2340240c076771d8.tar.gz arch-tools-5cd96f04deb82e55aa60f91a2340240c076771d8.tar.bz2 arch-tools-5cd96f04deb82e55aa60f91a2340240c076771d8.zip |
Make sure to unicode-sanitize all strings passed to ncurses to prevent runtime exceptions.
Diffstat (limited to 'bugzilla-viewer.py')
-rwxr-xr-x | bugzilla-viewer.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/bugzilla-viewer.py b/bugzilla-viewer.py index 686a3aa..e62ac98 100755 --- a/bugzilla-viewer.py +++ b/bugzilla-viewer.py @@ -17,6 +17,14 @@ import portage.versions CPV_REGEX = re.compile("[A-Za-z0-9+_.-]+/[A-Za-z0-9+_-]+-[0-9]+(?:\.[0-9]+)*[a-z0-9_]*(?:-r[0-9]+)?") +def unicode_sanitize(text): + """Converts a possibly unicode text to a regular string.""" + if type(text) == unicode: + real_output = text + else: + real_output = unicode(text, errors='replace') + return real_output.encode("utf-8") + class TermTooSmall(Exception): pass @@ -135,7 +143,7 @@ class MainWindow: for i in range(len(self.bugs)): self.bugs_pad.addstr(i, 0, - " %d %s" % (self.bugs[i].id_number(), self.bugs[i].summary())) + unicode_sanitize(" %d %s" % (self.bugs[i].id_number(), self.bugs[i].summary()))) def scroll_bugs_pad(self, amount): height = len(self.bugs) @@ -218,11 +226,7 @@ class MainWindow: self.contents_pad_pos = 0 for i in range(len(output)): - if type(output[i]) == unicode: - real_output = output[i] - else: - real_output = unicode(output[i], errors='replace') - self.contents_pad.addstr(i, 0, real_output.encode("utf-8")) + self.contents_pad.addstr(i, 0, unicode_sanitize(output[i])) def scroll_contents_pad(self, amount): height = self.contents_pad_length - self.height + 5 |