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 1Sdp4t-00053j-Qs for garchives@archives.gentoo.org; Sun, 10 Jun 2012 20:49:40 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 1A27FE001F; Sun, 10 Jun 2012 20:49:03 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id C6AC1E0675 for ; Sun, 10 Jun 2012 20:48:57 +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 0DFE61B4040 for ; Sun, 10 Jun 2012 20:48:57 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id C6C4CE542E for ; Sun, 10 Jun 2012 20:48:55 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1339361304.ff8d4c0fe3c91ae739e3e6518e90c0e8b0fe35d0.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/dep/ X-VCS-Repository: proj/portage X-VCS-Files: pym/portage/dep/__init__.py X-VCS-Directories: pym/portage/dep/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: ff8d4c0fe3c91ae739e3e6518e90c0e8b0fe35d0 X-VCS-Branch: master Date: Sun, 10 Jun 2012 20:48:55 +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: 16af938a-5dc4-476f-90e7-f68975f0d0a9 X-Archives-Hash: c09f3101ab936a66ce0f1d0ae46713d8 commit: ff8d4c0fe3c91ae739e3e6518e90c0e8b0fe35d0 Author: Zac Medico gentoo org> AuthorDate: Sun Jun 10 20:48:24 2012 +0000 Commit: Zac Medico gentoo org> CommitDate: Sun Jun 10 20:48:24 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/portage.git;a= =3Dcommit;h=3Dff8d4c0f _get_atom_re: handle many combinations A namedtuple of _eapi_attrs is used to hash atom regular expressions, making it easy to handle many different combinations, as will be necessary for the addition of new features such as abi-slot deps. --- pym/portage/dep/__init__.py | 62 +++++++++++++++++++++++++++++--------= ----- 1 files changed, 43 insertions(+), 19 deletions(-) diff --git a/pym/portage/dep/__init__.py b/pym/portage/dep/__init__.py index ade3a73..66ff1e9 100644 --- a/pym/portage/dep/__init__.py +++ b/pym/portage/dep/__init__.py @@ -27,6 +27,7 @@ __all__ =3D [ # "a? ( b? ( z ) ) -- Valid # =20 +import collections import re, sys import warnings from itertools import chain @@ -54,6 +55,48 @@ if sys.hexversion >=3D 0x3000000: # stable keywords, make these warnings unconditional. _internal_warnings =3D False =20 +_eapi_attrs =3D collections.namedtuple('_eapi_attrs', + 'dots_in_PN') + +_eapi_attrs_cache =3D {} + +def _get_eapi_attrs(eapi): + eapi_attrs =3D _eapi_attrs_cache.get(eapi) + if eapi_attrs is not None: + return eapi_attrs + + eapi_attrs =3D _eapi_attrs( + dots_in_PN =3D (eapi is None or eapi_allows_dots_in_PN(eapi)) + ) + + _eapi_attrs_cache[eapi] =3D eapi_attrs + return eapi_attrs + +_atom_re_cache =3D {} + +def _get_atom_re(eapi): + eapi_attrs =3D _get_eapi_attrs(eapi) + atom_re =3D _atom_re_cache.get(eapi_attrs) + if atom_re is not None: + return atom_re + + if eapi_attrs.dots_in_PN: + cp_re =3D _cp['dots_allowed_in_PN'] + cpv_re =3D _cpv['dots_allowed_in_PN'] + else: + cp_re =3D _cp['dots_disallowed_in_PN'] + cpv_re =3D _cpv['dots_disallowed_in_PN'] + + atom_re =3D re.compile('^(?P(?:' + + '(?P' + _op + cpv_re + ')|' + + '(?P=3D' + cpv_re + r'\*)|' + + '(?P' + cp_re + '))' +=20 + '(' + _slot_separator + _slot + ')?' + + _repo + ')(' + _use + ')?$', re.VERBOSE) + + _atom_re_cache[eapi_attrs] =3D atom_re + return atom_re + def cpvequal(cpv1, cpv2): """ =09 @@ -1666,25 +1709,6 @@ _repo_separator =3D "::" _repo_name =3D r'[\w][\w-]*' _repo =3D r'(?:' + _repo_separator + '(' + _repo_name + ')' + ')?' =20 -_atom_re =3D { - "dots_disallowed_in_PN": re.compile('^(?P(?:' + - '(?P' + _op + _cpv['dots_disallowed_in_PN'] + ')|' + - '(?P=3D' + _cpv['dots_disallowed_in_PN'] + r'\*)|' + - '(?P' + _cp['dots_disallowed_in_PN'] + '))' +=20 - '(' + _slot_separator + _slot + ')?' + _repo + ')(' + _use + ')?$', re= .VERBOSE), - "dots_allowed_in_PN": re.compile('^(?P(?:' + - '(?P' + _op + _cpv['dots_allowed_in_PN'] + ')|' + - '(?P=3D' + _cpv['dots_allowed_in_PN'] + r'\*)|' + - '(?P' + _cp['dots_allowed_in_PN'] + '))' +=20 - '(' + _slot_separator + _slot + ')?' + _repo + ')(' + _use + ')?$', re= .VERBOSE), -} - -def _get_atom_re(eapi): - if eapi is None or eapi_allows_dots_in_PN(eapi): - return _atom_re["dots_allowed_in_PN"] - else: - return _atom_re["dots_disallowed_in_PN"] -=09 _extended_cat =3D r'[\w+*][\w+.*-]*' _extended_pkg =3D { "dots_disallowed_in_PN": r'[\w+*][\w+*-]*?',