Browse Source

refactor to_utf8

Arnau Sanchez 9 years ago
parent
commit
f0d668b567
1 changed files with 4 additions and 4 deletions
  1. 4 4
      youtube_upload/lib.py

+ 4 - 4
youtube_upload/lib.py

@@ -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):