mirror of https://github.com/yt-dlp/yt-dlp.git
Work around 2.7.0 deficencies (Fixes #4223)
This commit is contained in:
parent
480b7c32a9
commit
e07e931375
|
@ -19,6 +19,7 @@ from .compat import (
|
||||||
compat_expanduser,
|
compat_expanduser,
|
||||||
compat_getpass,
|
compat_getpass,
|
||||||
compat_print,
|
compat_print,
|
||||||
|
workaround_optparse_bug9161,
|
||||||
)
|
)
|
||||||
from .utils import (
|
from .utils import (
|
||||||
DateRange,
|
DateRange,
|
||||||
|
@ -57,6 +58,8 @@ def _real_main(argv=None):
|
||||||
# https://github.com/rg3/youtube-dl/issues/820
|
# https://github.com/rg3/youtube-dl/issues/820
|
||||||
codecs.register(lambda name: codecs.lookup('utf-8') if name == 'cp65001' else None)
|
codecs.register(lambda name: codecs.lookup('utf-8') if name == 'cp65001' else None)
|
||||||
|
|
||||||
|
workaround_optparse_bug9161()
|
||||||
|
|
||||||
setproctitle('youtube-dl')
|
setproctitle('youtube-dl')
|
||||||
|
|
||||||
parser, opts, args = parseOpts(argv)
|
parser, opts, args = parseOpts(argv)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import getpass
|
import getpass
|
||||||
|
import optparse
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
@ -297,6 +298,26 @@ except TypeError:
|
||||||
else:
|
else:
|
||||||
compat_kwargs = lambda kwargs: kwargs
|
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__ = [
|
__all__ = [
|
||||||
'compat_HTTPError',
|
'compat_HTTPError',
|
||||||
'compat_chr',
|
'compat_chr',
|
||||||
|
@ -323,4 +344,5 @@ __all__ = [
|
||||||
'compat_xml_parse_error',
|
'compat_xml_parse_error',
|
||||||
'shlex_quote',
|
'shlex_quote',
|
||||||
'subprocess_check_output',
|
'subprocess_check_output',
|
||||||
|
'workaround_optparse_bug9161',
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue