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 1Qry1O-0006Vf-I4 for garchives@archives.gentoo.org; Fri, 12 Aug 2011 20:08:00 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id C7F6321C06A; Fri, 12 Aug 2011 20:07:43 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 9C34421C06A for ; Fri, 12 Aug 2011 20:07:43 +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 372041B4046 for ; Fri, 12 Aug 2011 20:07:43 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 8C2DC80040 for ; Fri, 12 Aug 2011 20:07:42 +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: <40bbcf283f9d968b815c1f539e546c1cdfa98a40.mgorny@gentoo> 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: 40bbcf283f9d968b815c1f539e546c1cdfa98a40 Date: Fri, 12 Aug 2011 20:07:42 +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: 766d4b3facca4e900393a4e60fe0582a commit: 40bbcf283f9d968b815c1f539e546c1cdfa98a40 Author: Micha=C5=82 G=C3=B3rny gentoo org> AuthorDate: Fri Aug 12 19:56:59 2011 +0000 Commit: Micha=C5=82 G=C3=B3rny gentoo org> CommitDate: Fri Aug 12 20:03:25 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/gentoopm.git;= a=3Dcommit;h=3D40bbcf28 Add two keyword matchers for kwargs. --- gentoopm/matchers.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 44 insertions(+), 0 deletions(-) diff --git a/gentoopm/matchers.py b/gentoopm/matchers.py new file mode 100644 index 0000000..c3401b1 --- /dev/null +++ b/gentoopm/matchers.py @@ -0,0 +1,44 @@ +#!/usr/bin/python +# vim:fileencoding=3Dutf-8 +# (c) 2011 Micha=C5=82 G=C3=B3rny +# Released under the terms of the 2-clause BSD license. + +from .basepm.filter import PMKeywordMatcher + +import re + +class RegExp(PMKeywordMatcher): + """ + A keyword attribute matcher using a regular expression. + """ + + def __init__(self, regexp): + """ + Instantiate the regexp matcher. + + @param re: a regular expression to match values against + @type re: string/compiled regexp + """ + if not hasattr(regexp, 'match'): + regexp =3D re.compile(regexp) + self._re =3D regexp + + def __eq__(self, val): + return bool(self._re.match(str(val))) + +class Contains(PMKeywordMatcher): + """ + A keyword attribute matcher checking for list membership. + """ + + def __init__(self, elem): + self._elem =3D elem + + def __eq__(self, val): + if isinstance(self._elem, str): + return self._elem in val + else: + for e in val: + if self._elem =3D=3D e: + return True + return False