changeset 145:ccd47a2d37a6

Carefully handle non unicode strings for urwid Urwid seems to have some issues with latin1 and unicode conversion when setting a text box. Therefore be sure to pass only unicode strings to urwid.
author Björn Ricks <bjoern.ricks@intevation.de>
date Tue, 13 Nov 2012 13:12:12 +0100
parents 9e853f9e63ad
children bb70dde875fd
files getan/project.py getan/states.py
diffstat 2 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/getan/project.py	Tue Nov 13 13:11:04 2012 +0100
+++ b/getan/project.py	Tue Nov 13 13:12:12 2012 +0100
@@ -8,6 +8,8 @@
 # This is Free Software licensed unter the terms of GPLv3 or later.
 # For details see LICENSE coming with the source of 'getan'.
 
+import locale
+
 from datetime import datetime, timedelta
 
 class Project(object):
@@ -69,6 +71,11 @@
         self.end        = end
         self.desc       = desc
 
+        # carefully handle non unicode string
+        # urwid seems to have some issue with plain str
+        if not isinstance(self.desc, unicode):
+            self.desc = unicode(self.desc, locale.getpreferredencoding())
+
     def duration(self):
         return (self.end - self.start)
 
--- a/getan/states.py	Tue Nov 13 13:11:04 2012 +0100
+++ b/getan/states.py	Tue Nov 13 13:12:12 2012 +0100
@@ -9,6 +9,7 @@
 #
 
 
+import locale
 import logging
 import signal
 from   datetime import datetime, timedelta
@@ -291,7 +292,13 @@
 
     def insert(self, key):
         logger.debug("Enter key: %r" % key)
-        self.footer.insert_text(key[0])
+        text = "".join(key)
+        # check for unicode here
+        # urwid (at least up to version 1.0.2) will crash if a non-unicode
+        # string with a char > 128 is passed here
+        if not isinstance(text, unicode):
+            text = unicode(text, locale.getpreferredencoding())
+        self.footer.insert_text(text)
         return self
 
 
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)