From: Zac Medico Date: Sat, 3 Aug 2013 09:39:00 +0000 (-0700) Subject: _argparse: improve parse_* method compatibility X-Git-Tag: v2.2.0_alpha192 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=7a0380fdd44b83242bf6d5fe491834ace460c21e;p=portage.git _argparse: improve parse_* method compatibility --- diff --git a/pym/portage/util/_argparse.py b/pym/portage/util/_argparse.py index a9cdc9e62..6ca785235 100644 --- a/pym/portage/util/_argparse.py +++ b/pym/portage/util/_argparse.py @@ -9,6 +9,8 @@ except ImportError: # Compatibility with Python 2.6 and 3.1 from optparse import OptionGroup, OptionParser + from portage.localization import _ + class ArgumentParser(object): def __init__(self, **kwargs): add_help = kwargs.pop("add_help", None) @@ -17,8 +19,6 @@ except ImportError: parser = OptionParser(**kwargs) self._parser = parser self.add_argument = parser.add_option - self.parse_known_args = parser.parse_args - self.parse_args = parser.parse_args self.print_help = parser.print_help self.error = parser.error @@ -27,6 +27,16 @@ except ImportError: self._parser.add_option_group(optiongroup) return _ArgumentGroup(optiongroup) + def parse_known_args(self, args=None, namespace=None): + return self._parser.parse_args(args, namespace) + + def parse_args(self, args=None, namespace=None): + args, argv = self.parse_known_args(args, namespace) + if argv: + msg = _('unrecognized arguments: %s') + self.error(msg % ' '.join(argv)) + return args + class _ArgumentGroup(object): def __init__(self, optiongroup): self.add_argument = optiongroup.add_option