summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2010-04-27 20:56:36 -0700
committerZac Medico <zmedico@gentoo.org>2010-04-27 20:56:36 -0700
commitc260933b121be4478b0e1b5a50d1862a7860fd0e (patch)
tree6a9b05a696e3d213042be7e32151e3409231bbe5
parent3002478e1906336cdd683826771cd485a3a9f66c (diff)
downloadportage-c260933b121be4478b0e1b5a50d1862a7860fd0e.tar.gz
portage-c260933b121be4478b0e1b5a50d1862a7860fd0e.tar.bz2
portage-c260933b121be4478b0e1b5a50d1862a7860fd0e.zip
Add a Package.iuse.is_valid_flag() method to replace the regex attribute,
in order to avoid compiling regex for each Package instance.
-rw-r--r--pym/_emerge/Package.py29
-rw-r--r--pym/portage/dep/__init__.py4
2 files changed, 11 insertions, 22 deletions
diff --git a/pym/_emerge/Package.py b/pym/_emerge/Package.py
index bce4e6cbe..8e0c37890 100644
--- a/pym/_emerge/Package.py
+++ b/pym/_emerge/Package.py
@@ -153,12 +153,11 @@ class Package(Task):
class _iuse(object):
__slots__ = ("__weakref__", "all", "enabled", "disabled",
- "iuse_implicit", "tokens") + \
- ('_regex',)
+ "tokens") + ("_iuse_implicit_regex",)
- def __init__(self, tokens, iuse_implicit):
+ def __init__(self, tokens, iuse_implicit_regex):
self.tokens = tuple(tokens)
- self.iuse_implicit = iuse_implicit
+ self._iuse_implicit_regex = iuse_implicit_regex
enabled = []
disabled = []
other = []
@@ -174,23 +173,13 @@ class Package(Task):
self.disabled = frozenset(disabled)
self.all = frozenset(chain(enabled, disabled, other))
- @property
- def regex(self):
+ def is_valid_flag(self, flag):
"""
- @returns: A regular expression that matches valid USE values which
- may be specified in USE dependencies.
+ @returns: True if flag is a valid USE value which may
+ be specified in USE dependencies, False otherwise.
"""
- try:
- return self._regex
- except AttributeError:
- # Escape anything except ".*" which is supposed
- # to pass through from _get_implicit_iuse()
- regex = (re.escape(x) for x in \
- chain(self.all, self.iuse_implicit))
- regex = "^(%s)$" % "|".join(regex)
- regex = re.compile(regex.replace("\\.\\*", ".*"))
- self._regex = regex
- return regex
+ return flag in self.all or \
+ self._iuse_implicit_regex.match(flag) is not None
def _get_hash_key(self):
hash_key = getattr(self, "_hash_key", None)
@@ -306,7 +295,7 @@ class _PackageMetadataWrapper(_PackageMetadataWrapperBase):
def _set_iuse(self, k, v):
self._pkg.iuse = self._pkg._iuse(
- v.split(), self._pkg.root_config.iuse_implicit)
+ v.split(), self._pkg.root_config.settings._iuse_implicit_re)
def _set_slot(self, k, v):
self._pkg.slot = v
diff --git a/pym/portage/dep/__init__.py b/pym/portage/dep/__init__.py
index abe5a0666..341953930 100644
--- a/pym/portage/dep/__init__.py
+++ b/pym/portage/dep/__init__.py
@@ -1185,10 +1185,10 @@ def match_from_list(mydep, candidate_list):
for x in candidate_list:
use = getattr(x, "use", None)
if use is not None:
- regex = x.iuse.regex
+ is_valid_flag = x.iuse.is_valid_flag
missing_iuse = False
for y in mydep.use.required:
- if regex.match(y) is None:
+ if not is_valid_flag(y):
missing_iuse = True
break
if missing_iuse: