Replace dict.keys() usage with __iter__(), since it behaves identically in
authorZac Medico <zmedico@gentoo.org>
Tue, 22 Sep 2009 21:37:53 +0000 (21:37 -0000)
committerZac Medico <zmedico@gentoo.org>
Tue, 22 Sep 2009 21:37:53 +0000 (21:37 -0000)
both python 2.x and 3.x.

svn path=/main/trunk/; revision=14385

pym/portage/getbinpkg.py
pym/portage/glsa.py
pym/portage/manifest.py
pym/portage/sets/base.py
pym/portage/sets/dbapi.py
pym/portage/sets/files.py
pym/portage/util.py

index 804015dbef72ddd004e4f842c1b13a509dd8ea97..69ae56fa53a9127bb9e0020c73295f609a97c286 100644 (file)
@@ -817,7 +817,7 @@ class PackageIndex(object):
                if self.modified:
                        self.header["TIMESTAMP"] = str(long(time.time()))
                        self.header["PACKAGES"] = str(len(self.packages))
-               keys = list(self.header.keys())
+               keys = list(self.header)
                keys.sort()
                self._writepkgindex(pkgfile, [(k, self.header[k]) \
                        for k in keys if self.header[k]])
@@ -834,7 +834,7 @@ class PackageIndex(object):
                                for k, v in self._default_pkg_data.items():
                                        if metadata.get(k) == v:
                                                metadata.pop(k, None)
-                       keys = list(metadata.keys())
+                       keys = list(metadata)
                        keys.sort()
                        self._writepkgindex(pkgfile,
                                [(k, metadata[k]) for k in keys if metadata[k]])
index 1f061b23108e8d22ffab013b6e7e2e2a7faba65a..4049efc2d7e6f18b6daafb4fdf6677c3bd744a81 100644 (file)
@@ -581,7 +581,7 @@ class Glsa:
                outstream.write(_("Announced on:      %s\n") % self.announced)
                outstream.write(_("Last revised on:   %s : %02d\n\n") % (self.revised, self.count))
                if self.glsatype == "ebuild":
-                       for k in self.packages.keys():
+                       for k in self.packages:
                                pkg = self.packages[k]
                                for path in pkg:
                                        vul_vers = "".join(path["vul_vers"])
@@ -626,7 +626,7 @@ class Glsa:
                @returns:       True if the system is affected, False if not
                """
                rValue = False
-               for k in self.packages.keys():
+               for k in self.packages:
                        pkg = self.packages[k]
                        for path in pkg:
                                if path["arch"] == "*" or self.config["ARCH"] in path["arch"].split():
@@ -679,7 +679,7 @@ class Glsa:
                @return:        list of package-versions that have to be merged
                """
                rValue = []
-               for pkg in self.packages.keys():
+               for pkg in self.packages:
                        for path in self.packages[pkg]:
                                update = getMinUpgrade(path["vul_atoms"], path["unaff_atoms"], \
                                        self.portdbapi, self.vardbapi, minimize=least_change)
index 7b20a3c2d56160637fd652f30191102eb26c115a..cb81b893328ec0810e0ecfa746dee24be176f85c 100644 (file)
@@ -74,7 +74,7 @@ class ManifestEntry(object):
 class Manifest2Entry(ManifestEntry):
        def __str__(self):
                myline = " ".join([self.type, self.name, str(self.hashes["size"])])
-               myhashkeys = list(self.hashes.keys())
+               myhashkeys = list(self.hashes)
                myhashkeys.remove("size")
                myhashkeys.sort()
                for h in myhashkeys:
@@ -202,15 +202,15 @@ class Manifest(object):
                return myhashdict
 
        def _createManifestEntries(self):
-               mytypes = list(self.fhashdict.keys())
+               mytypes = list(self.fhashdict)
                mytypes.sort()
                for t in mytypes:
-                       myfiles = list(self.fhashdict[t].keys())
+                       myfiles = list(self.fhashdict[t])
                        myfiles.sort()
                        for f in myfiles:
                                myentry = Manifest2Entry(
                                        type=t, name=f, hashes=self.fhashdict[t][f].copy())
