Make dumbdbm use bytes for keys consistently.
This commit is contained in:
parent
bb839ef8ac
commit
7b4beea02e
|
@ -200,7 +200,11 @@ class _Database(UserDict.DictMixin):
|
||||||
self._commit()
|
self._commit()
|
||||||
|
|
||||||
def keys(self):
|
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):
|
def __contains__(self, key):
|
||||||
key = key.decode("latin-1")
|
key = key.decode("latin-1")
|
||||||
|
|
|
@ -102,7 +102,7 @@ class DumbDBMTestCase(unittest.TestCase):
|
||||||
f[b'1'] = b'hello2'
|
f[b'1'] = b'hello2'
|
||||||
f.close()
|
f.close()
|
||||||
f = dumbdbm.open(_fname)
|
f = dumbdbm.open(_fname)
|
||||||
self.assertEqual(f['1'], b'hello2')
|
self.assertEqual(f[b'1'], b'hello2')
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
def test_line_endings(self):
|
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)
|
v = random.choice((b'a', b'b', b'c')) * random.randrange(10000)
|
||||||
d[k] = v
|
d[k] = v
|
||||||
f[k.encode("ascii")] = v
|
f[k.encode("ascii")] = v
|
||||||
self.assertEqual(f[k], v)
|
self.assertEqual(f[k.encode("ascii")], v)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
f = dumbdbm.open(_fname)
|
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())
|
got = sorted(f.items())
|
||||||
self.assertEqual(expected, got)
|
self.assertEqual(expected, got)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
Loading…
Reference in New Issue