From 94cfbe354a35f590b9536660d9db741675c78f3e Mon Sep 17 00:00:00 2001 From: Ruud Date: Sat, 14 Jan 2012 13:40:31 +0100 Subject: [PATCH] Try decode first on toUnicode --- couchpotato/core/helpers/encoding.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/couchpotato/core/helpers/encoding.py b/couchpotato/core/helpers/encoding.py index 1f1fe161..6e521673 100644 --- a/couchpotato/core/helpers/encoding.py +++ b/couchpotato/core/helpers/encoding.py @@ -1,5 +1,6 @@ from couchpotato.core.logger import CPLog from string import ascii_letters, digits +import os import re import unicodedata @@ -19,11 +20,18 @@ def simplifyString(original): def toUnicode(original, *args): try: - if type(original) is unicode: + if type(original) == str: + try: + from couchpotato.environment import Env + return original.decode(Env.get('encoding')) + except UnicodeDecodeError: + raise + elif type(original) is unicode: return original else: return unicode(original, *args) except UnicodeDecodeError: + log.error('Unable to decode value: %s... ' % repr(original)[:20]) ascii_text = str(original).encode('string_escape') return unicode(ascii_text)