Replace failure handling with up-front check.
authorPhilipp Hagemeister <phihag@phihag.de>
Thu, 24 Jul 2014 11:29:44 +0000 (13:29 +0200)
committerPhilipp Hagemeister <phihag@phihag.de>
Thu, 24 Jul 2014 11:29:44 +0000 (13:29 +0200)
The only time that write_string should fail is if the Python is completely braindead.
Check for that condition and output a more accurate warning.

See #3326 for details.

youtube_dl/YoutubeDL.py

index 4ff1ae0e8970e43994fcf5a83a2e0719a0e324fa..f295174cf32c9c9289ff97652d2228b17f701395 100755 (executable)
@@ -1234,21 +1234,18 @@ class YoutubeDL(object):
         if not self.params.get('verbose'):
             return
 
+        if type('') is not compat_str:
+            # Python 2.6 on SLES11 SP1 (https://github.com/rg3/youtube-dl/issues/3326)
+            self.report_warning(
+                'Your Python is broken! Update to a newer and supported version')
+
         encoding_str = (
             '[debug] Encodings: locale %s, fs %s, out %s, pref %s\n' % (
                 locale.getpreferredencoding(),
                 sys.getfilesystemencoding(),
                 sys.stdout.encoding,
                 self.get_encoding()))
-        try:
-            write_string(encoding_str, encoding=None)
-        except:
-            errmsg = 'Failed to write encoding string %r' % encoding_str
-            try:
-                sys.stdout.write(errmsg)
-            except:
-                pass
-            raise IOError(errmsg)
+        write_string(encoding_str, encoding=None)
 
         self._write_string('[debug] youtube-dl version ' + __version__ + '\n')
         try: