Use dict iteration methods common to both Python 2 and 3.

The .items, .keys, and .values methods in Python 2 make copies, so the
test framework uses the .iter* flavors of those methods. But in Python
3 those .iter* (and even the 2.7 .view*) flavors are removed and the
original methods return views.

Measurements were taken under Python2 to see what impact the copying
had, and there was none. Thus it is not worth the effort to avoid.

Reported as a compatibility issue by 2to3.

Signed-off-by: Jeremy Heiner <ScalaProtractor at gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Jeremy Heiner 2013-10-12 12:44:33 -04:00 committed by Allan McRae
parent 071ba05534
commit 95b0a868f2
4 changed files with 9 additions and 9 deletions

View file

@ -236,7 +236,7 @@ class pmdb(object):
for pkg, entry in pkg_entries: for pkg, entry in pkg_entries:
path = os.path.join(self.dbdir, pkg.fullname()) path = os.path.join(self.dbdir, pkg.fullname())
util.mkdir(path) util.mkdir(path)
for name, data in entry.iteritems(): for name, data in entry.items():
util.mkfile(path, name, data) util.mkfile(path, name, data)
if self.dbfile: if self.dbfile:
@ -247,7 +247,7 @@ class pmdb(object):
info = tarfile.TarInfo(pkg.fullname()) info = tarfile.TarInfo(pkg.fullname())
info.type = tarfile.DIRTYPE info.type = tarfile.DIRTYPE
tar.addfile(info) tar.addfile(info)
for name, data in entry.iteritems(): for name, data in entry.items():
filename = os.path.join(pkg.fullname(), name) filename = os.path.join(pkg.fullname(), name)
info = tarfile.TarInfo(filename) info = tarfile.TarInfo(filename)
info.size = len(data) info.size = len(data)

View file

@ -223,7 +223,7 @@ class pmpkg(object):
def installfile(self): def installfile(self):
data = [] data = []
for key, value in self.install.iteritems(): for key, value in self.install.items():
if value: if value:
data.append("%s() {\n%s\n}\n" % (key, value)) data.append("%s() {\n%s\n}\n" % (key, value))

View file

@ -58,7 +58,7 @@ class pmtest(object):
"""Find a package object matching the name and version specified in """Find a package object matching the name and version specified in
either sync databases or the local package collection. The local database either sync databases or the local package collection. The local database
is allowed to match if allow_local is True.""" is allowed to match if allow_local is True."""
for db in self.db.itervalues(): for db in self.db.values():
if db.is_local and not allow_local: if db.is_local and not allow_local:
continue continue
pkg = db.getpkg(name) pkg = db.getpkg(name)
@ -151,7 +151,7 @@ class pmtest(object):
vprint("\t%s" % os.path.join(util.TMPDIR, pkg.filename())) vprint("\t%s" % os.path.join(util.TMPDIR, pkg.filename()))
pkg.finalize() pkg.finalize()
pkg.makepkg(tmpdir) pkg.makepkg(tmpdir)
for key, value in self.db.iteritems(): for key, value in self.db.items():
for pkg in value.pkgs: for pkg in value.pkgs:
pkg.finalize() pkg.finalize()
if key == "local" and not self.createlocalpkgs: if key == "local" and not self.createlocalpkgs:
@ -167,7 +167,7 @@ class pmtest(object):
# Creating sync database archives # Creating sync database archives
vprint(" Creating databases") vprint(" Creating databases")
for key, value in self.db.iteritems(): for key, value in self.db.items():
vprint("\t" + value.treename) vprint("\t" + value.treename)
value.generate() value.generate()

View file

@ -112,13 +112,13 @@ def writedata(filename, data):
def mkcfgfile(filename, root, option, db): def mkcfgfile(filename, root, option, db):
# Options # Options
data = ["[options]"] data = ["[options]"]
for key, value in option.iteritems(): for key, value in option.items():
data.extend(["%s = %s" % (key, j) for j in value]) data.extend(["%s = %s" % (key, j) for j in value])
# Repositories # Repositories
# sort by repo name so tests can predict repo order, rather than be # sort by repo name so tests can predict repo order, rather than be
# subjects to the whims of python dict() ordering # subjects to the whims of python dict() ordering
for key in sorted(db.iterkeys()): for key in sorted(db.keys()):
if key != "local": if key != "local":
value = db[key] value = db[key]
data.append("[%s]\n" \ data.append("[%s]\n" \
@ -126,7 +126,7 @@ def mkcfgfile(filename, root, option, db):
"Server = file://%s" \ "Server = file://%s" \
% (value.treename, value.getverify(), \ % (value.treename, value.getverify(), \
os.path.join(root, SYNCREPO, value.treename))) os.path.join(root, SYNCREPO, value.treename)))
for optkey, optval in value.option.iteritems(): for optkey, optval in value.option.items():
data.extend(["%s = %s" % (optkey, j) for j in optval]) data.extend(["%s = %s" % (optkey, j) for j in optval])
mkfile(root, filename, "\n".join(data)) mkfile(root, filename, "\n".join(data))