diff options
author | Zac Medico <zmedico@gentoo.org> | 2013-08-03 02:39:00 -0700 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2013-08-03 02:39:00 -0700 |
commit | 7a0380fdd44b83242bf6d5fe491834ace460c21e (patch) | |
tree | c70c6a6044970a36c50aafbfe545de229e435978 | |
parent | runTests: portage.util._argparse (diff) | |
download | portage-7a0380fdd44b83242bf6d5fe491834ace460c21e.tar.gz portage-7a0380fdd44b83242bf6d5fe491834ace460c21e.tar.bz2 portage-7a0380fdd44b83242bf6d5fe491834ace460c21e.zip |
_argparse: improve parse_* method compatibilityv2.2.0_alpha192
-rw-r--r-- | pym/portage/util/_argparse.py | 14 |
1 files changed, 12 insertions, 2 deletions
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 |