summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-06-25 21:59:58 +0000
committerZac Medico <zmedico@gentoo.org>2009-06-25 21:59:58 +0000
commit6113aa2cd60a36ecd95bc379d0012bcb0c44ddfa (patch)
tree8e031960e3d2dbc210b905a5ec873955a33404e0
parent390f035e818552f29a0f2bb00b6c46dbecf85344 (diff)
downloadportage-6113aa2cd60a36ecd95bc379d0012bcb0c44ddfa.tar.gz
portage-6113aa2cd60a36ecd95bc379d0012bcb0c44ddfa.tar.bz2
portage-6113aa2cd60a36ecd95bc379d0012bcb0c44ddfa.zip
Use @property instead of __getattribute__ to implement lazy Package.iuse.regex
initialization. svn path=/main/trunk/; revision=13696
-rw-r--r--pym/_emerge/Package.py35
1 files changed, 20 insertions, 15 deletions
diff --git a/pym/_emerge/Package.py b/pym/_emerge/Package.py
index 1b8a90c8b..1d90975c7 100644
--- a/pym/_emerge/Package.py
+++ b/pym/_emerge/Package.py
@@ -72,7 +72,9 @@ class Package(Task):
class _iuse(object):
- __slots__ = ("__weakref__", "all", "enabled", "disabled", "iuse_implicit", "regex", "tokens")
+ __slots__ = ("__weakref__", "all", "enabled", "disabled",
+ "iuse_implicit", "tokens") + \
+ ('_regex',)
def __init__(self, tokens, iuse_implicit):
self.tokens = tuple(tokens)
@@ -92,20 +94,23 @@ class Package(Task):
self.disabled = frozenset(disabled)
self.all = frozenset(chain(enabled, disabled, other))
- def __getattribute__(self, name):
- if name == "regex":
- try:
- return object.__getattribute__(self, "regex")
- except AttributeError:
- all = object.__getattribute__(self, "all")
- iuse_implicit = object.__getattribute__(self, "iuse_implicit")
- # Escape anything except ".*" which is supposed
- # to pass through from _get_implicit_iuse()
- regex = (re.escape(x) for x in chain(all, iuse_implicit))
- regex = "^(%s)$" % "|".join(regex)
- regex = regex.replace("\\.\\*", ".*")
- self.regex = re.compile(regex)
- return object.__getattribute__(self, name)
+ @property
+ def regex(self):
+ """
+ @returns: A regular expression that matches valid USE values which
+ may be specified in USE dependencies.
+ """
+ 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
def _get_hash_key(self):
hash_key = getattr(self, "_hash_key", None)