From c7b0add86f67942b8e68c1b9dd537132e9383d2f Mon Sep 17 00:00:00 2001 From: Philipp Hagemeister Date: Sat, 15 Nov 2014 15:17:19 +0100 Subject: [PATCH] [compat] Work around kwargs bugs in old 2.6 Python releases (Fixes #3813) --- youtube_dl/compat.py | 9 +++++++++ youtube_dl/options.py | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/youtube_dl/compat.py b/youtube_dl/compat.py index b3752634a..385924803 100644 --- a/youtube_dl/compat.py +++ b/youtube_dl/compat.py @@ -288,6 +288,14 @@ def compat_getpass(prompt, *args, **kwargs): else: compat_getpass = getpass.getpass +# Old 2.6 and 2.7 releases require kwargs to be bytes +try: + (lambda x: x)(**{'x': 0}) +except TypeError: + def compat_kwargs(kwargs): + return dict((bytes(k), v) for k, v in kwargs.items()) +else: + compat_kwargs = lambda kwargs: kwargs __all__ = [ 'compat_HTTPError', @@ -299,6 +307,7 @@ def compat_getpass(prompt, *args, **kwargs): 'compat_html_entities', 'compat_html_parser', 'compat_http_client', + 'compat_kwargs', 'compat_ord', 'compat_parse_qs', 'compat_print', diff --git a/youtube_dl/options.py b/youtube_dl/options.py index c182abfdc..16aa6ffca 100644 --- a/youtube_dl/options.py +++ b/youtube_dl/options.py @@ -8,6 +8,7 @@ from .compat import ( compat_expanduser, compat_getenv, + compat_kwargs, ) from .utils import ( get_term_width, @@ -112,7 +113,7 @@ def _hide_login_info(opts): 'conflict_handler': 'resolve', } - parser = optparse.OptionParser(**kw) + parser = optparse.OptionParser(**compat_kwargs(kw)) general = optparse.OptionGroup(parser, 'General Options') general.add_option(