summaryrefslogtreecommitdiffstats
path: root/pym
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2008-04-27 07:22:58 +0000
committerZac Medico <zmedico@gentoo.org>2008-04-27 07:22:58 +0000
commit63bb2a13e9543eb694e92150142a8dc85394cd89 (patch)
tree13eeb45babede1a2ad59123b260f5bf49def9cda /pym
parent7900ba47dbc933248a355967fb3e7debb5c079dd (diff)
downloadportage-63bb2a13e9543eb694e92150142a8dc85394cd89.tar.gz
portage-63bb2a13e9543eb694e92150142a8dc85394cd89.tar.bz2
portage-63bb2a13e9543eb694e92150142a8dc85394cd89.zip
Take the classes that initialize variables in __slots__ with keyword
constructor arguments and make them all derive from a new SlotObject class. svn path=/main/trunk/; revision=9994
Diffstat (limited to 'pym')
-rw-r--r--pym/_emerge/__init__.py73
1 files changed, 31 insertions, 42 deletions
diff --git a/pym/_emerge/__init__.py b/pym/_emerge/__init__.py
index 7e8308a9a..c3c4a896a 100644
--- a/pym/_emerge/__init__.py
+++ b/pym/_emerge/__init__.py
@@ -829,14 +829,25 @@ def filter_iuse_defaults(iuse):
else:
yield flag
-class AbstractDepPriority(object):
- __slots__ = ("__weakref__", "buildtime", "runtime", "runtime_post")
+class SlotObject(object):
+ __slots__ = ("__weakref__")
+
def __init__(self, **kwargs):
- for myattr in chain(self.__slots__, AbstractDepPriority.__slots__):
- if myattr == "__weakref__":
+ classes = [self.__class__]
+ while classes:
+ c = classes.pop()
+ if c is SlotObject:
+ continue
+ classes.extend(c.__bases__)
+ slots = getattr(c, "__slots__", None)
+ if not slots:
continue
- myvalue = kwargs.get(myattr, False)
- setattr(self, myattr, myvalue)
+ for myattr in slots:
+ myvalue = kwargs.get(myattr, None)
+ setattr(self, myattr, myvalue)
+
+class AbstractDepPriority(SlotObject):
+ __slots__ = ("buildtime", "runtime", "runtime_post")
def __lt__(self, other):
return self.__int__() < other
@@ -1207,28 +1218,14 @@ def show_masked_packages(masked_packages):
shown_licenses.add(l)
return have_eapi_mask
-class Task(object):
- __slots__ = ("__weakref__", "_hash_key",)
-
- def __init__(self, **kwargs):
- classes = [self.__class__]
- while classes:
- c = classes.pop()
- if c is Task:
- continue
- classes.extend(c.__bases__)
- slots = getattr(c, "__slots__", None)
- if not slots:
- continue
- for myattr in slots:
- myvalue = kwargs.get(myattr, None)
- setattr(self, myattr, myvalue)
+class Task(SlotObject):
+ __slots__ = ("_hash_key",)
def _get_hash_key(self):
- try:
- return self._hash_key
- except AttributeError:
+ hash_key = getattr(self, "_hash_key", None)
+ if hash_key is None:
raise NotImplementedError(self)
+ return hash_key
def __eq__(self, other):
return self._get_hash_key() == other
@@ -1258,9 +1255,8 @@ class Blocker(Task):
__slots__ = ("root", "atom", "satisfied")
def _get_hash_key(self):
- try:
- return self._hash_key
- except AttributeError:
+ hash_key = getattr(self, "_hash_key", None)
+ if hash_key is None:
self._hash_key = \
("blocks", self.root, self.atom)
return self._hash_key
@@ -1276,9 +1272,8 @@ class Package(Task):
self.cpv_slot = "%s:%s" % (self.cpv, self.metadata["SLOT"])
def _get_hash_key(self):
- try:
- return self._hash_key
- except AttributeError:
+ hash_key = getattr(self, "_hash_key", None)
+ if hash_key is None:
operation = "merge"
if self.onlydeps or self.installed:
operation = "nomerge"
@@ -1307,9 +1302,8 @@ class Package(Task):
class Uninstall(Package):
__slots__ = ()
def _get_hash_key(self):
- try:
- return self._hash_key
- except AttributeError:
+ hash_key = getattr(self, "_hash_key", None)
+ if hash_key is None:
self._hash_key = \
(self.type_name, self.root, self.cpv, "uninstall")
return self._hash_key
@@ -1341,16 +1335,11 @@ class SetArg(DependencyArg):
self.set = set
self.name = self.arg[len(SETPREFIX):]
-class Dependency(object):
- __slots__ = ("__weakref__", "atom", "blocker", "depth",
+class Dependency(SlotObject):
+ __slots__ = ("atom", "blocker", "depth",
"parent", "onlydeps", "priority", "root")
def __init__(self, **kwargs):
- for myattr in self.__slots__:
- if myattr == "__weakref__":
- continue
- myvalue = kwargs.get(myattr, None)
- setattr(self, myattr, myvalue)
-
+ SlotObject.__init__(self, **kwargs)
if self.priority is None:
self.priority = DepPriority()
if self.depth is None: