From: Zac Medico Date: Tue, 22 Sep 2009 21:37:53 +0000 (-0000) Subject: Replace dict.keys() usage with __iter__(), since it behaves identically in X-Git-Tag: v2.2_rc42~39 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=e0acff3dfd020c99538a58e799ccfdc0f9e957a3;p=portage.git Replace dict.keys() usage with __iter__(), since it behaves identically in both python 2.x and 3.x. svn path=/main/trunk/; revision=14385 --- diff --git a/pym/portage/getbinpkg.py b/pym/portage/getbinpkg.py index 804015dbe..69ae56fa5 100644 --- a/pym/portage/getbinpkg.py +++ b/pym/portage/getbinpkg.py @@ -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]]) diff --git a/pym/portage/glsa.py b/pym/portage/glsa.py index 1f061b231..4049efc2d 100644 --- a/pym/portage/glsa.py +++ b/pym/portage/glsa.py @@ -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) diff --git a/pym/portage/manifest.py b/pym/portage/manifest.py index 7b20a3c2d..cb81b8933 100644 --- a/pym/portage/manifest.py +++ b/pym/portage/manifest.py @@ -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: diff --git a/pym/portage/sets/base.py b/pym/portage/sets/base.py index 0c08ee194..d58b5f297 100644 --- a/pym/portage/sets/base.py +++ b/pym/portage/sets/base.py @@ -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 diff --git a/pym/portage/sets/dbapi.py b/pym/portage/sets/dbapi.py index 06ebcadfd..f2e7dd110 100644 --- a/pym/portage/sets/dbapi.py +++ b/pym/portage/sets/dbapi.py @@ -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, diff --git a/pym/portage/sets/files.py b/pym/portage/sets/files.py index 8a7e4d84d..e8650becd 100644 --- a/pym/portage/sets/files.py +++ b/pym/portage/sets/files.py @@ -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: diff --git a/pym/portage/util.py b/pym/portage/util.py index ab70fd5c4..28d4e626c 100644 --- a/pym/portage/util.py +++ b/pym/portage/util.py @@ -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): """