diff options
author | Zac Medico <zmedico@gentoo.org> | 2008-11-05 23:55:17 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2008-11-05 23:55:17 +0000 |
commit | 866b553f115237a1c0312722e842a2840efe0a05 (patch) | |
tree | faf081abce3e91145176342859d2f18ec9bcbaa7 | |
parent | 4ca862e20fd6d912ae400943893071c62b7f62e7 (diff) | |
download | portage-866b553f115237a1c0312722e842a2840efe0a05.tar.gz portage-866b553f115237a1c0312722e842a2840efe0a05.tar.bz2 portage-866b553f115237a1c0312722e842a2840efe0a05.zip |
Override Atom.__setattr__() to make Atom instances immutable. Thanks to Brian
Harring for the suggestion.
svn path=/main/trunk/; revision=11812
-rw-r--r-- | pym/portage/dep.py | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/pym/portage/dep.py b/pym/portage/dep.py index fc6a8b10e..bcfe63c45 100644 --- a/pym/portage/dep.py +++ b/pym/portage/dep.py @@ -529,29 +529,32 @@ class Atom(object): def __init__(self, s): if not isvalidatom(s, allow_blockers=True): raise InvalidAtom(s) + obj_setattr = object.__setattr__ for x in self._str_methods: - setattr(self, x, getattr(s, x)) + obj_setattr(self, x, getattr(s, x)) blocker = "!" == s[:1] if blocker: - self.blocker = self._blocker(forbid_overlap=("!" == s[1:2])) - if self.blocker.overlap.forbid: + blocker = self._blocker(forbid_overlap=("!" == s[1:2])) + if blocker.overlap.forbid: s = s[2:] else: s = s[1:] else: - self.blocker = False - - self.cp = dep_getkey(s) - self.cpv = dep_getcpv(s) - self.slot = dep_getslot(s) - self.operator = get_operator(s) - #self.repo = self._get_repo(s) - self.use = dep_getusedeps(s) - if self.use: - self.use = _use_dep(self.use) + blocker = False + obj_setattr(self, "blocker", blocker) + + obj_setattr(self, "cp", dep_getkey(s)) + obj_setattr(self, "cpv", dep_getcpv(s)) + obj_setattr(self, "slot", dep_getslot(s)) + obj_setattr(self, "operator", get_operator(s)) + + use = dep_getusedeps(s) + if use: + use = _use_dep(use) else: - self.use = None + use = None + obj_setattr(self, "use", use) def __cmp__(self, other): self_str = str(self) @@ -562,6 +565,9 @@ class Atom(object): return 1 return -1 + def __setattr__(self, name, value): + raise AttributeError("Atom instances are immutable") + def get_operator(mydep): """ Return the operator used in a depstring. |