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
This commit is contained in:
helmutm 2008-10-12 07:28:45 +00:00
parent 83f4e5b078
commit b16be1581a

View file

@ -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''