[Python-checkins] r66247 - sandbox/trunk/dbm_sqlite/Lib/dbm/sqlite.py
skip.montanaro
python-checkins at python.org
Sat Sep 6 05:07:46 CEST 2008
Author: skip.montanaro
Date: Sat Sep 6 05:07:46 2008
New Revision: 66247
Log:
Reverse the def's of the iter* methods and their list counterparts. I'm a
bit suspicious of not closing the cursor before returning from the iter*
methods. Maybe someone with more experience here can provide some guidance.
Modified:
sandbox/trunk/dbm_sqlite/Lib/dbm/sqlite.py
Modified: sandbox/trunk/dbm_sqlite/Lib/dbm/sqlite.py
==============================================================================
--- sandbox/trunk/dbm_sqlite/Lib/dbm/sqlite.py (original)
+++ sandbox/trunk/dbm_sqlite/Lib/dbm/sqlite.py Sat Sep 6 05:07:46 2008
@@ -60,29 +60,21 @@
finally:
c.close()
- def keys(self):
+ def iterkeys(self):
c = self._conn.cursor()
- try:
- c.execute("select key from dict order by key")
- return [e[0] for e in c]
- finally:
- c.close()
+ c.execute("select key from dict order by key")
+ return (e[0] for e in c)
+ __iter__ = iterkeys
- def values(self):
+ def itervalues(self):
c = self._conn.cursor()
- try:
- c.execute("select value from dict order by key")
- return [e[0] for e in c]
- finally:
- c.close()
+ c.execute("select value from dict order by key")
+ return (e[0] for e in c)
- def items(self):
+ def iteritems(self):
c = self._conn.cursor()
- try:
- c.execute("select key, value from dict order by key")
- return list(c)
- finally:
- c.close()
+ c.execute("select key, value from dict order by key")
+ return (e for e in c)
def __contains__(self, key):
c = self._conn.cursor()
@@ -93,15 +85,14 @@
finally:
c.close()
- def iterkeys(self):
- return iter(self.keys())
- __iter__ = iterkeys
+ def keys(self):
+ return list(self.iterkeys())
- def iteritems(self):
- return iter(self.items())
+ def items(self):
+ return list(self.iteritems())
- def itervalues(self):
- return iter(self.values())
+ def values(self):
+ return list(self.itervalues())
def __len__(self):
c = self._conn.cursor()
More information about the Python-checkins
mailing list