Use detected encoding

#4388
This commit is contained in:
Ruud
2014-12-27 13:46:25 +01:00
parent 229d67c086
commit 8f4e03d04b
+6 -5
View File
@@ -37,14 +37,15 @@ def toUnicode(original, *args):
except: except:
try: try:
detected = detect(original) detected = detect(original)
if detected.get('encoding') == 'utf-8': try:
return original.decode('utf-8') return original.decode(detected.get('encoding'))
return ek(original, *args) except:
return ek(original, *args)
except: except:
raise raise
except: except:
log.error('Unable to decode value "%s..." : %s ', (repr(original)[:20], traceback.format_exc())) log.error('Unable to decode value "%s..." : %s ', (repr(original)[:20], traceback.format_exc()))
return toSafeString(original) return 'ERROR DECODING STRING'
def ss(original, *args): def ss(original, *args):
@@ -91,7 +92,7 @@ def ek(original, *args):
if isinstance(original, (str, unicode)): if isinstance(original, (str, unicode)):
try: try:
from couchpotato.environment import Env from couchpotato.environment import Env
return original.decode(Env.get('encoding')) return original.decode(Env.get('encoding'), 'ignore')
except UnicodeDecodeError: except UnicodeDecodeError:
raise raise