From: Zac Medico Date: Wed, 5 Nov 2008 23:55:17 +0000 (-0000) Subject: Override Atom.__setattr__() to make Atom instances immutable. Thanks to Brian X-Git-Tag: v2.2_rc14~46 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=866b553f115237a1c0312722e842a2840efe0a05;p=portage.git Override Atom.__setattr__() to make Atom instances immutable. Thanks to Brian Harring for the suggestion. svn path=/main/trunk/; revision=11812 --- 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.