From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 70F311381F3 for ; Sat, 3 Aug 2013 09:39:27 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 53EBEE0A88; Sat, 3 Aug 2013 09:39:24 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id E1E26E0A88 for ; Sat, 3 Aug 2013 09:39:23 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 9F12033EC57 for ; Sat, 3 Aug 2013 09:39:22 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 04634E468F for ; Sat, 3 Aug 2013 09:39:20 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1375522740.7a0380fdd44b83242bf6d5fe491834ace460c21e.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/util/ X-VCS-Repository: proj/portage X-VCS-Files: pym/portage/util/_argparse.py X-VCS-Directories: pym/portage/util/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 7a0380fdd44b83242bf6d5fe491834ace460c21e X-VCS-Branch: master Date: Sat, 3 Aug 2013 09:39:20 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 4d2fad01-e1e2-47d3-a009-b68be449bd5c X-Archives-Hash: 2d5c35331df04f352a15144e6357ba16 commit: 7a0380fdd44b83242bf6d5fe491834ace460c21e Author: Zac Medico gentoo org> AuthorDate: Sat Aug 3 09:39:00 2013 +0000 Commit: Zac Medico gentoo org> CommitDate: Sat Aug 3 09:39:00 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=7a0380fd _argparse: improve parse_* method compatibility --- pym/portage/util/_argparse.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pym/portage/util/_argparse.py b/pym/portage/util/_argparse.py index a9cdc9e..6ca7852 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