From b16be1581a3938d60a7206163f5f1eb6a86c1329 Mon Sep 17 00:00:00 2001 From: helmutm Date: Sun, 12 Oct 2008 07:28:45 +0000 Subject: [PATCH] fall back to ISO if error with UTF-8 git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2918 fd906abe-77d9-0310-91a1-e0d9ade77398 --- util/format.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/util/format.py b/util/format.py index 660430a..a5b532e 100644 --- a/util/format.py +++ b/util/format.py @@ -54,10 +54,13 @@ def toStr(value, encoding='UTF-8'): return value.encode(encoding) return str(value) -def toUnicode(value, encoding='UTF-8'): +def toUnicode(value, encoding='UTF-8', fallback='ISO8859-15'): if isinstance(value, unicode): return value elif isinstance(value, str): - return value.decode(encoding) + try: + return value.decode(encoding) + except UnicodeDecodeError: + return value.decode(fallback) else: return u''