-                               myhashkeys = list(myentry.hashes.keys())
+                               myhashkeys = list(myentry.hashes)
                                myhashkeys.sort()
                                for h in myhashkeys:
                                        if h not in ["size"] + portage.const.MANIFEST2_HASH_FUNCTIONS:
index 0c08ee1948b1a5f9a572e13859f7027017c219f4..d58b5f297be960cfca6c1c0a76d685f1a7d76be5 100644 (file)
@@ -126,7 +126,7 @@ class PackageSet(object):
                                rev_transform[atom] = atom
                        else:
                                rev_transform[Atom(atom.replace(atom.cp, pkg.cp, 1))] = atom
-               best_match = best_match_to_list(pkg, iter(rev_transform.keys()))
+               best_match = best_match_to_list(pkg, iter(rev_transform))
                if best_match:
                        return rev_transform[best_match]
                return None
index 06ebcadfd6cde3f065d2c470be1bcb0b28a9c074..f2e7dd1106d9528fd0b8597c8b4e70e5c1bc727e 100644 (file)
@@ -132,7 +132,7 @@ class VariableSet(EverythingSet):
                        raise SetConfigError(_("no includes or excludes given"))
                
                metadatadb = options.get("metadata-source", "vartree")
-               if not metadatadb in trees.keys():
+               if not metadatadb in trees:
                        raise SetConfigError(_("invalid value '%s' for option metadata-source") % metadatadb)
 
                return cls(trees["vartree"].dbapi,
index 8a7e4d84d3db46636725b15e482d4cc98f68af80..e8650becdd3ce4d341d80b493921a50637f27bc4 100644 (file)
@@ -84,7 +84,7 @@ class StaticFileSet(EditablePackageSet):
                                data = {}
                        if self.greedy:
                                atoms = []
-                               for a in data.keys():
+                               for a in data:
                                        matches = self.dbapi.match(a)
                                        for cpv in matches:
                                                atoms.append("%s:%s" % (cpv_getkey(cpv),
@@ -93,7 +93,7 @@ class StaticFileSet(EditablePackageSet):
                                        # in the latest new slot that may be available.
                                        atoms.append(a)
                        else:
-                               atoms = list(data.keys())
+                               atoms = iter(data)
                        self._setAtoms(atoms)
                        self._mtime = mtime
                
@@ -183,7 +183,7 @@ class ConfigFileSet(PackageSet):
 
        def load(self):
                data, errors = self.loader.load()
-               self._setAtoms(list(data.keys()))
+               self._setAtoms(iter(data))
        
        def singleBuilder(self, options, settings, trees):
                if not "filename" in options:
@@ -254,7 +254,7 @@ class WorldSet(EditablePackageSet):
                                        raise
                                del e
                                data = {}
-                       atoms = list(data.keys())
+                       atoms = list(data)
                        self._mtime = mtime
                        atoms_changed = True
                else:
@@ -274,7 +274,7 @@ class WorldSet(EditablePackageSet):
                                        raise
                                del e
                                data = {}
-                       nonatoms = list(data.keys())
+                       nonatoms = list(data)
                        self._mtime2 = mtime
                        atoms_changed = True
                else:
index ab70fd5c47a7eab4faab2e5cca3efac111df29f2..28d4e626c63f706f77c78cdf651a99a2091e3988 100644 (file)
@@ -225,13 +225,12 @@ def stack_dicts(dicts, incremental=0, incrementals=[], ignore_none=0):
                                return None
                if final_dict is None:
                        final_dict = {}
-               for y in list(mydict.keys()):
+               for y in mydict:
                        if True:
                                if y in final_dict and (incremental or (y in incrementals)):
                                        final_dict[y] += " "+mydict[y][:]
                                else:
                                        final_dict[y]  = mydict[y][:]
-                       mydict[y] = " ".join(mydict[y].split()) # Remove extra spaces.
        return final_dict
 
 def stack_lists(lists, incremental=1):
@@ -252,7 +251,7 @@ def stack_lists(lists, incremental=1):
                                        new_list[y] = True
                        else:
                                new_list[y] = True
-       return list(new_list.keys())
+       return list(new_list)
 
 def grabdict(myfilename, juststrings=0, empty=0, recursive=0, incremental=1):
        """