summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pym/portage/cache/anydbm.py2
-rw-r--r--pym/portage/cache/flat_hash.py2
-rw-r--r--pym/portage/cache/flat_list.py2
-rw-r--r--pym/portage/cache/metadata_overlay.py8
-rw-r--r--pym/portage/cache/sql_template.py2
-rw-r--r--pym/portage/cache/sqlite.py2
-rw-r--r--pym/portage/cache/template.py12
-rw-r--r--pym/portage/cache/util.py2
-rw-r--r--pym/portage/cache/volatile.py2
9 files changed, 22 insertions, 12 deletions
diff --git a/pym/portage/cache/anydbm.py b/pym/portage/cache/anydbm.py
index 8d72e40ca..47b8ac1bd 100644
--- a/pym/portage/cache/anydbm.py
+++ b/pym/portage/cache/anydbm.py
@@ -60,7 +60,7 @@ class database(fs_template.FsBased):
def _delitem(self, cpv):
del self.__db[cpv]
- def iterkeys(self):
+ def __iter__(self):
return iter(self.__db.keys())
def __contains__(self, cpv):
diff --git a/pym/portage/cache/flat_hash.py b/pym/portage/cache/flat_hash.py
index 05b900ea8..80b23fe4d 100644
--- a/pym/portage/cache/flat_hash.py
+++ b/pym/portage/cache/flat_hash.py
@@ -102,7 +102,7 @@ class database(fs_template.FsBased):
return os.path.exists(os.path.join(self.location, cpv))
- def iterkeys(self):
+ def __iter__(self):
"""generator for walking the dir struct"""
dirs = [self.location]
len_base = len(self.location)
diff --git a/pym/portage/cache/flat_list.py b/pym/portage/cache/flat_list.py
index 6dbbba96b..d3e480f96 100644
--- a/pym/portage/cache/flat_list.py
+++ b/pym/portage/cache/flat_list.py
@@ -86,7 +86,7 @@ class database(fs_template.FsBased):
return os.path.exists(os.path.join(self._base, cpv))
- def iterkeys(self):
+ def __iter__(self):
"""generator for walking the dir struct"""
dirs = [self._base]
len_base = len(self._base)
diff --git a/pym/portage/cache/metadata_overlay.py b/pym/portage/cache/metadata_overlay.py
index d1fcda1d1..2aaa7e07c 100644
--- a/pym/portage/cache/metadata_overlay.py
+++ b/pym/portage/cache/metadata_overlay.py
@@ -75,14 +75,14 @@ class database(template.database):
return False
return True
- def iterkeys(self):
+ def __iter__(self):
s = set()
- for cpv in self.db_rw.iterkeys():
- if self.has_key(cpv): # validates whiteout when necessary
+ for cpv in self.db_rw:
+ if cpv in self: # validates whiteout when necessary
yield cpv
# set includes whiteouts so they won't be yielded later
s.add(cpv)
- for cpv in self.db_ro.iterkeys():
+ for cpv in self.db_ro:
if cpv not in s:
yield cpv
diff --git a/pym/portage/cache/sql_template.py b/pym/portage/cache/sql_template.py
index 4ef3df421..f32a72844 100644
--- a/pym/portage/cache/sql_template.py
+++ b/pym/portage/cache/sql_template.py
@@ -209,7 +209,7 @@ class SQLDatabase(template.database):
return self.con.rowcount > 0
- def iterkeys(self):
+ def __iter__(self):
if not self.autocommits:
try: self.commit()
except self._BaseError, e:
diff --git a/pym/portage/cache/sqlite.py b/pym/portage/cache/sqlite.py
index 1cab49978..dae9d4c1d 100644
--- a/pym/portage/cache/sqlite.py
+++ b/pym/portage/cache/sqlite.py
@@ -223,7 +223,7 @@ class database(fs_template.FsBased):
else:
raise cache_errors.CacheCorruption(cpv, "key is not unique")
- def iterkeys(self):
+ def __iter__(self):
"""generator for walking the dir struct"""
cursor = self._db_cursor
cursor.execute("SELECT %s FROM %s" % \
diff --git a/pym/portage/cache/template.py b/pym/portage/cache/template.py
index 161b07f55..d5a07528c 100644
--- a/pym/portage/cache/template.py
+++ b/pym/portage/cache/template.py
@@ -95,7 +95,7 @@ class database(object):
return tuple(self.iterkeys())
def iterkeys(self):
- raise NotImplementedError
+ return iter(self)
def iteritems(self):
for x in self.iterkeys():
@@ -123,6 +123,16 @@ class database(object):
raise NotImplementedError
return self.has_key(cpv)
+ def __iter__(self):
+ """This method should always be overridden. It is provided only for
+ backward compatibility with modules that override iterkeys instead. It
+ will automatically raise a NotImplementedError if iterkeys has not been
+ overridden."""
+ if self.iterkeys is database.iterkeys:
+ # prevent a possible recursive loop
+ raise NotImplementedError(self)
+ return self.iterkeys()
+
def get(self, k, x=None):
try:
return self[k]
diff --git a/pym/portage/cache/util.py b/pym/portage/cache/util.py
index 4f0d563d2..3c6bdb70f 100644
--- a/pym/portage/cache/util.py
+++ b/pym/portage/cache/util.py
@@ -18,7 +18,7 @@ def mirror_cache(valid_nodes_iterable, src_cache, trg_cache, eclass_cache=None,
else:
noise=verbose_instance
- dead_nodes = set(trg_cache.iterkeys())
+ dead_nodes = set(trg_cache)
count=0
if not trg_cache.autocommits:
diff --git a/pym/portage/cache/volatile.py b/pym/portage/cache/volatile.py
index 555eafc5a..12c23dd56 100644
--- a/pym/portage/cache/volatile.py
+++ b/pym/portage/cache/volatile.py
@@ -16,7 +16,7 @@ class database(template.database):
config.pop("gid", None)
super(database, self).__init__(*args, **config)
self._data = {}
- self.iterkeys = self._data.iterkeys
+ self.__iter__ = self._data.__iter__
self._delitem = self._data.__delitem__
self.__contains__ = self._data.__contains__