mirror of
https://github.com/openSUSE/osc.git
synced 2024-11-10 06:46:15 +01:00
Merge pull request #803 from marcus-h/remove_chardet_decoding
Do not use the chardet module in util.helper.decode_it
This commit is contained in:
commit
869772f054
@ -56,22 +56,19 @@ def decode_list(ilist):
|
|||||||
|
|
||||||
|
|
||||||
def decode_it(obj):
|
def decode_it(obj):
|
||||||
""" Decodes the given object if obj is not a string
|
"""Decode the given object.
|
||||||
based on the chardet module if possible
|
|
||||||
"""
|
|
||||||
|
|
||||||
if obj is None or isinstance(obj, str):
|
If the given object has no decode method, the object itself is
|
||||||
|
returned. Otherwise, try to decode the object using utf-8. If this
|
||||||
|
fails due to a UnicodeDecodeError, try to decode the object using
|
||||||
|
latin-1.
|
||||||
|
"""
|
||||||
|
if not hasattr(obj, 'decode'):
|
||||||
return obj
|
return obj
|
||||||
else:
|
try:
|
||||||
try:
|
return obj.decode('utf-8')
|
||||||
import chardet
|
except UnicodeDecodeError:
|
||||||
return obj.decode(chardet.detect(obj)['encoding'])
|
return obj.decode('latin-1')
|
||||||
except:
|
|
||||||
try:
|
|
||||||
import locale
|
|
||||||
return obj.decode(locale.getlocale()[1])
|
|
||||||
except:
|
|
||||||
return obj.decode('latin-1')
|
|
||||||
|
|
||||||
|
|
||||||
def raw_input(*args):
|
def raw_input(*args):
|
||||||
|
Loading…
Reference in New Issue
Block a user