config class mapping interface cleanups from trunk r6916, r6919, and r6920.
authorZac Medico <zmedico@gentoo.org>
Fri, 22 Jun 2007 02:45:18 +0000 (02:45 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 22 Jun 2007 02:45:18 +0000 (02:45 -0000)
svn path=/main/branches/2.1.2/; revision=6933

pym/portage.py

index 44451269d1480a5db94160d2e434020ec22170b2..5369619d282f276a2ca064700c980f25e9444411 100644 (file)
@@ -2144,49 +2144,46 @@ class config:
                                        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):
-               for x in self.lookuplist:
-                       if x.has_key(mykey):
-                               return 1
-               return 0
+               return mykey in self
 
        def __contains__(self, mykey):
                """Called to implement membership test operators (in and not in)."""
-               return bool(self.has_key(mykey))
+               for d in self.lookuplist:
+                       if mykey in d:
+                               return True
+               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)
 
        def __iter__(self):
                keys = set()
                for d in self.lookuplist:
-                       for k in d:
-                               if k in keys:
-                                       continue
-                               keys.add(k)
-                               yield k
+                       keys.update(d)
+               return iter(keys)
+
+       def iterkeys(self):
+               return iter(self)
 
        def __setitem__(self,mykey,myvalue):
                "set a value; will be thrown away at reset() time"