summaryrefslogtreecommitdiffhomepage
path: root/youtube_dl/compat.py
diff options
context:
space:
mode:
authorPhilipp Hagemeister <[email protected]>2014-11-19 18:21:58 +0100
committerPhilipp Hagemeister <[email protected]>2014-11-19 18:21:58 +0100
commite07e931375df3984e4f92610413a2f52764bf432 (patch)
tree3af844173e60995d7a09b831a833dfc68680ea0f /youtube_dl/compat.py
parent480b7c32a94db050bb216519d3b7fd4589d1e8fb (diff)
downloadyoutube-dl-e07e931375df3984e4f92610413a2f52764bf432.tar.gz
youtube-dl-e07e931375df3984e4f92610413a2f52764bf432.zip
Work around 2.7.0 deficencies (Fixes #4223)
Diffstat (limited to 'youtube_dl/compat.py')
-rw-r--r--youtube_dl/compat.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/youtube_dl/compat.py b/youtube_dl/compat.py
index 385924803..64a975489 100644
--- a/youtube_dl/compat.py
+++ b/youtube_dl/compat.py
@@ -1,6 +1,7 @@
from __future__ import unicode_literals
import getpass
+import optparse
import os
import subprocess
import sys
@@ -297,6 +298,26 @@ except TypeError:
else:
compat_kwargs = lambda kwargs: kwargs
+
+# Fix https://github.com/rg3/youtube-dl/issues/4223
+# See http://bugs.python.org/issue9161 for what is broken
+def workaround_optparse_bug9161():
+ try:
+ optparse.OptionGroup('foo').add_option('-t')
+ except TypeError:
+ real_add_option = optparse.OptionGroup.add_option
+
+ def _compat_add_option(self, *args, **kwargs):
+ enc = lambda v: (
+ v.encode('ascii', 'replace') if isinstance(v, compat_str)
+ else v)
+ bargs = [enc(a) for a in args]
+ bkwargs = dict(
+ (k, enc(v)) for k, v in kwargs.items())
+ return real_add_option(self, *bargs, **bkwargs)
+ optparse.OptionGroup.add_option = _compat_add_option
+
+
__all__ = [
'compat_HTTPError',
'compat_chr',
@@ -323,4 +344,5 @@ __all__ = [
'compat_xml_parse_error',
'shlex_quote',
'subprocess_check_output',
+ 'workaround_optparse_bug9161',
]