From c2e008bda1745af6285078cce602824cda5a9e53 Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Thu, 25 Aug 2011 22:26:28 +0200 Subject: [PATCH] to_unicode: handle new common errors --- weboob/tools/misc.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/weboob/tools/misc.py b/weboob/tools/misc.py index e485a84c..18cb92ec 100644 --- a/weboob/tools/misc.py +++ b/weboob/tools/misc.py @@ -104,14 +104,17 @@ def to_unicode(text): if isinstance(text, unicode): return text if not isinstance(text, str): - text = str(text) + try: + text = str(text) + except UnicodeError: + return unicode(text) try: return unicode(text, 'utf-8') except UnicodeError: try: - return unicode(text, 'iso-8859-1') + return unicode(text, 'iso-8859-15') except UnicodeError: - return unicode(text, 'windows-1252') + return unicode(text, 'windows-1252', 'replace') def utc2local(date):