* [gentoo-commits] portage r10740 - main/trunk/pym/portage
@ 2008-06-20 14:37 Zac Medico (zmedico)
0 siblings, 0 replies; only message in thread
From: Zac Medico (zmedico) @ 2008-06-20 14:37 UTC (permalink / raw
To: gentoo-commits
Author: zmedico
Date: 2008-06-20 14:37:49 +0000 (Fri, 20 Jun 2008)
New Revision: 10740
Modified:
main/trunk/pym/portage/dep.py
Log:
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.
Modified: main/trunk/pym/portage/dep.py
===================================================================
--- main/trunk/pym/portage/dep.py 2008-06-20 13:39:14 UTC (rev 10739)
+++ main/trunk/pym/portage/dep.py 2008-06-20 14:37:49 UTC (rev 10740)
@@ -392,12 +392,25 @@
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:]
--
gentoo-commits@lists.gentoo.org mailing list
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2008-06-20 14:37 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-20 14:37 [gentoo-commits] portage r10740 - main/trunk/pym/portage Zac Medico (zmedico)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox