Browse Source

Fixed 'b in error messages for Python 3

Aaron Gokaslan 9 years ago
parent
commit
f00ff5ae54
1 changed files with 6 additions and 2 deletions
  1. 6 2
      youtube_upload/lib.py

+ 6 - 2
youtube_upload/lib.py

@@ -29,10 +29,14 @@ def debug(obj, fd=sys.stderr):
     """Write obj to standard error."""
     try:
         unicode
+        should_encode = not isinstance(obj, unicode)
     except NameError:
-        unicode = bytes
+        should_encode = False #Doing so is harmless in Python 3
     string = str(obj.encode(get_encoding(fd), "backslashreplace")
-                 if not isinstance(obj, unicode) else obj)
+                 if should_encode else obj)
+    #Python 3 handling workaround
+    if sys.version_info >= (3, 0) and isinstance(string, bytes):
+        fd.buffer.write(string + "\n") #We write the encoding directly
     fd.write(string + "\n")
 
 def catch_exceptions(exit_codes, fun, *args, **kwargs):