]> git.bitcoin.ninja Git - youtube-dl/commitdiff
[options] Fix file based configurations for python 2 (Closes #5401)
authorSergey M․ <dstftw@gmail.com>
Sat, 11 Apr 2015 21:57:56 +0000 (03:57 +0600)
committerSergey M․ <dstftw@gmail.com>
Sat, 11 Apr 2015 21:57:56 +0000 (03:57 +0600)
youtube_dl/options.py

index 5720fb424ff44ac3e659a797ee2bef8a5a1529b1..11603f60d6c9a1f5aff35a15927a7d1db2521802 100644 (file)
@@ -794,21 +794,22 @@ def parseOpts(overrideArguments=None):
         if opts.verbose:
             write_string('[debug] Override config: ' + repr(overrideArguments) + '\n')
     else:
-        command_line_conf = sys.argv[1:]
-        # Workaround for Python 2.x, where argv is a byte list
-        if sys.version_info < (3,):
-            command_line_conf = [
-                a.decode(preferredencoding(), 'replace') for a in command_line_conf]
+        def compat_conf(conf):
+            if sys.version_info < (3,):
+                return [a.decode(preferredencoding(), 'replace') for a in conf]
+            return conf
+
+        command_line_conf = compat_conf(sys.argv[1:])
 
         if '--ignore-config' in command_line_conf:
             system_conf = []
             user_conf = []
         else:
-            system_conf = _readOptions('/etc/youtube-dl.conf')
+            system_conf = compat_conf(_readOptions('/etc/youtube-dl.conf'))
             if '--ignore-config' in system_conf:
                 user_conf = []
             else:
-                user_conf = _readUserConf()
+                user_conf = compat_conf(_readUserConf())
         argv = system_conf + user_conf + command_line_conf
 
         opts, args = parser.parse_args(argv)