Gentoo Archives: gentoo-commits

From: "Zac Medico (zmedico)" <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] portage r10740 - main/trunk/pym/portage
Date: Fri, 20 Jun 2008 14:37:55
Message-Id: E1K9hkM-0002jd-2V@stork.gentoo.org
1 Author: zmedico
2 Date: 2008-06-20 14:37:49 +0000 (Fri, 20 Jun 2008)
3 New Revision: 10740
4
5 Modified:
6 main/trunk/pym/portage/dep.py
7 Log:
8 Instead of having Atom inherit from str, just emulate the interface. This
9 allows us to define __slots__ (not allowed when inheriting from str) and
10 therefore should conserve some memory by avoiding a __dict__ attribute
11 on every Atom.
12
13
14 Modified: main/trunk/pym/portage/dep.py
15 ===================================================================
16 --- main/trunk/pym/portage/dep.py 2008-06-20 13:39:14 UTC (rev 10739)
17 +++ main/trunk/pym/portage/dep.py 2008-06-20 14:37:49 UTC (rev 10740)
18 @@ -392,12 +392,25 @@
19 tokens.extend(self.conditional_disabled.difference(use))
20 return _use_dep(tokens)
21
22 -class Atom(str):
23 +class Atom(object):
24
25 + """
26 + For compatibility with existing atom string manipulation code, this
27 + class emulates most of the str methods that are useful with atoms.
28 + """
29 +
30 + _str_methods = ("endswith", "find", "index", "lstrip", "replace",
31 + "startswith", "strip", "rindex", "rfind", "rstrip", "__getitem__",
32 + "__len__", "__repr__", "__str__")
33 +
34 + __slots__ = ("__weakref__", "blocker", "cp", "cpv", "operator",
35 + "slot", "string", "use") + _str_methods
36 +
37 def __init__(self, s):
38 - str.__init__(self, s)
39 if not isvalidatom(s, allow_blockers=True):
40 raise InvalidAtom(s)
41 + for x in self._str_methods:
42 + setattr(self, x, getattr(s, x))
43 self.blocker = "!" == s[:1]
44 if self.blocker:
45 s = s[1:]
46
47 --
48 gentoo-commits@l.g.o mailing list