From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1QsJHV-00012A-4L for garchives@archives.gentoo.org; Sat, 13 Aug 2011 18:50:01 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 9DC2A21C2DA; Sat, 13 Aug 2011 18:49:33 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 6F75621C2DA for ; Sat, 13 Aug 2011 18:49:33 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id EE9EE1B4046 for ; Sat, 13 Aug 2011 18:49:32 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 9E90780048 for ; Sat, 13 Aug 2011 18:49:31 +0000 (UTC) From: "Michał Górny" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Michał Górny" Message-ID: Subject: [gentoo-commits] proj/gentoopm:master commit in: gentoopm/ X-VCS-Repository: proj/gentoopm X-VCS-Files: gentoopm/matchers.py X-VCS-Directories: gentoopm/ X-VCS-Committer: mgorny X-VCS-Committer-Name: Michał Górny X-VCS-Revision: f1c01cc80d50428705f09bb238ceb6c006a889dc Date: Sat, 13 Aug 2011 18:49:31 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: daf1479c909e2dff3165e59ea36ffa95 commit: f1c01cc80d50428705f09bb238ceb6c006a889dc Author: Micha=C5=82 G=C3=B3rny gentoo org> AuthorDate: Sat Aug 13 18:44:46 2011 +0000 Commit: Micha=C5=82 G=C3=B3rny gentoo org> CommitDate: Sat Aug 13 18:45:00 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/gentoopm.git;= a=3Dcommit;h=3Df1c01cc8 Support passing multiple values to Contains(). --- gentoopm/matchers.py | 31 ++++++++++++++++++++++++------- 1 files changed, 24 insertions(+), 7 deletions(-) diff --git a/gentoopm/matchers.py b/gentoopm/matchers.py index 52a005f..c0efe71 100644 --- a/gentoopm/matchers.py +++ b/gentoopm/matchers.py @@ -31,14 +31,31 @@ class Contains(PMKeywordMatcher): A keyword attribute matcher checking for list membership. """ =20 - def __init__(self, elem): - self._elem =3D elem + def __init__(self, *elems): + """ + Instantiate the matcher for arguments. If multiple arguments are passe= d + in, at least one of them must be contained in the value. + + @param elems: elements to match against the value contents + @type elems: any + """ + + self._simple_matchers =3D set() + self._complex_matchers =3D [] + for e in elems: + if isinstance(e, str): + self._simple_matchers.add(e) + else: + self._complex_matchers.append(e) =20 def __eq__(self, val): - if isinstance(self._elem, str): - return self._elem in val - else: + for n in self._simple_matchers: + if n in val: + return True + + for n in self._complex_matchers: for e in val: - if self._elem =3D=3D e: + if n =3D=3D e: return True - return False + + return False