mirror of
https://github.com/openSUSE/osc.git
synced 2025-01-29 15:56:17 +01:00
Merge pull request #815 from marcus-h/python2_decode_it_fix
Fix python2 regression in util.helper.decode_it
This commit is contained in:
commit
b13935adf7
@ -56,14 +56,14 @@ def decode_list(ilist):
|
|||||||
|
|
||||||
|
|
||||||
def decode_it(obj):
|
def decode_it(obj):
|
||||||
"""Decode the given object.
|
"""Decode the given object unless it is a str.
|
||||||
|
|
||||||
If the given object has no decode method, the object itself is
|
If the given object is a str or has no decode method, the object itself is
|
||||||
returned. Otherwise, try to decode the object using utf-8. If this
|
returned. Otherwise, try to decode the object using utf-8. If this
|
||||||
fails due to a UnicodeDecodeError, try to decode the object using
|
fails due to a UnicodeDecodeError, try to decode the object using
|
||||||
latin-1.
|
latin-1.
|
||||||
"""
|
"""
|
||||||
if not hasattr(obj, 'decode'):
|
if isinstance(obj, str) or not hasattr(obj, 'decode'):
|
||||||
return obj
|
return obj
|
||||||
try:
|
try:
|
||||||
return obj.decode('utf-8')
|
return obj.decode('utf-8')
|
||||||
|
Loading…
Reference in New Issue
Block a user