summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2006-10-26 08:10:35 +0000
committerZac Medico <zmedico@gentoo.org>2006-10-26 08:10:35 +0000
commite3d5ecc57975b2a168bc436efd90bc3223f1b4e7 (patch)
tree148e8d839c13b4dd6e463e270f88e481992d771a
parent017e1a5720d08133e8edd325bebe4145ed22add4 (diff)
downloadportage-e3d5ecc57975b2a168bc436efd90bc3223f1b4e7.tar.gz
portage-e3d5ecc57975b2a168bc436efd90bc3223f1b4e7.tar.bz2
portage-e3d5ecc57975b2a168bc436efd90bc3223f1b4e7.zip
Reverse the relationship between __contains__ and has_key in all cache classes since python handles the "in" operator more efficiently than a has_key method call.
svn path=/main/trunk/; revision=4821
-rw-r--r--pym/cache/anydbm.py2
-rw-r--r--pym/cache/flat_hash.py2
-rw-r--r--pym/cache/flat_list.py2
-rw-r--r--pym/cache/metadata_overlay.py2
-rw-r--r--pym/cache/sql_template.py2
-rw-r--r--pym/cache/sqlite.py2
-rw-r--r--pym/cache/template.py4
7 files changed, 8 insertions, 8 deletions
diff --git a/pym/cache/anydbm.py b/pym/cache/anydbm.py
index 87e448f30..a4e0003d4 100644
--- a/pym/cache/anydbm.py
+++ b/pym/cache/anydbm.py
@@ -63,7 +63,7 @@ class database(fs_template.FsBased):
def iterkeys(self):
return iter(self.__db.keys())
- def has_key(self, cpv):
+ def __contains__(self, cpv):
return cpv in self.__db
def __del__(self):
diff --git a/pym/cache/flat_hash.py b/pym/cache/flat_hash.py
index d4c5930c7..a8adb2205 100644
--- a/pym/cache/flat_hash.py
+++ b/pym/cache/flat_hash.py
@@ -98,7 +98,7 @@ class database(fs_template.FsBased):
raise cache_errors.CacheCorruption(cpv, e)
- def has_key(self, cpv):
+ def __contains__(self, cpv):
return os.path.exists(os.path.join(self.location, cpv))
diff --git a/pym/cache/flat_list.py b/pym/cache/flat_list.py
index 65fe5a781..85efa4c02 100644
--- a/pym/cache/flat_list.py
+++ b/pym/cache/flat_list.py
@@ -82,7 +82,7 @@ class database(fs_template.FsBased):
raise cache_errors.CacheCorruption(cpv, e)
- def has_key(self, cpv):
+ def __contains__(self, cpv):
return os.path.exists(os.path.join(self._base, cpv))
diff --git a/pym/cache/metadata_overlay.py b/pym/cache/metadata_overlay.py
index 673ba8dff..9320b0938 100644
--- a/pym/cache/metadata_overlay.py
+++ b/pym/cache/metadata_overlay.py
@@ -55,7 +55,7 @@ class database(template.database):
else:
del self.db_rw[cpv]
- def has_key(self, cpv):
+ def __contains__(self, cpv):
try:
self[cpv] # validates whiteout when necessary
except KeyError:
diff --git a/pym/cache/sql_template.py b/pym/cache/sql_template.py
index 5c8af08f8..e635616e9 100644
--- a/pym/cache/sql_template.py
+++ b/pym/cache/sql_template.py
@@ -196,7 +196,7 @@ class SQLDatabase(template.database):
return self.con.fetchone()[0]
- def has_key(self, cpv):
+ def __contains__(self, cpv):
if not self.autocommits:
try: self.commit()
except self._BaseError, e:
diff --git a/pym/cache/sqlite.py b/pym/cache/sqlite.py
index 571eff39b..6b1a3d323 100644
--- a/pym/cache/sqlite.py
+++ b/pym/cache/sqlite.py
@@ -200,7 +200,7 @@ class database(fs_template.FsBased):
self._db_table["packages"]["package_key"],
self._db_escape_string(cpv)))
- def has_key(self, cpv):
+ def __contains__(self, cpv):
cursor = self._db_cursor
cursor.execute(" ".join(
["SELECT %s FROM %s" %
diff --git a/pym/cache/template.py b/pym/cache/template.py
index 565e7d2ab..a628b1161 100644
--- a/pym/cache/template.py
+++ b/pym/cache/template.py
@@ -89,7 +89,7 @@ class database(object):
raise NotImplementedError
def has_key(self, cpv):
- raise NotImplementedError
+ return cpv in self
def keys(self):
return tuple(self.iterkeys())
@@ -114,7 +114,7 @@ class database(object):
raise NotImplementedError
def __contains__(self, cpv):
- return self.has_key(cpv)
+ raise NotImplementedError
def get(self, k, x=None):
try: