summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2007-06-21 21:37:25 +0000
committerZac Medico <zmedico@gentoo.org>2007-06-21 21:37:25 +0000
commit1d3954d9fb6c47fad9177fff5bd9a31981ac013d (patch)
treeee69aec524a07609e39deb3d19846902b85f888b
parentac67750451afe6c33d75553906839b28c9077230 (diff)
downloadportage-1d3954d9fb6c47fad9177fff5bd9a31981ac013d.tar.gz
portage-1d3954d9fb6c47fad9177fff5bd9a31981ac013d.tar.bz2
portage-1d3954d9fb6c47fad9177fff5bd9a31981ac013d.zip
Clean up config.__getitem__(), get() and setdefault() implementions.
svn path=/main/trunk/; revision=6920
-rw-r--r--pym/portage/__init__.py29
1 files changed, 13 insertions, 16 deletions
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
index bfc6f0839..6a4564ba5 100644
--- a/pym/portage/__init__.py
+++ b/pym/portage/__init__.py
@@ -2192,14 +2192,16 @@ class config(object):
del x[mykey]
def __getitem__(self,mykey):
- match = ''
- for x in self.lookuplist:
- if x is None:
- writemsg("!!! lookuplist is null.\n")
- elif x.has_key(mykey):
- match = x[mykey]
- break
- return match
+ for d in self.lookuplist:
+ if mykey in d:
+ return d[mykey]
+ return '' # for backward compat, don't raise KeyError
+
+ def get(self, k, x=None):
+ for d in self.lookuplist:
+ if k in d:
+ return d[k]
+ return x
def has_key(self,mykey):
return mykey in self
@@ -2212,18 +2214,13 @@ class config(object):
return False
def setdefault(self, k, x=None):
- if k in self:
- return self[k]
+ v = self.get(k)
+ if v is not None:
+ return v
else:
self[k] = x
return x
- def get(self, k, x=None):
- if k in self:
- return self[k]
- else:
- return x
-
def keys(self):
return list(self)