def _delitem(self, cpv):
del self.__db[cpv]
- def iterkeys(self):
+ def __iter__(self):
return iter(self.__db.keys())
def __contains__(self, cpv):
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)
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)
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
return self.con.rowcount > 0
- def iterkeys(self):
+ def __iter__(self):
if not self.autocommits:
try: self.commit()
except self._BaseError, e:
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" % \
return tuple(self.iterkeys())
def iterkeys(self):
- raise NotImplementedError
+ return iter(self)
def iteritems(self):
for x in self.iterkeys():
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]
else:
noise=verbose_instance
- dead_nodes = set(trg_cache.iterkeys())
+ dead_nodes = set(trg_cache)
count=0
if not trg_cache.autocommits:
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__