|
@@ -19,11 +19,11 @@ def default_sigint():
|
|
|
def to_utf8(s):
|
|
|
"""Re-encode string from the default system encoding to UTF-8."""
|
|
|
current = locale.getpreferredencoding()
|
|
|
- if hasattr(s, 'decode'):#Python 3 workaround
|
|
|
- return s.decode(current).encode("UTF-8") if s and current != "UTF-8" else s
|
|
|
+ if hasattr(s, 'decode'): #Python 3 workaround
|
|
|
+ return (s.decode(current).encode("UTF-8") if s and current != "UTF-8" else s)
|
|
|
+ elif isinstance(s, bytes):
|
|
|
+ return bytes.decode(s)
|
|
|
else:
|
|
|
- if isinstance(s, bytes):
|
|
|
- s = bytes.decode(s)
|
|
|
return s
|
|
|
|
|
|
def debug(obj, fd=sys.stderr):
|