Browse Source

Fixed some issues with Python2 and Unix

Aaron Gokaslan 9 years ago
parent
commit
1a24d1aaab
2 changed files with 8 additions and 5 deletions
  1. 3 2
      youtube_upload/auth/console.py
  2. 5 3
      youtube_upload/lib.py

+ 3 - 2
youtube_upload/auth/console.py

@@ -1,9 +1,10 @@
 import sys
-from builtins import input
 
 def get_code(authorize_url):
     
     """Show authorization URL and return the code the user wrote."""
     message = "Check this link in your browser: {0}".format(authorize_url)
     sys.stderr.write(message + "\n")
-    return input("Enter verification code: ")
+    try: input = raw_input #For Python2 compatability
+    except NameError: pass
+    return input("Enter verification code: ")

+ 5 - 3
youtube_upload/lib.py

@@ -18,11 +18,13 @@ 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'):   
+    if hasattr(s, 'decode'):#Python 3 workaround
         return s.decode(current).encode("UTF-8") if s and current != "UTF-8" else s
     else:
-        return bytes.decode(s)
-
+        if isinstance(s, bytes):
+            s = bytes.decode(s)
+        return s
+       
 def debug(obj, fd=sys.stderr):
     """Write obj to standard error."""
     try: