diff options
author | Guido van Rossum <guido@python.org> | 2007-08-28 00:09:54 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-08-28 00:09:54 (GMT) |
commit | 7b4beea02e6bf1db96c95781e3bb7e5233afc917 (patch) | |
tree | 42a4db441fb26f5f4c2306a532ee180bb1079ef4 /Lib | |
parent | bb839ef8ac446b0cb80ab4b818b111068af6a65c (diff) | |
download | cpython-7b4beea02e6bf1db96c95781e3bb7e5233afc917.zip cpython-7b4beea02e6bf1db96c95781e3bb7e5233afc917.tar.gz cpython-7b4beea02e6bf1db96c95781e3bb7e5233afc917.tar.bz2 |
Make dumbdbm use bytes for keys consistently.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/dumbdbm.py | 6 | ||||
-rw-r--r-- | Lib/test/test_dumbdbm.py | 6 |
2 files changed, 8 insertions, 4 deletions
diff --git a/Lib/dumbdbm.py b/Lib/dumbdbm.py index ad3ebcb..b47b7bd 100644 --- a/Lib/dumbdbm.py +++ b/Lib/dumbdbm.py @@ -200,7 +200,11 @@ class _Database(UserDict.DictMixin): self._commit() def keys(self): - return self._index.keys() + return [key.encode("latin-1") for key in self._index.keys()] + + def items(self): + return [(key.encode("latin-1"), self[key.encode("latin-1")]) + for key in self._index.keys()] def __contains__(self, key): key = key.decode("latin-1") diff --git a/Lib/test/test_dumbdbm.py b/Lib/test/test_dumbdbm.py index f327a5a..44bb369 100644 --- a/Lib/test/test_dumbdbm.py +++ b/Lib/test/test_dumbdbm.py @@ -102,7 +102,7 @@ class DumbDBMTestCase(unittest.TestCase): f[b'1'] = b'hello2' f.close() f = dumbdbm.open(_fname) - self.assertEqual(f['1'], b'hello2') + self.assertEqual(f[b'1'], b'hello2') f.close() def test_line_endings(self): @@ -157,11 +157,11 @@ class DumbDBMTestCase(unittest.TestCase): v = random.choice((b'a', b'b', b'c')) * random.randrange(10000) d[k] = v f[k.encode("ascii")] = v - self.assertEqual(f[k], v) + self.assertEqual(f[k.encode("ascii")], v) f.close() f = dumbdbm.open(_fname) - expected = sorted(d.items()) + expected = sorted((k.encode("latin-1"), v) for k, v in d.items()) got = sorted(f.items()) self.assertEqual(expected, got) f.close() |