fix unicode issues

This commit is contained in:
Romain Bignon 2010-12-01 15:22:47 +01:00
commit a42f75700a
2 changed files with 7 additions and 4 deletions

View file

@ -33,7 +33,7 @@ from weboob.core import Weboob, CallErrors
from weboob.core.scheduler import Scheduler from weboob.core.scheduler import Scheduler
from weboob.capabilities.messages import ICapMessages, ICapMessagesPost, Thread, Message from weboob.capabilities.messages import ICapMessages, ICapMessagesPost, Thread, Message
from weboob.tools.application.repl import ReplApplication from weboob.tools.application.repl import ReplApplication
from weboob.tools.misc import html2text, get_backtrace, utc2local from weboob.tools.misc import html2text, get_backtrace, utc2local, to_unicode
__all__ = ['Monboob'] __all__ = ['Monboob']
@ -196,9 +196,9 @@ class Monboob(ReplApplication):
backend.post_message(message) backend.post_message(message)
except Exception, e: except Exception, e:
content = u'Unable to send message to %s:\n' % thread_id content = u'Unable to send message to %s:\n' % thread_id
content += u'\n\t%s\n' % e content += u'\n\t%s\n' % to_unicode(e)
if logging.root.level == logging.DEBUG: if logging.root.level == logging.DEBUG:
content += u'\n%s\n' % get_backtrace(e) content += u'\n%s\n' % to_unicode(get_backtrace(e))
self.send_email(backend, Message(thread, self.send_email(backend, Message(thread,
0, 0,
title='Unable to send message', title='Unable to send message',

View file

@ -38,7 +38,10 @@ def to_unicode(text):
if isinstance(text, unicode): if isinstance(text, unicode):
return text return text
if not isinstance(text, str): if not isinstance(text, str):
text = str(text) try:
text = str(text)
except UnicodeError:
return unicode(text)
try: try:
return unicode(text, "utf8") return unicode(text, "utf8")
except UnicodeError: except UnicodeError: