[compat] Work around kwargs bugs in old 2.6 Python releases (Fixes #3813)

pull/8/head
Philipp Hagemeister 10 years ago
parent a0155d93d9
commit c7b0add86f

@ -288,6 +288,14 @@ if sys.version_info < (3, 0) and sys.platform == 'win32':
else: else:
compat_getpass = getpass.getpass 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__ = [ __all__ = [
'compat_HTTPError', 'compat_HTTPError',
@ -299,6 +307,7 @@ __all__ = [
'compat_html_entities', 'compat_html_entities',
'compat_html_parser', 'compat_html_parser',
'compat_http_client', 'compat_http_client',
'compat_kwargs',
'compat_ord', 'compat_ord',
'compat_parse_qs', 'compat_parse_qs',
'compat_print', 'compat_print',

@ -8,6 +8,7 @@ import sys
from .compat import ( from .compat import (
compat_expanduser, compat_expanduser,
compat_getenv, compat_getenv,
compat_kwargs,
) )
from .utils import ( from .utils import (
get_term_width, get_term_width,
@ -112,7 +113,7 @@ def parseOpts(overrideArguments=None):
'conflict_handler': 'resolve', 'conflict_handler': 'resolve',
} }
parser = optparse.OptionParser(**kw) parser = optparse.OptionParser(**compat_kwargs(kw))
general = optparse.OptionGroup(parser, 'General Options') general = optparse.OptionGroup(parser, 'General Options')
general.add_option( general.add_option(

Loading…
Cancel
Save