diff options
author | Zac Medico <zmedico@gentoo.org> | 2008-06-20 14:37:49 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2008-06-20 14:37:49 +0000 |
commit | 36a91804330dca702f9d924bfa2ca98c00deb7c6 (patch) | |
tree | 4619ff8be322dd4aa5b3d1e2139a149193b24e9c | |
parent | 860d9f6c5567fca195e214f6b9a3aa365cd8406a (diff) | |
download | portage-36a91804330dca702f9d924bfa2ca98c00deb7c6.tar.gz portage-36a91804330dca702f9d924bfa2ca98c00deb7c6.tar.bz2 portage-36a91804330dca702f9d924bfa2ca98c00deb7c6.zip |
Instead of having Atom inherit from str, just emulate the interface. This
allows us to define __slots__ (not allowed when inheriting from str) and
therefore should conserve some memory by avoiding a __dict__ attribute
on every Atom.
svn path=/main/trunk/; revision=10740
-rw-r--r-- | pym/portage/dep.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/pym/portage/dep.py b/pym/portage/dep.py index df6bdfd3e..03f428495 100644 --- a/pym/portage/dep.py +++ b/pym/portage/dep.py @@ -392,12 +392,25 @@ class _use_dep(object): tokens.extend(self.conditional_disabled.difference(use)) return _use_dep(tokens) -class Atom(str): +class Atom(object): + + """ + For compatibility with existing atom string manipulation code, this + class emulates most of the str methods that are useful with atoms. + """ + + _str_methods = ("endswith", "find", "index", "lstrip", "replace", + "startswith", "strip", "rindex", "rfind", "rstrip", "__getitem__", + "__len__", "__repr__", "__str__") + + __slots__ = ("__weakref__", "blocker", "cp", "cpv", "operator", + "slot", "string", "use") + _str_methods def __init__(self, s): - str.__init__(self, s) if not isvalidatom(s, allow_blockers=True): raise InvalidAtom(s) + for x in self._str_methods: + setattr(self, x, getattr(s, x)) self.blocker = "!" == s[:1] if self.blocker: s = s[1:] |